Bug 1070057 - Make TestResolver.resolve_tests filter by subsuite. r=ted

--HG--
extra : rebase_source : e04c903d40d5996ca28136bc9941dc74cd31ac9b
This commit is contained in:
Nick Alexander 2014-09-26 11:44:57 -07:00
parent c7eb81d119
commit ac9ce94697
2 changed files with 51 additions and 3 deletions

View File

@ -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()

View File

@ -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