tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

mach_test_package_commands.py (1921B)


      1 # This Source Code Form is subject to the terms of the Mozilla Public
      2 # License, v. 2.0. If a copy of the MPL was not distributed with this
      3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
      4 
      5 import argparse
      6 import os
      7 import sys
      8 from functools import partial
      9 
     10 from mach.decorators import Command
     11 
     12 parser = None
     13 
     14 
     15 def run_marionette(context, **kwargs):
     16    from marionette.runtests import MarionetteHarness, MarionetteTestRunner
     17    from mozlog.structured import commandline
     18 
     19    args = argparse.Namespace(**kwargs)
     20    args.binary = args.binary or context.firefox_bin
     21 
     22    test_root = os.path.join(context.package_root, "marionette", "tests")
     23    if not args.tests:
     24        args.tests = [
     25            os.path.join(
     26                test_root,
     27                "testing",
     28                "marionette",
     29                "harness",
     30                "marionette_harness",
     31                "tests",
     32                "unit-tests.toml",
     33            )
     34        ]
     35 
     36    normalize = partial(context.normalize_test_path, test_root)
     37    args.tests = list(map(normalize, args.tests))
     38 
     39    commandline.add_logging_group(parser)
     40    parser.verify_usage(args)
     41 
     42    args.logger = commandline.setup_logging(
     43        "Marionette Unit Tests", args, {"mach": sys.stdout}
     44    )
     45    status = MarionetteHarness(MarionetteTestRunner, args=vars(args)).run()
     46    return 1 if status else 0
     47 
     48 
     49 def setup_marionette_argument_parser():
     50    from marionette.runner.base import BaseMarionetteArguments
     51 
     52    global parser
     53    parser = BaseMarionetteArguments()
     54    return parser
     55 
     56 
     57 @Command(
     58    "marionette-test",
     59    category="testing",
     60    description="Run a Marionette test (Check UI or the internal JavaScript "
     61    "using marionette).",
     62    parser=setup_marionette_argument_parser,
     63 )
     64 def run_marionette_test(command_context, **kwargs):
     65    command_context.context.activate_mozharness_venv()
     66    return run_marionette(command_context.context, **kwargs)