Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

about adding new lines, set this back to "new content" #96

Open
github-actions bot opened this issue Aug 14, 2022 · 0 comments
Open

about adding new lines, set this back to "new content" #96

github-actions bot opened this issue Aug 14, 2022 · 0 comments
Labels

Comments

@github-actions
Copy link
Contributor

about adding new lines, set this back to "new content"

# After fixing the TODO about adding new lines, set this back to "new content"

        )


def test_server_back_syncs_changes_from_project_to_template_with_subdir_copier(
    copier_output_subdir_template_repo: Repo,
):
    template_path = Path(copier_output_subdir_template_repo.working_dir)
    template_output_path = template_path / "output"
    folder_name = "project"
    project_path = GENERATED_FILES_DIR / folder_name
    expect_file = project_path / "a1.txt"
    template_file = template_output_path / "{{ q1 }}.txt.jinja"
    non_templated_template_file = template_output_path / "README.md"
    non_templated_expect_file = project_path / "README.md"
    config = FlexlateDevConfig()
    with run_server(
        config, None, template_path, GENERATED_FILES_DIR, no_input=True, back_sync=True
    ) as context:
        project_repo = Repo(project_path)

        wait_until_path_exists(expect_file)
        # Check initial load
        assert expect_file.read_text() == "1"
        templated_modified_time = expect_file.lstat().st_mtime
        assert non_templated_expect_file.read_text() == "some existing content"
        assert non_templated_template_file.read_text() == "some existing content"
        non_templated_modified_time = non_templated_template_file.lstat().st_mtime

        # Cause a back sync
        non_templated_expect_file.write_text("new content")
        stage_and_commit_all(project_repo, "Trigger back sync")

        # Check back sync
        wait_until_file_has_content(
            # After fixing the TODO about adding new lines, set this back to "new content"
            non_templated_template_file,
            non_templated_modified_time,
            "new content\n",
        )

        wait_until_returns_true(
            lambda: not context.is_back_syncing, "Back sync is still running"
        )

        # Cause a reload
        template_file.write_text("new content {{ q2 }}")

        # Check reload
        wait_until_file_has_content(
            expect_file, templated_modified_time, "new content 1"
        )


def test_server_does_not_back_sync_a_forward_sync_change(
    copier_one_template_repo: Repo,
):
    template_path = Path(copier_one_template_repo.working_dir)
    folder_name = "project"
    project_path = GENERATED_FILES_DIR / folder_name
    expect_file = project_path / "a1.txt"
    non_templated_template_file = template_path / "README.md"
    non_templated_expect_file = project_path / "README.md"
    config = FlexlateDevConfig()
    with run_server(
        config, None, template_path, GENERATED_FILES_DIR, no_input=True, back_sync=True
    ) as context:
        template_repo = Repo(template_path)

        wait_until_path_exists(expect_file)
        # Check initial load
        assert expect_file.read_text() == "1"
        assert non_templated_expect_file.read_text() == "some existing content"
        assert non_templated_template_file.read_text() == "some existing content"
        non_templated_expect_modified_time = non_templated_expect_file.lstat().st_mtime

        # Check the most recent commit on the template repo. It should not change after forward sync
        last_commit_sha = template_repo.head.commit.hexsha

        # Cause a forward-sync
        non_templated_template_file.write_text("new content")

        # Check forward sync
        wait_until_file_has_content(
            non_templated_expect_file,
            non_templated_expect_modified_time,
            "new content",
        )

        # Wait for back-sync to finish sleeping, so it has a chance to run
        wait_until_returns_true(
            lambda: not context.back_sync_is_sleeping, "Back sync is still sleeping"
        )
        # Wait another half second so that back-sync definitely would have run if it was going to
        time.sleep(0.5)
        # Give time for potential back-sync to complete
        wait_until_returns_true(
            lambda: not context.is_back_syncing, "Back sync is still running"
        )

        # Last commit on template repo should not have changed after back-sync
        assert template_repo.head.commit.hexsha == last_commit_sha


# TODO: add tests for back sync cookiecutter
# TODO: add tests for auto-commit, need to set up temp git repos

c2cb6557dd0c25c1bc1dfd92638bca1228cee9e7

@github-actions github-actions bot added the todo label Aug 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

0 participants