From ac9ce94697e62744ee4200c80eb88c500d624f69 Mon Sep 17 00:00:00 2001 From: Nick Alexander Date: Fri, 26 Sep 2014 11:44:57 -0700 Subject: [PATCH] Bug 1070057 - Make TestResolver.resolve_tests filter by subsuite. r=ted --HG-- extra : rebase_source : e04c903d40d5996ca28136bc9941dc74cd31ac9b --- python/mozbuild/mozbuild/test/test_testing.py | 46 ++++++++++++++++++- python/mozbuild/mozbuild/testing.py | 8 +++- 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/python/mozbuild/mozbuild/test/test_testing.py b/python/mozbuild/mozbuild/test/test_testing.py index 2b55fd03614..0356e60c1af 100644 --- a/python/mozbuild/mozbuild/test/test_testing.py +++ b/python/mozbuild/mozbuild/test/test_testing.py @@ -101,6 +101,32 @@ ALL_TESTS_JSON = b''' "support-files": "\\ndata/**\\nxpcshell_updater.ini", "tail": "" } + ], + "mobile/android/tests/background/junit3/src/common/TestAndroidLogWriters.java": [ + { + "dir_relpath": "mobile/android/tests/background/junit3/src/common", + "file_relpath": "mobile/android/tests/background/junit3/src/common/TestAndroidLogWriters.java", + "flavor": "instrumentation", + "here": "/Users/nalexander/Mozilla/gecko-dev/mobile/android/tests/background/junit3", + "manifest": "/Users/nalexander/Mozilla/gecko-dev/mobile/android/tests/background/junit3/instrumentation.ini", + "name": "src/common/TestAndroidLogWriters.java", + "path": "/Users/nalexander/Mozilla/gecko-dev/mobile/android/tests/background/junit3/src/common/TestAndroidLogWriters.java", + "relpath": "src/common/TestAndroidLogWriters.java", + "subsuite": "background" + } + ], + "mobile/android/tests/browser/junit3/src/TestDistribution.java": [ + { + "dir_relpath": "mobile/android/tests/browser/junit3/src", + "file_relpath": "mobile/android/tests/browser/junit3/src/TestDistribution.java", + "flavor": "instrumentation", + "here": "/Users/nalexander/Mozilla/gecko-dev/mobile/android/tests/browser/junit3", + "manifest": "/Users/nalexander/Mozilla/gecko-dev/mobile/android/tests/browser/junit3/instrumentation.ini", + "name": "src/TestDistribution.java", + "path": "/Users/nalexander/Mozilla/gecko-dev/mobile/android/tests/browser/junit3/src/TestDistribution.java", + "relpath": "src/TestDistribution.java", + "subsuite": "browser" + } ] }'''.strip() @@ -127,14 +153,14 @@ class Base(unittest.TestCase): class TestTestMetadata(Base): def test_load(self): t = self._get_test_metadata() - self.assertEqual(len(t._tests_by_path), 4) + self.assertEqual(len(t._tests_by_path), 6) self.assertEqual(len(list(t.tests_with_flavor('xpcshell'))), 3) self.assertEqual(len(list(t.tests_with_flavor('mochitest-plain'))), 0) def test_resolve_all(self): t = self._get_test_metadata() - self.assertEqual(len(list(t.resolve_tests())), 5) + self.assertEqual(len(list(t.resolve_tests())), 7) def test_resolve_filter_flavor(self): t = self._get_test_metadata() @@ -213,6 +239,22 @@ class TestTestResolver(Base): actual = list(r.resolve_tests(paths=['services'], cwd=r.topobjdir)) self.assertEqual(actual, expected) + def test_subsuites(self): + """Test filtering by subsuite.""" + + r = self._get_resolver() + + tests = list(r.resolve_tests(paths=['mobile'])) + self.assertEqual(len(tests), 2) + + tests = list(r.resolve_tests(paths=['mobile'], subsuite='browser')) + self.assertEqual(len(tests), 1) + self.assertEqual(tests[0]['name'], 'src/TestDistribution.java') + + tests = list(r.resolve_tests(paths=['mobile'], subsuite='background')) + self.assertEqual(len(tests), 1) + self.assertEqual(tests[0]['name'], 'src/common/TestAndroidLogWriters.java') + if __name__ == '__main__': main() diff --git a/python/mozbuild/mozbuild/testing.py b/python/mozbuild/mozbuild/testing.py index 316d2ee04ba..1d322b51366 100644 --- a/python/mozbuild/mozbuild/testing.py +++ b/python/mozbuild/mozbuild/testing.py @@ -70,7 +70,7 @@ class TestMetadata(object): for path in sorted(self._tests_by_flavor.get(flavor, [])): yield self._tests_by_path[path] - def resolve_tests(self, paths=None, flavor=None, under_path=None): + def resolve_tests(self, paths=None, flavor=None, subsuite=None, under_path=None): """Resolve tests from an identifier. This is a generator of dicts describing each test. @@ -88,6 +88,9 @@ class TestMetadata(object): If ``flavor`` is a string, it will be used to filter returned tests to only be the flavor specified. A flavor is something like ``xpcshell``. + + If ``subsuite`` is a string, it will be used to filter returned tests + to only be in the subsuite specified. """ def fltr(tests): for test in tests: @@ -96,6 +99,9 @@ class TestMetadata(object): (flavor != 'devtools' and test.get('flavor') != flavor): continue + if subsuite and test.get('subsuite') != subsuite: + continue + if under_path \ and not test['file_relpath'].startswith(under_path): continue