bug 1255479 - add PYTHON_UNIT_TESTS to all-tests.json. r?nalexander
MozReview-Commit-ID: HJ6ohvEOgdX
--- a/python/mozbuild/mozbuild/frontend/emitter.py
+++ b/python/mozbuild/mozbuild/frontend/emitter.py
@@ -1074,16 +1074,21 @@ class TreeMetadataEmitter(LoggingMixin):
for obj in self._process_reftest_manifest(context, flavor, path, manifest):
yield obj
for flavor in WEB_PATFORM_TESTS_FLAVORS:
for path, manifest in context.get("%s_MANIFESTS" % flavor.upper().replace('-', '_'), []):
for obj in self._process_web_platform_tests_manifest(context, path, manifest):
yield obj
+ python_tests = context.get('PYTHON_UNIT_TESTS')
+ if python_tests:
+ for obj in self._process_python_tests(context, python_tests):
+ yield obj
+
def _process_test_manifest(self, context, info, manifest_path, mpmanifest):
flavor, install_root, install_subdir, package_tests = info
path = mozpath.normpath(mozpath.join(context.srcdir, manifest_path))
manifest_dir = mozpath.dirname(path)
manifest_reldir = mozpath.dirname(mozpath.relpath(path,
context.config.topsrcdir))
install_prefix = mozpath.join(install_root, install_subdir)
@@ -1277,16 +1282,46 @@ class TreeMetadataEmitter(LoggingMixin):
'head': '',
'tail': '',
'support-files': '',
'subsuite': '',
})
yield obj
+ def _process_python_tests(self, context, python_tests):
+ manifest_full_path = context.main_path
+ manifest_reldir = mozpath.dirname(mozpath.relpath(manifest_full_path,
+ context.config.topsrcdir))
+
+ obj = TestManifest(context, manifest_full_path,
+ mozpath.basename(manifest_full_path),
+ flavor='python', install_prefix='python/',
+ relpath=mozpath.join(manifest_reldir,
+ mozpath.basename(manifest_full_path)))
+
+ for test in python_tests:
+ test = mozpath.normpath(mozpath.join(context.srcdir, test))
+ if not os.path.isfile(test):
+ raise SandboxValidationError('Path specified in '
+ 'PYTHON_UNIT_TESTS does not exist: %s' % test,
+ context)
+ obj.tests.append({
+ 'path': test,
+ 'here': mozpath.dirname(test),
+ 'manifest': manifest_full_path,
+ 'name': mozpath.basename(test),
+ 'head': '',
+ 'tail': '',
+ 'support-files': '',
+ 'subsuite': '',
+ })
+
+ yield obj
+
def _process_jar_manifests(self, context):
jar_manifests = context.get('JAR_MANIFESTS', [])
if len(jar_manifests) > 1:
raise SandboxValidationError('While JAR_MANIFESTS is a list, '
'it is currently limited to one value.', context)
for path in jar_manifests:
yield JARManifest(context, path)
--- a/python/mozbuild/mozbuild/test/frontend/data/test-manifest-keys-extracted/moz.build
+++ b/python/mozbuild/mozbuild/test/frontend/data/test-manifest-keys-extracted/moz.build
@@ -4,8 +4,9 @@
A11Y_MANIFESTS += ['a11y.ini']
BROWSER_CHROME_MANIFESTS += ['browser.ini']
METRO_CHROME_MANIFESTS += ['metro.ini']
MOCHITEST_MANIFESTS += ['mochitest.ini']
MOCHITEST_CHROME_MANIFESTS += ['chrome.ini']
XPCSHELL_TESTS_MANIFESTS += ['xpcshell.ini']
REFTEST_MANIFESTS += ['reftest.list']
CRASHTEST_MANIFESTS += ['crashtest.list']
+PYTHON_UNIT_TESTS += ['test_foo.py']
new file mode 100644
--- /dev/null
+++ b/python/mozbuild/mozbuild/test/frontend/data/test-python-unit-test-missing/moz.build
@@ -0,0 +1,4 @@
+# Any copyright is dedicated to the Public Domain.
+# http://creativecommons.org/publicdomain/zero/1.0/
+
+PYTHON_UNIT_TESTS += ['test_foo.py']
--- a/python/mozbuild/mozbuild/test/frontend/test_emitter.py
+++ b/python/mozbuild/mozbuild/test/frontend/test_emitter.py
@@ -475,25 +475,31 @@ class TestEmitterBasic(unittest.TestCase
'reftest1-ref.html': 'reftest.list',
'reftest2.html': 'included-reftest.list',
'reftest2-ref.html': 'included-reftest.list',
}
for t in obj.tests:
self.assertTrue(t['manifest'].endswith(expected_manifests[t['name']]))
+ def test_python_unit_test_missing(self):
+ """Missing files in PYTHON_UNIT_TESTS should raise."""
+ reader = self.reader('test-python-unit-test-missing')
+ with self.assertRaisesRegexp(SandboxValidationError,
+ 'Path specified in PYTHON_UNIT_TESTS does not exist:'):
+ objs = self.read_topsrcdir(reader)
def test_test_manifest_keys_extracted(self):
"""Ensure all metadata from test manifests is extracted."""
reader = self.reader('test-manifest-keys-extracted')
objs = [o for o in self.read_topsrcdir(reader)
if isinstance(o, TestManifest)]
- self.assertEqual(len(objs), 8)
+ self.assertEqual(len(objs), 9)
metadata = {
'a11y.ini': {
'flavor': 'a11y',
'installs': {
'a11y.ini': False,
'test_a11y.js': True,
},
@@ -548,16 +554,20 @@ class TestEmitterBasic(unittest.TestCase
'reftest.list': {
'flavor': 'reftest',
'installs': {},
},
'crashtest.list': {
'flavor': 'crashtest',
'installs': {},
},
+ 'moz.build': {
+ 'flavor': 'python',
+ 'installs': {},
+ }
}
for o in objs:
m = metadata[mozpath.basename(o.manifest_relpath)]
self.assertTrue(o.path.startswith(o.directory))
self.assertEqual(o.flavor, m['flavor'])
self.assertEqual(o.dupe_manifest, m.get('dupe', False))
--- a/python/mozbuild/mozbuild/testing.py
+++ b/python/mozbuild/mozbuild/testing.py
@@ -279,17 +279,18 @@ TEST_MANIFESTS = dict(
REFTEST_FLAVORS = ('crashtest', 'reftest')
# Web platform tests have their own manifest format and are processed separately.
WEB_PATFORM_TESTS_FLAVORS = ('web-platform-tests',)
def all_test_flavors():
return ([v[0] for v in TEST_MANIFESTS.values()] +
list(REFTEST_FLAVORS) +
- list(WEB_PATFORM_TESTS_FLAVORS))
+ list(WEB_PATFORM_TESTS_FLAVORS) +
+ ['python'])
# Convenience methods for test manifest reading.
def read_manifestparser_manifest(context, manifest_path):
path = mozpath.normpath(mozpath.join(context.srcdir, manifest_path))
return manifestparser.TestManifest(manifests=[path], strict=True,
rootdir=context.config.topsrcdir,
finder=context._finder)