Skip to content

Refactor/mock exercise test verify#284

Open
desmondwong1215 wants to merge 6 commits intogit-mastery:mainfrom
desmondwong1215:refactor/mock-exercise-test-verify
Open

Refactor/mock exercise test verify#284
desmondwong1215 wants to merge 6 commits intogit-mastery:mainfrom
desmondwong1215:refactor/mock-exercise-test-verify

Conversation

@desmondwong1215
Copy link
Copy Markdown
Contributor

  • Refactor mock-only test_verify cases to use a shared start_mock_exercise() helper in GitAutograderTestLoader, reducing duplicated temp repo and config setup across exercises.
  • Clean up the clone_repo, fork-repo, and tags-push tests so exception assertions run in the right place, and the mock exercise path matches the existing loader-based test style.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 6, 2026

Hi @desmondwong1215, thank you for your contribution! 🎉

This PR comes from your fork desmondwong1215/exercises on branch refactor/mock-exercise-test-verify.

Before you request for a review, please ensure that you have tested your changes locally!

Important

The previously recommended way of using ./test-download.py is no longer the best way to test your changes locally.

Please read the following instructions for the latest instructions.

Prerequisites

Ensure that you have the gitmastery app installed locally (instructions)

Testing steps

If you already have a local Git-Mastery root to test, you can skip the following step.

Create a Git-Mastery root locally:

gitmastery setup

Navigate into the Git-Mastery root (defaults to gitmastery-exercises/):

cd gitmastery-exercises/

Edit the .gitmastery.json configuration file. You need to set the following values under the exercises_source key.

{
    # other fields...
    "exercises_source": {
        "username": "desmondwong1215",
        "repository": "exercises",
        "branch": "refactor/mock-exercise-test-verify"
    }
}

Then, you can use the gitmastery app to download and verify your changes locally.

gitmastery download <your new change>
gitmastery verify

Checklist

  • (For exercises and hands-ons) I have verified that the downloading behavior works
  • (For exercises only) I have verified that the verification behavior is accurate

Important

To any reviewers of this pull request, please use the same instructions above to test the changes.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors several mock-heavy test_verify suites to use a shared GitAutograderTestLoader.start_mock_exercise() helper, reducing duplicated temporary exercise repo/config setup and making exception assertions more consistent.

Changes:

  • Added start_mock_exercise() context manager to GitAutograderTestLoader for creating a lightweight mock GitAutograderExercise from a temp directory + generated .gitmastery-exercise.json.
  • Updated clone_repo, fork_repo, and tags_push test_verify.py files to use loader.start_mock_exercise() instead of per-test/fixture manual setup.
  • Adjusted exception assertions so they validate GitAutograderWrongAnswerException.message after the pytest.raises(...) context.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
exercise_utils/test.py Introduces GitAutograderTestLoader.start_mock_exercise() helper to create a temp exercise + config for mock-only tests.
clone_repo/test_verify.py Migrates mock-only verification tests to start_mock_exercise() and updates exception assertions.
fork_repo/test_verify.py Migrates mock-only verification tests to start_mock_exercise() and updates exception assertions.
tags_push/test_verify.py Migrates mock-only verification tests to start_mock_exercise() and updates exception assertions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +300 to +303
repo_dir.mkdir(parents=True, exist_ok=True)

if init:
Repo.init(repo_dir)
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

start_mock_exercise() currently always creates repo_dir and can run Repo.init(repo_dir) whenever init=True, even when repo_type is set to values like "ignore" or "remote". In this repo’s exercise config conventions, repo_type="ignore" means the repo isn’t created at all, and init can be null/None (see existing exercise configs and scripts). Consider making init Optional[bool] (to allow None) and only creating/initializing a git repo when repo_type == "local" and init is True; for ignore you should typically skip repo creation entirely.

Suggested change
repo_dir.mkdir(parents=True, exist_ok=True)
if init:
Repo.init(repo_dir)
if repo_type == "local":
repo_dir.mkdir(parents=True, exist_ok=True)
if init is True:
Repo.init(repo_dir)

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants