mach_test_package_commands.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. import argparse
  5. import os
  6. import sys
  7. from functools import partial
  8. from mach.decorators import (
  9. CommandProvider,
  10. Command,
  11. )
  12. parser = None
  13. def run_marionette(context, **kwargs):
  14. from marionette.runtests import (
  15. MarionetteTestRunner,
  16. MarionetteHarness
  17. )
  18. from mozlog.structured import commandline
  19. args = argparse.Namespace(**kwargs)
  20. args.binary = args.binary or context.firefox_bin
  21. args.e10s = context.mozharness_config.get('e10s', args.e10s)
  22. test_root = os.path.join(context.package_root, 'marionette', 'tests')
  23. if not args.tests:
  24. args.tests = [os.path.join(test_root, 'testing', 'marionette', 'harness',
  25. 'marionette_harness', 'tests', 'unit-tests.ini')]
  26. normalize = partial(context.normalize_test_path, test_root)
  27. args.tests = map(normalize, args.tests)
  28. commandline.add_logging_group(parser)
  29. parser.verify_usage(args)
  30. args.logger = commandline.setup_logging("Marionette Unit Tests",
  31. args,
  32. {"mach": sys.stdout})
  33. status = MarionetteHarness(MarionetteTestRunner, args=vars(args)).run()
  34. return 1 if status else 0
  35. def setup_marionette_argument_parser():
  36. from marionette.runner.base import BaseMarionetteArguments
  37. global parser
  38. parser = BaseMarionetteArguments()
  39. return parser
  40. @CommandProvider
  41. class MachCommands(object):
  42. def __init__(self, context):
  43. self.context = context
  44. @Command(
  45. 'marionette-test', category='testing',
  46. description='Run a Marionette test (Check UI or the internal JavaScript '
  47. 'using marionette).',
  48. parser=setup_marionette_argument_parser)
  49. def run_marionette_test(self, **kwargs):
  50. return run_marionette(self.context, **kwargs)