def test_run_information(exit_code, expected, **kwargs) -> None: with temporary_dir() as buildroot: with environment_as(PANTS_BUILDROOT_OVERRIDE=buildroot): run_tracker = RunTracker( create_options_bootstrapper([]).bootstrap_options) specs = ["src/python/pants/goal/run_tracker_test.py"] run_tracker.start(run_start_time=time.time(), specs=specs) run_information = run_tracker.run_information() assert run_information["buildroot"] == get_buildroot() assert run_information["path"] == get_buildroot() # freezegun doesn't seem to accurately mock the time zone, # (i.e. the time zone used depends on that of the machine that # executes the test), so we can only safely assert that the # month and year appear in the human-readable string contained # in the "datetime" key assert "Jan" in run_information["datetime"] assert "2020" in run_information["datetime"] assert run_information["timestamp"] == 1578657601.0 assert run_information["user"] == getpass.getuser() assert run_information["version"] == VERSION assert re.match("pants.*run_tracker_test.py", run_information["cmd_line"]) assert run_information["specs_from_command_line"] == [ "src/python/pants/goal/run_tracker_test.py" ] frozen_time = kwargs["frozen_time"] frozen_time.tick(delta=datetime.timedelta(seconds=1)) run_tracker.end_run(exit_code) run_information_after_ended = run_tracker.run_information() assert run_information_after_ended["outcome"] == expected
def test_run_information(exit_code: ExitCode, expected: str, tmp_path: Path, **kwargs) -> None: frozen_time = kwargs["frozen_time"] buildroot = tmp_path.as_posix() with environment_as(PANTS_BUILDROOT_OVERRIDE=buildroot): spec = "test/example.py" ob = create_options_bootstrapper(["list", spec]) run_tracker = RunTracker(ob.args, ob.bootstrap_options) specs = [spec] run_tracker.start(run_start_time=time.time(), specs=specs) run_information = run_tracker.run_information() assert run_information["buildroot"] == get_buildroot() assert run_information["path"] == get_buildroot() # freezegun doesn't seem to accurately mock the time zone, # (i.e. the time zone used depends on that of the machine that # executes the test), so we can only safely assert that the # month and year appear in the human-readable string contained # in the "datetime" key assert "Jan" in run_information["datetime"] assert "2020" in run_information["datetime"] assert run_information["timestamp"] == 1578657601.0 assert run_information["user"] == getpass.getuser() assert run_information["version"] == VERSION assert re.match(f"pants.*{spec}", run_information["cmd_line"]) assert run_information["specs_from_command_line"] == [spec] frozen_time.tick(delta=datetime.timedelta(seconds=1)) run_tracker.end_run(exit_code) run_information_after_ended = run_tracker.run_information() assert run_information_after_ended["outcome"] == expected