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

Unified 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, 3 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 side-by-side diff with in-line comments
Download patch
Index: tools/telemetry/third_party/coverage/tests/helpers.py
diff --git a/tools/telemetry/third_party/coverage/tests/helpers.py b/tools/telemetry/third_party/coverage/tests/helpers.py
new file mode 100644
index 0000000000000000000000000000000000000000..aa094bc1621043e2088f3aa03efdf56fad053d45
--- /dev/null
+++ b/tools/telemetry/third_party/coverage/tests/helpers.py
@@ -0,0 +1,52 @@
+# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
+# For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt
+
+"""Helpers for coverage.py tests."""
+
+import subprocess
+
+
+def run_command(cmd):
+ """Run a command in a sub-process.
+
+ Returns the exit status code and the combined stdout and stderr.
+
+ """
+ proc = subprocess.Popen(
+ cmd, shell=True,
+ stdin=subprocess.PIPE, stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT
+ )
+ output, _ = proc.communicate()
+ status = proc.returncode
+
+ # Get the output, and canonicalize it to strings with newlines.
+ if not isinstance(output, str):
+ output = output.decode('utf-8')
+ output = output.replace('\r', '')
+
+ return status, output
+
+
+class CheckUniqueFilenames(object):
+ """Asserts the uniqueness of file names passed to a function."""
+ def __init__(self, wrapped):
+ self.filenames = set()
+ self.wrapped = wrapped
+
+ @classmethod
+ def hook(cls, cov, method_name):
+ """Replace a method with our checking wrapper."""
+ method = getattr(cov, method_name)
+ hook = cls(method)
+ setattr(cov, method_name, hook.wrapper)
+ return hook
+
+ def wrapper(self, filename, *args, **kwargs):
+ """The replacement method. Check that we don't have dupes."""
+ assert filename not in self.filenames, (
+ "File name %r passed to %r twice" % (filename, self.wrapped)
+ )
+ self.filenames.add(filename)
+ ret = self.wrapped(filename, *args, **kwargs)
+ return ret
« 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