Bug 1317970 - Use manifestparser manifests for python unit tests, r=chmanchester

This deprecates PYTHON_UNIT_TESTS and replaces it with PYTHON_UNITTEST_MANIFESTS.
In the build system, this means python unittests will be treated the same as all
other test suites that use manifestparser. New manifests called 'python.ini' have
been created for all test directories containing python unittests.

MozReview-Commit-ID: IBHG7Thif2D

--HG--
extra : rebase_source : 11a92a2bc544d067946bbd774975140147458caa
This commit is contained in:
Andrew Halberstadt 2016-11-16 09:59:22 -05:00
Родитель 2d76b4f70d
Коммит 6adcf5b456
35 изменённых файлов: 133 добавлений и 284 удалений

Просмотреть файл

@ -0,0 +1 @@
[compare-mozconfigs-wrapper.py]

Просмотреть файл

@ -38,8 +38,8 @@ for var in ('MOZ_CRASHREPORTER', 'MOZ_PROFILE_MIGRATOR',
DEFINES[var] = True
if CONFIG['MOZ_BUILD_APP'] == 'browser':
PYTHON_UNIT_TESTS += [
'compare-mozconfig/compare-mozconfigs-wrapper.py',
PYTHON_UNITTEST_MANIFESTS += [
'compare-mozconfig/python.ini',
]
if CONFIG['ENABLE_TESTS'] or CONFIG['MOZ_DMD']:

Просмотреть файл

@ -32,12 +32,8 @@ if CONFIG['HOST_OS_ARCH'] != 'WINNT':
if CONFIG['MOZ_SYSTEM_ICU']:
DEFINES['MOZ_SYSTEM_ICU'] = True
PYTHON_UNIT_TESTS += [
'tests/test_mozbuild_reading.py',
'tests/unit-expandlibs.py',
'tests/unit-mozunit.py',
'tests/unit-nsinstall.py',
'tests/unit-printprereleasesuffix.py',
PYTHON_UNITTEST_MANIFESTS += [
'tests/python.ini',
]
if CONFIG['GNU_CC'] and CONFIG['MOZ_OPTIMIZE']:

5
config/tests/python.ini Normal file
Просмотреть файл

@ -0,0 +1,5 @@
[test_mozbuild_reading.py]
[unit-expandlibs.py]
[unit-mozunit.py]
[unit-nsinstall.py]
[unit-printprereleasesuffix.py]

Просмотреть файл

@ -144,8 +144,8 @@ if CONFIG['MOZ_BUILD_APP'] in ['browser', 'mobile/android', 'xulrunner']:
DEFINES['HAVE_SIDEBAR'] = True
PYTHON_UNIT_TESTS += [
'mozwebidlcodegen/test/test_mozwebidlcodegen.py',
PYTHON_UNITTEST_MANIFESTS += [
'mozwebidlcodegen/test/python.ini',
]
if CONFIG['GNU_CXX']:

Просмотреть файл

@ -0,0 +1 @@
[test_mozwebidlcodegen.py]

Просмотреть файл

@ -17,7 +17,7 @@ USE_LIBS += [
OS_LIBS += CONFIG['MOZ_ZLIB_LIBS']
DISABLE_STL_WRAPPING = True
PYTHON_UNIT_TESTS += ['run_test_zip.py']
PYTHON_UNITTEST_MANIFESTS += ['python.ini']
if CONFIG['GNU_CXX']:
CXXFLAGS += ['-Wno-error=shadow']

Просмотреть файл

@ -0,0 +1 @@
[run_test_zip.py]

Просмотреть файл

@ -0,0 +1,6 @@
[test_conditions.py]
[test_config.py]
[test_dispatcher.py]
[test_entry_point.py]
[test_error_output.py]
[test_logger.py]

Просмотреть файл

@ -65,7 +65,7 @@ class MachCommands(MachCommandBase):
@CommandArgument('tests', nargs='*',
metavar='TEST',
help=('Tests to run. Each test can be a single file or a directory. '
'Default test resolution relies on PYTHON_UNIT_TESTS.'))
'Default test resolution relies on PYTHON_UNITTEST_MANIFESTS.'))
def python_test(self,
tests=[],
test_objects=None,
@ -118,13 +118,13 @@ class MachCommands(MachCommandBase):
test_objects = resolver.resolve_tests(paths=tests,
flavor='python')
else:
# Otherwise just run everything in PYTHON_UNIT_TESTS
# Otherwise just run everything in PYTHON_UNITTEST_MANIFESTS
test_objects = resolver.resolve_tests(flavor='python')
if not test_objects:
message = 'TEST-UNEXPECTED-FAIL | No tests collected'
if not path_only:
message += ' (Not in PYTHON_UNIT_TESTS? Try --path-only?)'
message += ' (Not in PYTHON_UNITTEST_MANIFESTS? Try --path-only?)'
self.log(logging.WARN, 'python-test', {}, message)
return 1

Просмотреть файл

@ -20,69 +20,10 @@ SPHINX_PYTHON_PACKAGE_DIRS += [
SPHINX_TREES['mach'] = 'mach/docs'
PYTHON_UNIT_TESTS += [
'mach/mach/test/test_conditions.py',
'mach/mach/test/test_config.py',
'mach/mach/test/test_dispatcher.py',
'mach/mach/test/test_entry_point.py',
'mach/mach/test/test_error_output.py',
'mach/mach/test/test_logger.py',
'mozbuild/dumbmake/test/test_dumbmake.py',
'mozbuild/mozbuild/test/action/test_buildlist.py',
'mozbuild/mozbuild/test/action/test_generate_browsersearch.py',
'mozbuild/mozbuild/test/action/test_package_fennec_apk.py',
'mozbuild/mozbuild/test/backend/test_android_eclipse.py',
'mozbuild/mozbuild/test/backend/test_build.py',
'mozbuild/mozbuild/test/backend/test_configenvironment.py',
'mozbuild/mozbuild/test/backend/test_recursivemake.py',
'mozbuild/mozbuild/test/backend/test_visualstudio.py',
'mozbuild/mozbuild/test/compilation/test_warnings.py',
'mozbuild/mozbuild/test/configure/lint.py',
'mozbuild/mozbuild/test/configure/test_checks_configure.py',
'mozbuild/mozbuild/test/configure/test_compile_checks.py',
'mozbuild/mozbuild/test/configure/test_configure.py',
'mozbuild/mozbuild/test/configure/test_lint.py',
'mozbuild/mozbuild/test/configure/test_moz_configure.py',
'mozbuild/mozbuild/test/configure/test_options.py',
'mozbuild/mozbuild/test/configure/test_toolchain_configure.py',
'mozbuild/mozbuild/test/configure/test_toolchain_helpers.py',
'mozbuild/mozbuild/test/configure/test_toolkit_moz_configure.py',
'mozbuild/mozbuild/test/configure/test_util.py',
'mozbuild/mozbuild/test/controller/test_ccachestats.py',
'mozbuild/mozbuild/test/controller/test_clobber.py',
'mozbuild/mozbuild/test/frontend/test_context.py',
'mozbuild/mozbuild/test/frontend/test_emitter.py',
'mozbuild/mozbuild/test/frontend/test_namespaces.py',
'mozbuild/mozbuild/test/frontend/test_reader.py',
'mozbuild/mozbuild/test/frontend/test_sandbox.py',
'mozbuild/mozbuild/test/test_base.py',
'mozbuild/mozbuild/test/test_containers.py',
'mozbuild/mozbuild/test/test_dotproperties.py',
'mozbuild/mozbuild/test/test_expression.py',
'mozbuild/mozbuild/test/test_jarmaker.py',
'mozbuild/mozbuild/test/test_line_endings.py',
'mozbuild/mozbuild/test/test_makeutil.py',
'mozbuild/mozbuild/test/test_mozconfig.py',
'mozbuild/mozbuild/test/test_mozinfo.py',
'mozbuild/mozbuild/test/test_preprocessor.py',
'mozbuild/mozbuild/test/test_pythonutil.py',
'mozbuild/mozbuild/test/test_testing.py',
'mozbuild/mozbuild/test/test_util.py',
'mozbuild/mozpack/test/test_chrome_flags.py',
'mozbuild/mozpack/test/test_chrome_manifest.py',
'mozbuild/mozpack/test/test_copier.py',
'mozbuild/mozpack/test/test_errors.py',
'mozbuild/mozpack/test/test_files.py',
'mozbuild/mozpack/test/test_manifests.py',
'mozbuild/mozpack/test/test_mozjar.py',
'mozbuild/mozpack/test/test_packager.py',
'mozbuild/mozpack/test/test_packager_formats.py',
'mozbuild/mozpack/test/test_packager_l10n.py',
'mozbuild/mozpack/test/test_packager_unpack.py',
'mozbuild/mozpack/test/test_path.py',
'mozbuild/mozpack/test/test_unify.py',
'mozlint/test/test_formatters.py',
'mozlint/test/test_parser.py',
'mozlint/test/test_roller.py',
'mozlint/test/test_types.py',
PYTHON_UNITTEST_MANIFESTS += [
'mach/mach/test/python.ini',
'mozbuild/dumbmake/test/python.ini',
'mozbuild/mozbuild/test/python.ini',
'mozbuild/mozpack/test/python.ini',
'mozlint/test/python.ini',
]

Просмотреть файл

@ -0,0 +1 @@
[test_dumbmake.py]

Просмотреть файл

@ -120,7 +120,6 @@ MOZBUILD_VARIABLES = [
b'PARALLEL_DIRS',
b'PREF_JS_EXPORTS',
b'PROGRAM',
b'PYTHON_UNIT_TESTS',
b'RESOURCE_FILES',
b'SDK_HEADERS',
b'SDK_LIBRARY',

Просмотреть файл

@ -1154,10 +1154,6 @@ VARIABLES = {
Implies FORCE_SHARED_LIB.
"""),
'PYTHON_UNIT_TESTS': (StrictOrderingOnAppendList, list,
"""A list of python unit tests.
"""),
'HOST_LIBRARY_NAME': (unicode, unicode,
"""Name of target library generated when cross compiling.
"""),
@ -1575,6 +1571,11 @@ VARIABLES = {
"""List of manifest files defining xpcshell tests.
"""),
'PYTHON_UNITTEST_MANIFESTS': (ManifestparserManifestList, list,
"""List of manifest files defining python unit tests.
"""),
# The following variables are used to control the target of installed files.
'XPI_NAME': (unicode, unicode,
"""The name of an extension XPI to generate.

Просмотреть файл

@ -934,7 +934,6 @@ class TreeMetadataEmitter(LoggingMixin):
'ANDROID_GENERATED_RESFILES',
'DISABLE_STL_WRAPPING',
'EXTRA_DSO_LDOPTS',
'PYTHON_UNIT_TESTS',
'RCFILE',
'RESFILE',
'RCINCLUDE',
@ -1260,11 +1259,6 @@ class TreeMetadataEmitter(LoggingMixin):
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
@ -1430,36 +1424,6 @@ class TreeMetadataEmitter(LoggingMixin):
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:

Просмотреть файл

@ -9,4 +9,4 @@ MOCHITEST_CHROME_MANIFESTS += ['chrome.ini']
XPCSHELL_TESTS_MANIFESTS += ['xpcshell.ini']
REFTEST_MANIFESTS += ['reftest.list']
CRASHTEST_MANIFESTS += ['crashtest.list']
PYTHON_UNIT_TESTS += ['test_foo.py']
PYTHON_UNITTEST_MANIFESTS += ['python.ini']

Просмотреть файл

@ -0,0 +1 @@
[test_foo.py]

Просмотреть файл

@ -1,4 +0,0 @@
# Any copyright is dedicated to the Public Domain.
# http://creativecommons.org/publicdomain/zero/1.0/
PYTHON_UNIT_TESTS += ['test_foo.py']

Просмотреть файл

@ -540,13 +540,6 @@ class TestEmitterBasic(unittest.TestCase):
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:'):
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')
@ -619,9 +612,11 @@ class TestEmitterBasic(unittest.TestCase):
'flavor': 'crashtest',
'installs': {},
},
'moz.build': {
'python.ini': {
'flavor': 'python',
'installs': {},
'installs': {
'python.ini': False,
},
}
}

Просмотреть файл

@ -0,0 +1,40 @@
[action/test_buildlist.py]
[action/test_generate_browsersearch.py]
[action/test_package_fennec_apk.py]
[backend/test_android_eclipse.py]
[backend/test_build.py]
[backend/test_configenvironment.py]
[backend/test_recursivemake.py]
[backend/test_visualstudio.py]
[compilation/test_warnings.py]
[configure/lint.py]
[configure/test_checks_configure.py]
[configure/test_compile_checks.py]
[configure/test_configure.py]
[configure/test_lint.py]
[configure/test_moz_configure.py]
[configure/test_options.py]
[configure/test_toolchain_configure.py]
[configure/test_toolchain_helpers.py]
[configure/test_toolkit_moz_configure.py]
[configure/test_util.py]
[controller/test_ccachestats.py]
[controller/test_clobber.py]
[frontend/test_context.py]
[frontend/test_emitter.py]
[frontend/test_namespaces.py]
[frontend/test_reader.py]
[frontend/test_sandbox.py]
[test_base.py]
[test_containers.py]
[test_dotproperties.py]
[test_expression.py]
[test_jarmaker.py]
[test_line_endings.py]
[test_makeutil.py]
[test_mozconfig.py]
[test_mozinfo.py]
[test_preprocessor.py]
[test_pythonutil.py]
[test_testing.py]
[test_util.py]

Просмотреть файл

@ -288,6 +288,7 @@ TEST_MANIFESTS = dict(
FIREFOX_UI_FUNCTIONAL=('firefox-ui-functional', 'firefox-ui', '.', False),
FIREFOX_UI_UPDATE=('firefox-ui-update', 'firefox-ui', '.', False),
PUPPETEER_FIREFOX=('firefox-ui-functional', 'firefox-ui', '.', False),
PYTHON_UNITTEST=('python', 'python', '.', False),
# marionette tests are run from the srcdir
# TODO(ato): make packaging work as for other test suites
@ -311,8 +312,7 @@ WEB_PLATFORM_TESTS_FLAVORS = ('web-platform-tests',)
def all_test_flavors():
return ([v[0] for v in TEST_MANIFESTS.values()] +
list(REFTEST_FLAVORS) +
list(WEB_PLATFORM_TESTS_FLAVORS) +
['python'])
list(WEB_PLATFORM_TESTS_FLAVORS))
class TestInstallInfo(object):
def __init__(self):

Просмотреть файл

@ -0,0 +1,13 @@
[test_chrome_flags.py]
[test_chrome_manifest.py]
[test_copier.py]
[test_errors.py]
[test_files.py]
[test_manifests.py]
[test_mozjar.py]
[test_packager.py]
[test_packager_formats.py]
[test_packager_l10n.py]
[test_packager_unpack.py]
[test_path.py]
[test_unify.py]

Просмотреть файл

@ -0,0 +1,4 @@
[test_formatters.py]
[test_parser.py]
[test_roller.py]
[test_types.py]

Просмотреть файл

@ -455,12 +455,10 @@ To update from a directory of tests in `~/mozmill/src/mozmill-tests/firefox/` ru
Tests
`````
manifestparser includes a suite of tests:
https://github.com/mozilla/mozbase/tree/master/manifestparsery/tests
manifestparser includes a suite of tests.
`test_manifest.txt` is a doctest that may be helpful in figuring out
how to use the API. Tests are run via `python test.py`.
how to use the API. Tests are run via `mach python-test testing/mozbase/manifestparser`.
Bugs
````

Просмотреть файл

@ -4,8 +4,21 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
PYTHON_UNIT_TESTS += [
'test.py',
PYTHON_UNITTEST_MANIFESTS += [
'manifestparser/tests/manifest.ini',
'mozcrash/tests/manifest.ini',
'mozdevice/tests/manifest.ini',
'mozfile/tests/manifest.ini',
'mozhttpd/tests/manifest.ini',
'mozinfo/tests/manifest.ini',
'mozinstall/tests/manifest.ini',
'mozlog/tests/manifest.ini',
'moznetwork/tests/manifest.ini',
'mozprocess/tests/manifest.ini',
'mozprofile/tests/manifest.ini',
'mozrunner/tests/manifest.ini',
'moztest/tests/manifest.ini',
'mozversion/tests/manifest.ini',
]
python_modules = [
@ -33,6 +46,4 @@ TEST_HARNESS_FILES.mozbase += [m + '/**' for m in python_modules]
TEST_HARNESS_FILES.mozbase += [
'setup_development.py',
'test-manifest.ini',
'test.py',
]

Просмотреть файл

@ -1,24 +0,0 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# mozbase test manifest, in the format of
# http://mozbase.readthedocs.org/en/latest/manifestparser.html
# run with
# https://github.com/mozilla/mozbase/blob/master/test.py
[include:manifestparser/tests/manifest.ini]
[include:mozcrash/tests/manifest.ini]
[include:mozdevice/tests/manifest.ini]
[include:mozfile/tests/manifest.ini]
[include:mozhttpd/tests/manifest.ini]
[include:mozinfo/tests/manifest.ini]
[include:mozinstall/tests/manifest.ini]
[include:mozlog/tests/manifest.ini]
[include:moznetwork/tests/manifest.ini]
[include:mozprocess/tests/manifest.ini]
[include:mozprofile/tests/manifest.ini]
[include:mozrunner/tests/manifest.ini]
[include:moztest/tests/manifest.ini]
[include:mozversion/tests/manifest.ini]

Просмотреть файл

@ -1,104 +0,0 @@
#!/usr/bin/env python
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
"""
run mozbase tests from a manifest,
by default https://github.com/mozilla/mozbase/blob/master/test-manifest.ini
"""
import imp
import manifestparser
import mozinfo
import optparse
import os
import sys
import unittest
import mozlog
from moztest.results import TestResultCollection
from moztest.adapters.unit import StructuredTestRunner
here = os.path.dirname(os.path.abspath(__file__))
def unittests(path):
"""return the unittests in a .py file"""
path = os.path.abspath(path)
unittests = []
assert os.path.exists(path)
directory = os.path.dirname(path)
sys.path.insert(0, directory) # insert directory into path for top-level imports
modname = os.path.splitext(os.path.basename(path))[0]
module = imp.load_source(modname, path)
sys.path.pop(0) # remove directory from global path
loader = unittest.TestLoader()
suite = loader.loadTestsFromModule(module)
for test in suite:
unittests.append(test)
return unittests
def main(args=sys.argv[1:]):
# parse command line options
usage = '%prog [options] manifest.ini <manifest.ini> <...>'
parser = optparse.OptionParser(usage=usage, description=__doc__)
parser.add_option('-b', "--binary",
dest="binary", help="Binary path",
metavar=None, default=None)
parser.add_option('--list', dest='list_tests',
action='store_true', default=False,
help="list paths of tests to be run")
mozlog.commandline.add_logging_group(parser)
options, args = parser.parse_args(args)
logger = mozlog.commandline.setup_logging("mozbase", options,
{"tbpl": sys.stdout})
# read the manifest
if args:
manifests = args
else:
manifests = [os.path.join(here, 'test-manifest.ini')]
missing = []
for manifest in manifests:
# ensure manifests exist
if not os.path.exists(manifest):
missing.append(manifest)
assert not missing, 'manifest(s) not found: %s' % ', '.join(missing)
manifest = manifestparser.TestManifest(manifests=manifests)
if options.binary:
# A specified binary should override the environment variable
os.environ['BROWSER_PATH'] = options.binary
# gather the tests
tests = manifest.active_tests(disabled=False, **mozinfo.info)
tests = [test['path'] for test in tests]
logger.suite_start(tests)
if options.list_tests:
# print test paths
print '\n'.join(tests)
sys.exit(0)
# create unittests
unittestlist = []
for test in tests:
unittestlist.extend(unittests(test))
# run the tests
suite = unittest.TestSuite(unittestlist)
runner = StructuredTestRunner(logger=logger)
unittest_results = runner.run(suite)
results = TestResultCollection.from_unittest_results(None, unittest_results)
logger.suite_end()
# exit according to results
sys.exit(1 if results.num_failures else 0)
if __name__ == '__main__':
main()

Просмотреть файл

@ -6,12 +6,9 @@
TEST_DIRS += ['example']
if CONFIG['HOST_OS_ARCH'] != 'Darwin':
# Disabled on Mac due to our builders still being on MacOS 10.7,
# see bug 1255588
PYTHON_UNIT_TESTS += [
'selftest.py',
]
PYTHON_UNITTEST_MANIFESTS += [
'python.ini',
]
TESTING_JS_MODULES += [
'dbg-actors.js',

Просмотреть файл

@ -0,0 +1,3 @@
[selftest.py]
# Disabled on Mac due to our builders still being on MacOS 10.7, see bug 1255588
skip-if = os == "mac"

Просмотреть файл

@ -113,8 +113,8 @@ LOCAL_INCLUDES += [
'google-breakpad/src',
]
PYTHON_UNIT_TESTS += [
'tools/unit-symbolstore.py',
PYTHON_UNITTEST_MANIFESTS += [
'tools/python.ini',
]
include('/toolkit/crashreporter/crashreporter.mozbuild')

Просмотреть файл

@ -0,0 +1 @@
[unit-symbolstore.py]

Просмотреть файл

@ -4,8 +4,8 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
PYTHON_UNIT_TESTS += [
'runtests.py',
PYTHON_UNITTEST_MANIFESTS += [
'python.ini',
]
GENERATED_FILES += [

Просмотреть файл

@ -0,0 +1 @@
[runtests.py]

Просмотреть файл

@ -4,8 +4,8 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
PYTHON_UNIT_TESTS += [
'runtests.py',
PYTHON_UNITTEST_MANIFESTS += [
'python.ini',
]
SDK_FILES.bin += [

Просмотреть файл

@ -0,0 +1 @@
[runtests.py]