Exemplo n.º 1
0
def test_pull_request_interleaved_with_commit():
    """Test a the case where:
    1.  A pull request is generated.
    2.  A commit unrelated to the pull request gets merged.
    3.  The pull request gets merged.
    4.  Regenerate and create a new pull request.  Autosynth should be able to
        identify the changes triggered by #2.
    """
    with tempfile.TemporaryDirectory() as working_dir, util.OsChdirContext(
        working_dir
    ), tempfile.TemporaryDirectory() as temp_dir:
        text = make_working_repo(working_dir)
        metadata_path = os.path.join(working_dir, "synth.metadata")
        synthesizer = SimpleSynthesizer()
        versions = autosynth.git_source.enumerate_versions_for_working_repo(
            metadata_path, []
        )
        subprocess.check_call(["git", "branch", "test"])

        # Write version d in master.
        working_path = pathlib.Path(working_dir)
        subprocess.check_call(["git", "checkout", "master"])
        text = text.replace('"c\\n"', '"d\\n"')
        (working_path / "synth.py").write_text(text)
        subprocess.check_call(["git", "commit", "-am", "d"])

        subprocess.check_call(["git", "checkout", "test"])
        toolbox = autosynth.synth.SynthesizeLoopToolbox(
            [versions], "test", temp_dir, metadata_path, ""
        )
        autosynth.synth.synthesize_loop(toolbox, False, MockChangePusher(), synthesizer)

        # Merge in the pull request.
        subprocess.check_call(["git", "checkout", "master"])
        subprocess.check_call(["git", "merge", "--squash", "-X", "theirs", "test"])
        subprocess.check_call(["git", "commit", "-am", "merged PR"])

        # Create a second pull request.
        subprocess.check_call(["git", "checkout", "-b", "test2"])
        with open(metadata_path, "rb") as metadata_file:
            metadata: typing.Dict[str, typing.Any] = json.load(metadata_file)
        versions = autosynth.git_source.enumerate_versions_for_working_repo(
            metadata_path, metadata.get("sources", [])
        )
        toolbox = autosynth.synth.SynthesizeLoopToolbox(
            [versions], "test2", temp_dir, metadata_path, ""
        )
        autosynth.synth.synthesize_loop(toolbox, False, MockChangePusher(), synthesizer)

        assert_git_log_matches(
            pathlib.Path(__file__).parent
            / "testdata"
            / "test-pull-request-interleaved-with-commit.log"
        )
Exemplo n.º 2
0
def synthesize_loop_fixture(
) -> typing.Generator[SynthesizeLoopFixture, None, None]:
    with tempfile.TemporaryDirectory(
    ) as temp_dir, tempfile.TemporaryDirectory(
    ) as working_repo, util.OsChdirContext(working_repo):
        # Create a git repo with a README.
        subprocess.check_call(["git", "init", "."])
        with open("README.md", "wt") as readme:
            readme.write("Well done.")
        git.commit_all_changes("Added Readme")
        subprocess.check_call(["git", "checkout", "-b", "test"])
        # Create a synthesizer.
        yield SynthesizeLoopFixture(temp_dir)
Exemplo n.º 3
0
def test_working_repo():
    """Tests the tricky case where the working_repo is the one being iterated over."""
    with tempfile.TemporaryDirectory() as working_dir, util.OsChdirContext(
            working_dir), tempfile.TemporaryDirectory() as temp_dir:
        make_working_repo(working_dir)
        metadata_path = os.path.join(working_dir, "synth.metadata")
        synthesizer = SimpleSynthesizer()
        versions = autosynth.git_source.enumerate_versions_for_working_repo(
            metadata_path, [])
        subprocess.check_call(["git", "checkout", "-b", "test"])
        toolbox = autosynth.synth.SynthesizeLoopToolbox([versions], "test",
                                                        temp_dir,
                                                        metadata_path, "")
        assert 1 == autosynth.synth.synthesize_loop(toolbox, False,
                                                    MockChangePusher(),
                                                    synthesizer)
        assert_git_log_matches(
            pathlib.Path(__file__).parent / "testdata" /
            "test-working-repo-golden.log")
Exemplo n.º 4
0
def working_repo():
    with tempfile.TemporaryDirectory() as working_dir, util.OsChdirContext(
            working_dir):
        make_working_repo(working_dir)
        yield working_dir