Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(101)

Side by Side Diff: tools/telemetry/third_party/coverage/tests/helpers.py

Issue 1366913004: Add coverage Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 # Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
2 # For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt
3
4 """Helpers for coverage.py tests."""
5
6 import subprocess
7
8
9 def run_command(cmd):
10 """Run a command in a sub-process.
11
12 Returns the exit status code and the combined stdout and stderr.
13
14 """
15 proc = subprocess.Popen(
16 cmd, shell=True,
17 stdin=subprocess.PIPE, stdout=subprocess.PIPE,
18 stderr=subprocess.STDOUT
19 )
20 output, _ = proc.communicate()
21 status = proc.returncode
22
23 # Get the output, and canonicalize it to strings with newlines.
24 if not isinstance(output, str):
25 output = output.decode('utf-8')
26 output = output.replace('\r', '')
27
28 return status, output
29
30
31 class CheckUniqueFilenames(object):
32 """Asserts the uniqueness of file names passed to a function."""
33 def __init__(self, wrapped):
34 self.filenames = set()
35 self.wrapped = wrapped
36
37 @classmethod
38 def hook(cls, cov, method_name):
39 """Replace a method with our checking wrapper."""
40 method = getattr(cov, method_name)
41 hook = cls(method)
42 setattr(cov, method_name, hook.wrapper)
43 return hook
44
45 def wrapper(self, filename, *args, **kwargs):
46 """The replacement method. Check that we don't have dupes."""
47 assert filename not in self.filenames, (
48 "File name %r passed to %r twice" % (filename, self.wrapped)
49 )
50 self.filenames.add(filename)
51 ret = self.wrapped(filename, *args, **kwargs)
52 return ret
OLDNEW
« no previous file with comments | « tools/telemetry/third_party/coverage/tests/goldtest.py ('k') | tools/telemetry/third_party/coverage/tests/js/index.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698