diff --git a/remote_branch_rename/download.py b/remote_branch_rename/download.py index 0d572cc8..7ed5d6c3 100644 --- a/remote_branch_rename/download.py +++ b/remote_branch_rename/download.py @@ -2,11 +2,6 @@ def setup(verbose: bool = False): - checkout("try-quick-fix", True, verbose) - empty_commit("Fixed scrolling issue", verbose) - - checkout("main", False, verbose) - checkout("improve-loadding", True, verbose) empty_commit("Improved loading of page", verbose) diff --git a/remote_branch_rename/test_verify.py b/remote_branch_rename/test_verify.py index e5341910..4a2f1c6c 100644 --- a/remote_branch_rename/test_verify.py +++ b/remote_branch_rename/test_verify.py @@ -1,25 +1,21 @@ from contextlib import contextmanager from typing import Iterator, Tuple -from unittest.mock import patch from repo_smith.repo_smith import RepoSmith from exercise_utils.test import ( GitAutograderTest, GitAutograderTestLoader, - GitMasteryHelper, assert_output, ) from git_autograder import GitAutograderStatus from .verify import ( - FIX_SCROLLING_BUG_MISSING, IMPROVE_LOADING_LOCAL_MISSING, IMPROVE_LOADING_LOCAL_STILL_EXISTS, IMPROVE_LOADING_REMOTE_MISSING, IMPROVE_LOADING_REMOTE_OLD_PRESENT, - NO_RENAME_EVIDENCE_TRY_QUICK_FIX, - TRY_QUICK_FIX_STILL_EXISTS, + NO_RENAME_EVIDENCE_IMPROVE_LOADING, verify, ) @@ -30,100 +26,68 @@ @contextmanager def base_setup() -> Iterator[Tuple[GitAutograderTest, RepoSmith]]: - with loader.start() as (test, rs): - rs.git.commit(message="Empty", allow_empty=True) - rs.helper(GitMasteryHelper).create_start_tag() - rs.git.branch("try-quick-fix") + with loader.start(include_remote_repo=True) as (test, rs, rs_remote): + remote_path = str(rs_remote.repo.git_dir) + + rs.git.commit(message="Improved loading of page", allow_empty=True) + rs.git.remote_add("origin", remote_path) rs.git.branch("improve-loadding") + rs.git.push("origin", "improve-loadding") yield test, rs def test_base(): - with ( - patch("remote_branch_rename.verify.fetch_remotes", side_effect=None), - patch( - "remote_branch_rename.verify.get_remotes", return_value=["improve-loading"] - ), - base_setup() as (test, rs), - ): - rs.git.branch("fix-scrolling-bug", old_branch="try-quick-fix", move=True) - rs.git.branch("improve-loading", old_branch="improve-loadding", move=True) - - output = test.run() - assert_output(output, GitAutograderStatus.SUCCESSFUL) - - -def test_new_fix_scrolling_bug_branch(): - with base_setup() as (test, rs): - rs.git.branch("fix-scrolling-bug") - rs.git.branch("improve-loading", old_branch="improve-loadding", move=True) - - output = test.run() - assert_output( - output, GitAutograderStatus.UNSUCCESSFUL, [TRY_QUICK_FIX_STILL_EXISTS] - ) - - -def test_rename_quick_fix_wrong(): with base_setup() as (test, rs): - rs.git.branch("fix-scroling-bug", old_branch="try-quick-fix", move=True) rs.git.branch("improve-loading", old_branch="improve-loadding", move=True) + rs.git.push("origin", "improve-loading") + rs.git.push("origin", ":improve-loadding") output = test.run() - assert_output( - output, GitAutograderStatus.UNSUCCESSFUL, [FIX_SCROLLING_BUG_MISSING] - ) + assert_output(output, GitAutograderStatus.SUCCESSFUL) -def test_not_quick_fix_rename(): +def test_new_improve_loading_branch(): with base_setup() as (test, rs): - rs.git.branch("not-this", old_branch="try-quick-fix", move=True) - rs.git.branch("improve-loading", old_branch="improve-loadding", move=True) - rs.git.branch("fix-scrolling-bug") + rs.git.branch("improve-loading") output = test.run() assert_output( - output, GitAutograderStatus.UNSUCCESSFUL, [NO_RENAME_EVIDENCE_TRY_QUICK_FIX] + output, + GitAutograderStatus.UNSUCCESSFUL, + [IMPROVE_LOADING_LOCAL_STILL_EXISTS], ) -def test_new_improve_loading_branch(): +def test_rename_improve_loading_wrong(): with base_setup() as (test, rs): - rs.git.branch("fix-scrolling-bug", old_branch="try-quick-fix", move=True) - rs.git.branch("improve-loading") + rs.git.branch("improve-loaing", old_branch="improve-loadding", move=True) output = test.run() assert_output( output, GitAutograderStatus.UNSUCCESSFUL, - [IMPROVE_LOADING_LOCAL_STILL_EXISTS], + [IMPROVE_LOADING_LOCAL_MISSING], ) -def test_rename_improve_loading_wrong(): +def test_improve_loading_no_rename_evidence(): with base_setup() as (test, rs): - rs.git.branch("fix-scrolling-bug", old_branch="try-quick-fix", move=True) - rs.git.branch("improve-loaing", old_branch="improve-loadding", move=True) + rs.git.branch("improve-loading") + rs.git.branch("improve-loadding", delete=True) output = test.run() assert_output( output, GitAutograderStatus.UNSUCCESSFUL, - [IMPROVE_LOADING_LOCAL_MISSING], + [NO_RENAME_EVIDENCE_IMPROVE_LOADING], ) def test_improve_loadding_remote_exists(): - with ( - patch("remote_branch_rename.verify.fetch_remotes", side_effect=None), - patch( - "remote_branch_rename.verify.get_remotes", return_value=["improve-loadding"] - ), - base_setup() as (test, rs), - ): - rs.git.branch("fix-scrolling-bug", old_branch="try-quick-fix", move=True) + with base_setup() as (test, rs): rs.git.branch("improve-loading", old_branch="improve-loadding", move=True) + rs.git.push("origin", "improve-loading") output = test.run() assert_output( @@ -134,15 +98,9 @@ def test_improve_loadding_remote_exists(): def test_improve_loading_remote_missing(): - with ( - patch("remote_branch_rename.verify.fetch_remotes", side_effect=None), - patch( - "remote_branch_rename.verify.get_remotes", return_value=["improve-loaing"] - ), - base_setup() as (test, rs), - ): - rs.git.branch("fix-scrolling-bug", old_branch="try-quick-fix", move=True) + with base_setup() as (test, rs): rs.git.branch("improve-loading", old_branch="improve-loadding", move=True) + rs.git.push("origin", ":improve-loadding") output = test.run() assert_output( diff --git a/remote_branch_rename/verify.py b/remote_branch_rename/verify.py index e4d69736..3bc653aa 100644 --- a/remote_branch_rename/verify.py +++ b/remote_branch_rename/verify.py @@ -8,21 +8,13 @@ GitAutograderStatus, ) -TRY_QUICK_FIX_STILL_EXISTS = ( - "Branch 'try-quick-fix' still exists! Remember to rename it to 'fix-scrolling-bug'" -) -FIX_SCROLLING_BUG_MISSING = "Branch 'fix-scrolling-bug' is missing, did you correctly rename the branch 'try-quick-fix' to 'fix-scrolling-bug'?" -NO_RENAME_EVIDENCE_TRY_QUICK_FIX = ( - "Branch 'try-quick-fix' was not renamed to 'fix-scrolling-bug'!" -) - IMPROVE_LOADING_LOCAL_STILL_EXISTS = "Local branch 'improve-loadding' still exists! Remember to rename it to 'improve-loading'" IMPROVE_LOADING_LOCAL_MISSING = "Local branch 'improve-loading' is missing, did you correctly rename the branch 'improve-loadding' to 'improve-loading'?" NO_RENAME_EVIDENCE_IMPROVE_LOADING = ( "Local branch 'improve-loadding' was not renamed to 'improve-loading'!" ) IMPROVE_LOADING_REMOTE_MISSING = "Remote branch 'improve-loading' is missing, did you correctly push the renamed branch to the remote?" -IMPROVE_LOADING_REMOTE_OLD_PRESENT = "Remote branch 'improve-loadding' still exists! Remember to rename it to 'improve-loadding'" +IMPROVE_LOADING_REMOTE_OLD_PRESENT = "Remote branch 'improve-loadding' still exists! Remember to rename it to 'improve-loading'" def branch_has_rename_evidence( @@ -72,18 +64,8 @@ def has_remote(remotes: List[str], target: str) -> bool: def verify(exercise: GitAutograderExercise) -> GitAutograderOutput: repo: Repo = exercise.repo.repo - # try-quick-fix -> fix-scrolling-bug - local_branches = [h.name for h in repo.heads] - if "try-quick-fix" in local_branches: - raise exercise.wrong_answer([TRY_QUICK_FIX_STILL_EXISTS]) - - if "fix-scrolling-bug" not in local_branches: - raise exercise.wrong_answer([FIX_SCROLLING_BUG_MISSING]) - - if not branch_has_rename_evidence(exercise, "fix-scrolling-bug", "try-quick-fix"): - raise exercise.wrong_answer([NO_RENAME_EVIDENCE_TRY_QUICK_FIX]) - # improve-loadding -> improve-loading + local_branches = [h.name for h in repo.heads] if "improve-loadding" in local_branches: raise exercise.wrong_answer([IMPROVE_LOADING_LOCAL_STILL_EXISTS])