def assert_git_log_matches(golden_log_path: pathlib.Path): handle, git_log_path = tempfile.mkstemp(".log") log_cmd = ["git", "log", "-p", "--no-decorate"] log_cmd.extend(["--", ".", ":(exclude)synth.metadata"]) with os.fdopen(handle, "w") as git_log: subprocess.run(log_cmd, stdout=git_log) util.assert_git_logs_match(git_log_path, str(golden_log_path), log_lines_match)
def synthesize_loop_with_realistic_change_history( synthesize_loop_fixture: SynthesizeLoopFixture, multiple_prs: bool, golden_file: str): change_history = [ [ WriteFile("a.txt", "a"), NoChange(), NoChange(), NoChange(), WriteFile("b.txt", "b"), WriteFile("a.txt", "z"), ], [ NoChange(), Failed(), Failed(), WriteFile("c.txt", "c"), WriteFile("c.txt", "c-more"), NoChange(), ], ] source_versions = compile_histories(change_history, synthesize_loop_fixture.synthesizer) # Call synthesize_loop. synthesize_loop_fixture.synthesize_loop(source_versions, multiple_prs) # Confirm the git log looks like the golden log. handle, git_log_path = tempfile.mkstemp(".log") with os.fdopen(handle, "w") as git_log: subprocess.run( ["git", "log", "-p", "--no-decorate"], stdout=git_log, ) golden_log_path = str( pathlib.Path(__file__).parent / "testdata" / golden_file) util.assert_git_logs_match(git_log_path, golden_log_path) # Confirm that binary search yielded some benefit: for at least one version # synthesize was never called. flat_source_versions = [v for group in source_versions for v in group] versions_never_synthesized = [ v for v in flat_source_versions if v.synthesize_call_count == 0 ] assert len(versions_never_synthesized) > 0