def runtests(setup_test_harness, binary, parser): setup_test_harness(*setup_args) runreftest = pytest.importorskip('runreftest') harness_root = runreftest.SCRIPT_DIRECTORY buf = StringIO() build = parser.build_obj options = vars(parser.parse_args([])) options.update({ 'app': binary, 'focusFilterMode': 'non-needs-focus', 'log_raw': [buf], 'suite': 'reftest', 'specialPowersExtensionPath': os.path.join(harness_root, 'specialpowers'), }) if not os.path.isdir(build.bindir): package_root = os.path.dirname(harness_root) options.update({ 'extraProfileFiles': [os.path.join(package_root, 'bin', 'plugins')], 'reftestExtensionPath': os.path.join(harness_root, 'reftest'), 'sandboxReadWhitelist': [here, os.environ['PYTHON_TEST_TMP']], 'utilityPath': os.path.join(package_root, 'bin'), }) if 'MOZ_FETCHES_DIR' in os.environ: options['sandboxReadWhitelist'].append( os.environ['MOZ_FETCHES_DIR']) else: options.update({ 'extraProfileFiles': [os.path.join(build.topobjdir, 'dist', 'plugins')], 'sandboxReadWhitelist': [build.topobjdir, build.topsrcdir], }) def normalize(test): if os.path.isabs(test): return test return os.path.join(here, 'files', test) def inner(*tests, **opts): assert len(tests) > 0 tests = map(normalize, tests) options['tests'] = tests options.update(opts) result = runreftest.run_test_harness(parser, Namespace(**options)) out = json.loads('[' + ','.join(buf.getvalue().splitlines()) + ']') buf.close() return result, out return inner
def get_reftest(setup_test_harness, binary, parser): setup_test_harness(*setup_args) runreftest = pytest.importorskip("runreftest") harness_root = runreftest.SCRIPT_DIRECTORY build = parser.build_obj options = vars(parser.parse_args([])) options.update({ "app": binary, "focusFilterMode": "non-needs-focus", "suite": "reftest", }) if not os.path.isdir(build.bindir): package_root = os.path.dirname(harness_root) options.update({ "extraProfileFiles": [os.path.join(package_root, "bin", "plugins")], "reftestExtensionPath": os.path.join(harness_root, "reftest"), "sandboxReadWhitelist": [here, os.environ["PYTHON_TEST_TMP"]], "utilityPath": os.path.join(package_root, "bin"), "specialPowersExtensionPath": os.path.join(harness_root, "specialpowers"), }) if "MOZ_FETCHES_DIR" in os.environ: options["sandboxReadWhitelist"].append( os.environ["MOZ_FETCHES_DIR"]) else: options.update({ "extraProfileFiles": [os.path.join(build.topobjdir, "dist", "plugins")], "sandboxReadWhitelist": [build.topobjdir, build.topsrcdir], "specialPowersExtensionPath": os.path.join(build.distdir, "xpi-stage", "specialpowers"), }) def inner(**opts): options.update(opts) config = Namespace(**options) # This is pulled from `runreftest.run_test_harness` minus some error # checking that isn't necessary in this context. It should stay roughly # in sync. reftest = runreftest.RefTest(config.suite) parser.validate(config, reftest) config.app = reftest.getFullPath(config.app) assert os.path.exists(config.app) if config.xrePath is None: config.xrePath = os.path.dirname(config.app) return reftest, config return inner
def get_reftest(setup_test_harness, binary, parser): setup_test_harness(*setup_args) runreftest = pytest.importorskip('runreftest') harness_root = runreftest.SCRIPT_DIRECTORY build = parser.build_obj options = vars(parser.parse_args([])) options.update({ 'app': binary, 'focusFilterMode': 'non-needs-focus', 'suite': 'reftest', }) if not os.path.isdir(build.bindir): package_root = os.path.dirname(harness_root) options.update({ 'extraProfileFiles': [os.path.join(package_root, 'bin', 'plugins')], 'reftestExtensionPath': os.path.join(harness_root, 'reftest'), 'sandboxReadWhitelist': [here, os.environ['PYTHON_TEST_TMP']], 'utilityPath': os.path.join(package_root, 'bin'), 'specialPowersExtensionPath': os.path.join(harness_root, 'specialpowers'), }) if 'MOZ_FETCHES_DIR' in os.environ: options['sandboxReadWhitelist'].append( os.environ['MOZ_FETCHES_DIR']) else: options.update({ 'extraProfileFiles': [os.path.join(build.topobjdir, 'dist', 'plugins')], 'sandboxReadWhitelist': [build.topobjdir, build.topsrcdir], 'specialPowersExtensionPath': os.path.join(build.distdir, 'xpi-stage', 'specialpowers'), }) def inner(**opts): options.update(opts) config = Namespace(**options) # This is pulled from `runreftest.run_test_harness` minus some error # checking that isn't necessary in this context. It should stay roughly # in sync. reftest = runreftest.RefTest(config.suite) parser.validate(config, reftest) config.app = reftest.getFullPath(config.app) assert os.path.exists(config.app) if config.xrePath is None: config.xrePath = os.path.dirname(config.app) return reftest, config return inner
def runtests(setup_test_harness, binary, parser, request): """Creates an easy to use entry point into the mochitest harness. :returns: A function with the signature `*tests, **opts`. Each test is a file name (relative to the `files` dir). At least one is required. The opts are used to override the default mochitest options, they are optional. """ setup_test_harness(*setup_args) runtests = pytest.importorskip('runtests') mochitest_root = runtests.SCRIPT_DIR test_root = os.path.join(mochitest_root, 'tests', 'selftests') buf = StringIO() options = vars(parser.parse_args([])) options.update({ 'app': binary, 'keep_open': False, 'log_raw': [buf], }) if not os.path.isdir(runtests.build_obj.bindir): package_root = os.path.dirname(mochitest_root) options.update({ 'certPath': os.path.join(package_root, 'certs'), 'utilityPath': os.path.join(package_root, 'bin'), }) options['extraProfileFiles'].append( os.path.join(package_root, 'bin', 'plugins')) options.update(getattr(request.module, 'OPTIONS', {})) def normalize(test): return { 'name': test, 'relpath': test, 'path': os.path.join(test_root, test), # add a dummy manifest file because mochitest expects it 'manifest': os.path.join(test_root, 'mochitest.ini'), 'manifest_relpath': 'mochitest.ini', } def inner(*tests, **opts): assert len(tests) > 0 manifest = TestManifest() manifest.tests.extend(map(normalize, tests)) options['manifestFile'] = manifest options.update(opts) result = runtests.run_test_harness(parser, Namespace(**options)) out = json.loads('[' + ','.join(buf.getvalue().splitlines()) + ']') buf.close() return result, out return inner
def runtests(setup_test_harness, binary, parser, request): """Creates an easy to use entry point into the mochitest harness. :returns: A function with the signature `*tests, **opts`. Each test is a file name (relative to the `files` dir). At least one is required. The opts are used to override the default mochitest options, they are optional. """ setup_test_harness(*setup_args) runtests = pytest.importorskip("runtests") mochitest_root = runtests.SCRIPT_DIR test_root = os.path.join(mochitest_root, "tests", "selftests") buf = StringIO() options = vars(parser.parse_args([])) options.update({ "app": binary, "keep_open": False, "log_raw": [buf], }) if not os.path.isdir(runtests.build_obj.bindir): package_root = os.path.dirname(mochitest_root) options.update({ "certPath": os.path.join(package_root, "certs"), "utilityPath": os.path.join(package_root, "bin"), }) options["extraProfileFiles"].append( os.path.join(package_root, "bin", "plugins")) options.update(getattr(request.module, "OPTIONS", {})) def normalize(test): return { "name": test, "relpath": test, "path": os.path.join(test_root, test), # add a dummy manifest file because mochitest expects it "manifest": os.path.join(test_root, "mochitest.ini"), "manifest_relpath": "mochitest.ini", } def inner(*tests, **opts): assert len(tests) > 0 manifest = TestManifest() manifest.tests.extend(map(normalize, tests)) options["manifestFile"] = manifest options.update(opts) result = runtests.run_test_harness(parser, Namespace(**options)) out = json.loads("[" + ",".join(buf.getvalue().splitlines()) + "]") buf.close() return result, out return inner
def runtests(setup_test_harness, binary, parser, request): """Creates an easy to use entry point into the mochitest harness. :returns: A function with the signature `*tests, **opts`. Each test is a file name (relative to the `files` dir). At least one is required. The opts are used to override the default mochitest options, they are optional. """ setup_test_harness(*setup_args) runtests = pytest.importorskip('runtests') mochitest_root = runtests.SCRIPT_DIR test_root = os.path.join(mochitest_root, 'tests', 'selftests') buf = StringIO() options = vars(parser.parse_args([])) options.update({ 'app': binary, 'keep_open': False, 'log_raw': [buf], }) if not os.path.isdir(runtests.build_obj.bindir): package_root = os.path.dirname(mochitest_root) options.update({ 'certPath': os.path.join(package_root, 'certs'), 'utilityPath': os.path.join(package_root, 'bin'), }) options['extraProfileFiles'].append(os.path.join(package_root, 'bin', 'plugins')) options.update(getattr(request.module, 'OPTIONS', {})) def normalize(test): return { 'name': test, 'relpath': test, 'path': os.path.join(test_root, test), # add a dummy manifest file because mochitest expects it 'manifest': os.path.join(test_root, 'mochitest.ini'), } def inner(*tests, **opts): assert len(tests) > 0 manifest = TestManifest() manifest.tests.extend(map(normalize, tests)) options['manifestFile'] = manifest options.update(opts) result = runtests.run_test_harness(parser, Namespace(**options)) out = json.loads('[' + ','.join(buf.getvalue().splitlines()) + ']') buf.close() return result, out return inner
def runtests(setup_test_harness, binary, parser): setup_test_harness(*setup_args) runreftest = pytest.importorskip('runreftest') harness_root = runreftest.SCRIPT_DIRECTORY buf = StringIO() build = parser.build_obj options = vars(parser.parse_args([])) options.update({ 'app': binary, 'focusFilterMode': 'non-needs-focus', 'log_raw': [buf], 'suite': 'reftest', 'specialPowersExtensionPath': os.path.join(harness_root, 'specialpowers'), }) if not os.path.isdir(build.bindir): package_root = os.path.dirname(harness_root) options.update({ 'extraProfileFiles': [os.path.join(package_root, 'bin', 'plugins')], 'reftestExtensionPath': os.path.join(harness_root, 'reftest'), 'sandboxReadWhitelist': [here, os.environ['PYTHON_TEST_TMP']], 'utilityPath': os.path.join(package_root, 'bin'), }) else: options.update({ 'extraProfileFiles': [os.path.join(build.topobjdir, 'dist', 'plugins')], 'sandboxReadWhitelist': [build.topobjdir, build.topsrcdir], }) def normalize(test): if os.path.isabs(test): return test return os.path.join(here, 'files', test) def inner(*tests, **opts): assert len(tests) > 0 tests = map(normalize, tests) options['tests'] = tests options.update(opts) result = runreftest.run_test_harness(parser, Namespace(**options)) out = json.loads('[' + ','.join(buf.getvalue().splitlines()) + ']') buf.close() return result, out return inner
def skip_using_mozinfo(request, setup_test_harness): """Gives tests the ability to skip based on values from mozinfo. Example: @pytest.mark.skip_mozinfo("!e10s || os == 'linux'") def test_foo(): pass """ setup_test_harness(*setup_args) runreftest = pytest.importorskip("runreftest") runreftest.update_mozinfo() skip_mozinfo = request.node.get_marker("skip_mozinfo") if skip_mozinfo: value = skip_mozinfo.args[0] if expression.parse(value, **mozinfo.info): pytest.skip("skipped due to mozinfo match: \n{}".format(value))
def skip_using_mozinfo(request, setup_test_harness): """Gives tests the ability to skip based on values from mozinfo. Example: @pytest.mark.skip_mozinfo("!e10s || os == 'linux'") def test_foo(): pass """ setup_test_harness(*setup_args) runreftest = pytest.importorskip('runreftest') runreftest.update_mozinfo() skip_mozinfo = request.node.get_marker('skip_mozinfo') if skip_mozinfo: value = skip_mozinfo.args[0] if expression.parse(value, **mozinfo.info): pytest.skip("skipped due to mozinfo match: \n{}".format(value))
def parser(setup_test_harness): setup_test_harness(*setup_args) cmdline = pytest.importorskip("reftestcommandline") return cmdline.DesktopArgumentsParser()
def parser(setup_test_harness): setup_test_harness(*setup_args) cmdline = pytest.importorskip('reftestcommandline') return cmdline.DesktopArgumentsParser()
def build_obj(setup_test_harness): setup_test_harness(*setup_args) mochitest_options = pytest.importorskip("mochitest_options") return mochitest_options.build_obj
def runtests(setup_test_harness, binary, parser, request): """Creates an easy to use entry point into the mochitest harness. :returns: A function with the signature `*tests, **opts`. Each test is a file name (relative to the `files` dir). At least one is required. The opts are used to override the default mochitest options, they are optional. """ flavor = "plain" if "flavor" in request.fixturenames: flavor = request.getfixturevalue("flavor") runFailures = "" if "runFailures" in request.fixturenames: runFailures = request.getfixturevalue("runFailures") setup_test_harness(*setup_args, flavor=flavor) runtests = pytest.importorskip("runtests") mochitest_root = runtests.SCRIPT_DIR if flavor == "plain": test_root = os.path.join(mochitest_root, "tests", "selftests") manifest_name = "mochitest.ini" elif flavor == "browser-chrome": test_root = os.path.join(mochitest_root, "browser", "tests", "selftests") manifest_name = "browser.ini" else: raise Exception(f"Invalid flavor {flavor}!") # pylint --py3k: W1648 buf = six.StringIO() options = vars(parser.parse_args([])) options.update( { "app": binary, "flavor": flavor, "runFailures": runFailures, "keep_open": False, "log_raw": [buf], } ) if runFailures == "selftest": options["crashAsPass"] = True options["timeoutAsPass"] = True if not os.path.isdir(runtests.build_obj.bindir): package_root = os.path.dirname(mochitest_root) options.update( { "certPath": os.path.join(package_root, "certs"), "utilityPath": os.path.join(package_root, "bin"), } ) options["extraProfileFiles"].append( os.path.join(package_root, "bin", "plugins") ) options.update(getattr(request.module, "OPTIONS", {})) def normalize(test): return { "name": test, "relpath": test, "path": os.path.join(test_root, test), # add a dummy manifest file because mochitest expects it "manifest": os.path.join(test_root, manifest_name), "manifest_relpath": manifest_name, "skip-if": runFailures, } def inner(*tests, **opts): assert len(tests) > 0 manifest = TestManifest() # pylint --py3k: W1636 manifest.tests.extend(list(map(normalize, tests))) options["manifestFile"] = manifest options.update(opts) result = runtests.run_test_harness(parser, Namespace(**options)) out = json.loads("[" + ",".join(buf.getvalue().splitlines()) + "]") buf.close() return result, out return inner
def build_obj(setup_test_harness): setup_test_harness(*setup_args) mochitest_options = pytest.importorskip('mochitest_options') return mochitest_options.build_obj