Bug 1568157 - Part 5: Move the NodePicker initialization into a getter. r=yulia
[gecko.git] / testing / marionette / mach_commands.py
blob2de9ca50c7c9dbce50135b221352a097967ca45a
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/.
5 from __future__ import absolute_import, print_function, unicode_literals
7 import argparse
8 import os
9 import sys
11 from mach.decorators import (
12 CommandProvider,
13 Command,
16 from mozbuild.base import (
17 MachCommandBase,
18 MachCommandConditions as conditions,
21 SUPPORTED_APPS = ['firefox', 'android', 'thunderbird']
23 def create_parser_tests():
24 from marionette_harness.runtests import MarionetteArguments
25 from mozlog.structured import commandline
27 parser = MarionetteArguments()
28 commandline.add_logging_group(parser)
29 return parser
32 def run_marionette(tests, binary=None, topsrcdir=None, **kwargs):
33 from mozlog.structured import commandline
35 from marionette_harness.runtests import (
36 MarionetteTestRunner,
37 MarionetteHarness
40 parser = create_parser_tests()
42 args = argparse.Namespace(tests=tests)
44 args.binary = binary
45 args.logger = kwargs.pop('log', None)
47 for k, v in kwargs.iteritems():
48 setattr(args, k, v)
50 parser.verify_usage(args)
52 if not args.logger:
53 args.logger = commandline.setup_logging("Marionette Unit Tests",
54 args,
55 {"mach": sys.stdout})
56 failed = MarionetteHarness(MarionetteTestRunner, args=vars(args)).run()
57 if failed > 0:
58 return 1
59 else:
60 return 0
63 def is_buildapp_in(*apps):
64 def is_buildapp_supported(cls):
65 for a in apps:
66 c = getattr(conditions, 'is_{}'.format(a), None)
67 if c and c(cls):
68 return True
69 return False
71 is_buildapp_supported.__doc__ = 'Must have a {} build.'.format(
72 ' or '.join(apps))
73 return is_buildapp_supported
76 @CommandProvider
77 class MarionetteTest(MachCommandBase):
78 @Command("marionette-test",
79 category="testing",
80 description="Remote control protocol to Gecko, used for browser automation.",
81 conditions=[is_buildapp_in(*SUPPORTED_APPS)],
82 parser=create_parser_tests,
84 def marionette_test(self, tests, **kwargs):
85 if "test_objects" in kwargs:
86 tests = []
87 for obj in kwargs["test_objects"]:
88 tests.append(obj["file_relpath"])
89 del kwargs["test_objects"]
91 if not tests:
92 if conditions.is_thunderbird(self):
93 tests = [os.path.join(self.topsrcdir,
94 "comm/testing/marionette/unit-tests.ini")]
95 else:
96 tests = [os.path.join(self.topsrcdir,
97 "testing/marionette/harness/marionette_harness/tests/unit-tests.ini")]
99 # Force disable e10s because it is not supported in Fennec
100 if kwargs.get("app") == "fennec":
101 kwargs["e10s"] = False
103 if not kwargs.get("binary") and \
104 (conditions.is_firefox(self) or conditions.is_thunderbird(self)):
105 kwargs["binary"] = self.get_binary_path("app")
107 return run_marionette(tests, topsrcdir=self.topsrcdir, **kwargs)