Skip to content

Commit 4b8dfb5

Browse files
committed
Bug 1630940 - Fix mach interface
Also add some tests to verify the enable telemetry setting gets picked up
1 parent 940ccb1 commit 4b8dfb5

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

mozregression/cli.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ def get_default_date_range(fetch_config):
462462

463463
class Configuration(object):
464464
"""
465-
Holds the configuration extracted from the command line.
465+
Holds the configuration extracted from the command line + configuration file.
466466
467467
This is usually instantiated by calling :func:`cli`.
468468
@@ -479,7 +479,7 @@ class Configuration(object):
479479
information about a build
480480
"""
481481

482-
def __init__(self, options):
482+
def __init__(self, options, config):
483483
self.options = options
484484
self.logger = init_logger(debug=options.debug)
485485
# allow to filter process output based on the user option
@@ -501,6 +501,8 @@ def __init__(self, options):
501501
None if re_ignore_mozversion_line.match(data["message"]) else data
502502
)
503503

504+
self.enable_telemetry = config["enable-telemetry"] not in ("no", "false", 0)
505+
504506
self.action = None
505507
self.fetch_config = None
506508

@@ -639,7 +641,6 @@ def cli(argv=None, conf_file=DEFAULT_CONF_FNAME, namespace=None):
639641
options = namespace
640642
else:
641643
options = parse_args(argv=argv, defaults=config)
642-
options.enable_telemetry = defaults["enable-telemetry"] not in ("no", "false", 0)
643644
if not options.cmdargs:
644645
# we don't set the cmdargs default to be that from the
645646
# configuration file, because then any new arguments
@@ -656,4 +657,4 @@ def cli(argv=None, conf_file=DEFAULT_CONF_FNAME, namespace=None):
656657
)
657658
print("*" * 10)
658659
print()
659-
return Configuration(options)
660+
return Configuration(options, config)

mozregression/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ def main(
333333

334334
app = Application(config.fetch_config, config.options)
335335
send_telemetry_ping_oop(
336-
mozregression_variant, config.fetch_config.app_name, config.options.enable_telemetry
336+
mozregression_variant, config.fetch_config.app_name, config.enable_telemetry
337337
)
338338

339339
method = getattr(app, config.action)

tests/unit/test_cli.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ def test_warn_invalid_build_type_in_conf(self):
110110
)
111111

112112

113-
def do_cli(*argv):
114-
conf = cli.cli(argv, conf_file=None)
113+
def do_cli(*argv, conf_file=None):
114+
conf = cli.cli(argv, conf_file=conf_file)
115115
conf.validate()
116116
return conf
117117

@@ -159,6 +159,8 @@ def test_no_args(os, bits, default_good_date):
159159
assert config.action == "bisect_nightlies"
160160
assert config.options.good == default_good_date
161161
assert config.options.bad == datetime.date.today()
162+
# telemetry is by default enabled
163+
assert config.enable_telemetry
162164

163165

164166
TODAY = datetime.date.today()
@@ -361,3 +363,13 @@ def test_get_default_date_range(app, os, bits, processor, build_type, expected_r
361363
fetch_config.set_build_type(build_type)
362364

363365
assert expected_range == cli.get_default_date_range(fetch_config)
366+
367+
368+
@pytest.mark.parametrize("enable_telemetry", (True, False))
369+
def test_telemetry(enable_telemetry):
370+
with tempfile.NamedTemporaryFile(mode="w", delete=False) as f:
371+
f.write("enable-telemetry = %s\n" % ("yes" if enable_telemetry else "no"))
372+
f.close()
373+
config = do_cli(conf_file=f.name)
374+
assert config.enable_telemetry is enable_telemetry
375+
os.unlink(f.name)

0 commit comments

Comments
 (0)