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

Unified Diff: scripts/slave/unittests/expect_tests/type_definitions.py

Issue 354913003: Add module discovery and autoloading to expect_tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/build
Patch Set: Fix formatting + comment Created 6 years, 6 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: scripts/slave/unittests/expect_tests/type_definitions.py
diff --git a/scripts/slave/unittests/expect_tests/type_definitions.py b/scripts/slave/unittests/expect_tests/type_definitions.py
index ec5ffeef151b825825a30424a7f27f36dbfe905a..1d4cb00da8665ddf88f9f3c4bb611773fb17c468 100644
--- a/scripts/slave/unittests/expect_tests/type_definitions.py
+++ b/scripts/slave/unittests/expect_tests/type_definitions.py
@@ -18,6 +18,7 @@ UnknownError = namedtuple('UnknownError', 'message')
NoMatchingTestsError = namedtuple('NoMatchingTestsError', '')
Result = namedtuple('Result', 'data')
MultiResult = namedtuple('MultiResult', 'results')
+Cleanup = namedtuple('Cleanup', 'func_call')
class ResultStageAbort(Exception):
pass
@@ -191,11 +192,10 @@ class Test(_Test):
return super(Test, cls).__new__(cls, name, func_call, expect_dir,
expect_base, ext, covers, breakpoints)
- def coverage_includes(self):
- if self.covers is not None:
- return self.covers
- test_file = inspect.getabsfile(self.func_call.func)
+ @staticmethod
+ def covers_obj(obj):
+ test_file = inspect.getabsfile(obj)
covers = [test_file]
match = Test.TEST_COVERS_MATCH.match(test_file)
if match:
@@ -203,17 +203,25 @@ class Test(_Test):
os.path.dirname(os.path.dirname(test_file)),
match.group(1) + '.py'
))
-
return covers
+ @staticmethod
+ def expect_dir_obj(obj):
+ test_file = inspect.getabsfile(obj)
+ return os.path.splitext(test_file)[0] + '.expected'
+
+ def coverage_includes(self):
+ if self.covers is not None:
+ return self.covers
+ return self.covers_obj(self.func_call.func)
+
def expect_path(self, ext=None):
expect_dir = self.expect_dir
if expect_dir is None:
- test_file = inspect.getabsfile(self.func_call.func)
- expect_dir = os.path.splitext(test_file)[0] + '.expected'
+ expect_dir = self.expect_dir_obj(self.func_call.func)
name = self.expect_base or self.name
name = ''.join('_' if c in '<>:"\\/|?*\0' else c for c in name)
- return os.path.join(self.expect_dir, name + ('.%s' % (ext or self.ext)))
+ return os.path.join(expect_dir, name + ('.%s' % (ext or self.ext)))
def run(self, context=None):
return self.func_call(context=context)

Powered by Google App Engine
This is Rietveld 408576698