def run_mach(tmpdir): """Return a function that runs mach with the provided arguments and then returns a list of the data contained within any telemetry entries generated during the command. """ # Use tmpdir as the mozbuild state path, and enable telemetry in # a machrc there. update_or_create_build_telemetry_config(text_type(tmpdir.join('machrc'))) env = dict(os.environ) env[b'MOZBUILD_STATE_PATH'] = str(tmpdir) env[b'MACH_TELEMETRY_NO_SUBMIT'] = b'1' # Let whatever mach command we invoke from tests believe it's the main command. del env['MACH_MAIN_PID'] mach = os.path.join(buildconfig.topsrcdir, 'mach') def run(*args, **kwargs): # Run mach with the provided arguments out = subprocess.check_output([sys.executable, mach] + list(args), stderr=subprocess.STDOUT, env=env, **kwargs) # Load any telemetry data that was written path = tmpdir.join('telemetry', 'outgoing') try: return [json.load(f.open('rb')) for f in path.listdir()] except EnvironmentError: print(TELEMETRY_LOAD_ERROR % out, file=sys.stderr) for p in path.parts(reverse=True): if not p.check(dir=1): print('Path does not exist: "%s"' % p, file=sys.stderr) raise return run
def run_mach(tmpdir): """Return a function that runs mach with the provided arguments and then returns a list of the data contained within any telemetry entries generated during the command. """ # Use tmpdir as the mozbuild state path, and enable telemetry in # a machrc there. update_or_create_build_telemetry_config(unicode(tmpdir.join('machrc'))) env = dict(os.environ) env[b'MOZBUILD_STATE_PATH'] = str(tmpdir) env[b'MACH_TELEMETRY_NO_SUBMIT'] = b'1' # Let whatever mach command we invoke from tests believe it's the main command. del env['MACH_MAIN_PID'] mach = os.path.join(buildconfig.topsrcdir, 'mach') def run(*args, **kwargs): # Run mach with the provided arguments subprocess.check_output([sys.executable, mach] + list(args), stderr=subprocess.STDOUT, env=env, **kwargs) # Load any telemetry data that was written path = unicode(tmpdir.join('telemetry', 'outgoing')) return [ json.load(open(os.path.join(path, f), 'rb')) for f in os.listdir(path) ] return run
def test_file_exists_no_build_section(config_path, write_config): write_config('''[foo] bar = 2 ''') update_or_create_build_telemetry_config(config_path) s = read(config_path) assert (s.build.telemetry) assert (s.foo.bar == 2)
def test_existing_build_section(config_path, write_config): write_config('''[foo] bar = 2 [build] abc = xyz ''') update_or_create_build_telemetry_config(config_path) s = read(config_path) assert (s.build.telemetry) assert (s.build.abc == 'xyz') assert (s.foo.bar == 2)
def test_existing_build_section(config_path, write_config): write_config( """[foo] bar = 2 [build] abc = xyz """ ) update_or_create_build_telemetry_config(config_path) s = read(config_path) assert s.build.telemetry assert s.build.abc == "xyz" assert s.foo.bar == 2
def run_mach(tmpdir): """Return a function that runs mach with the provided arguments and then returns a list of the data contained within any telemetry entries generated during the command. """ # Use tmpdir as the mozbuild state path, and enable telemetry in # a machrc there. if PY3: update_or_create_build_telemetry_config(str(tmpdir.join("machrc"))) else: update_or_create_build_telemetry_config( text_type(tmpdir.join("machrc"))) env = dict(os.environ) env["MOZBUILD_STATE_PATH"] = str(tmpdir) env["TEST_MACH_TELEMETRY_NO_SUBMIT"] = "1" mach = os.path.join(buildconfig.topsrcdir, "mach") def run(*args, **kwargs): # Let whatever mach command we invoke from tests believe it's the main command. mach_main_pid = env.pop("MACH_MAIN_PID") moz_automation = env.pop("MOZ_AUTOMATION", None) task_id = env.pop("TASK_ID", None) # Run mach with the provided arguments out = subprocess.check_output([sys.executable, mach] + list(args), stderr=subprocess.STDOUT, env=env, **kwargs) env["MACH_MAIN_PID"] = mach_main_pid env["MOZ_AUTOMATION"] = moz_automation env["TASK_ID"] = task_id # Load any telemetry data that was written path = tmpdir.join("telemetry", "outgoing") try: if PY3: read_mode = "r" else: read_mode = "rb" return [json.load(f.open(read_mode)) for f in path.listdir()] except EnvironmentError: print(TELEMETRY_LOAD_ERROR % out, file=sys.stderr) for p in path.parts(reverse=True): if not p.check(dir=1): print('Path does not exist: "%s"' % p, file=sys.stderr) raise return run
def test_malformed_file(config_path, write_config): """Ensure that a malformed config file doesn't cause breakage.""" write_config( """[foo bar = 1 """ ) assert not update_or_create_build_telemetry_config(config_path)
def test_nonexistent(config_path): update_or_create_build_telemetry_config(config_path) s = read(config_path) assert s.build.telemetry