Refactor/mock exercise test verify#284
Refactor/mock exercise test verify#284desmondwong1215 wants to merge 6 commits intogit-mastery:mainfrom
Conversation
|
Hi @desmondwong1215, thank you for your contribution! 🎉 This PR comes from your fork Before you request for a review, please ensure that you have tested your changes locally! Important The previously recommended way of using Please read the following instructions for the latest instructions. PrerequisitesEnsure that you have the Testing stepsIf you already have a local Git-Mastery root to test, you can skip the following step. Create a Git-Mastery root locally: gitmastery setupNavigate into the Git-Mastery root (defaults to cd gitmastery-exercises/Edit the {
# other fields...
"exercises_source": {
"username": "desmondwong1215",
"repository": "exercises",
"branch": "refactor/mock-exercise-test-verify"
}
}Then, you can use the gitmastery download <your new change>
gitmastery verifyChecklist
Important To any reviewers of this pull request, please use the same instructions above to test the changes. |
There was a problem hiding this comment.
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 toGitAutograderTestLoaderfor creating a lightweight mockGitAutograderExercisefrom a temp directory + generated.gitmastery-exercise.json. - Updated
clone_repo,fork_repo, andtags_pushtest_verify.pyfiles to useloader.start_mock_exercise()instead of per-test/fixture manual setup. - Adjusted exception assertions so they validate
GitAutograderWrongAnswerException.messageafter thepytest.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.
exercise_utils/test.py
Outdated
| repo_dir.mkdir(parents=True, exist_ok=True) | ||
|
|
||
| if init: | ||
| Repo.init(repo_dir) |
There was a problem hiding this comment.
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.
| 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) |
test_verifycases to use a sharedstart_mock_exercise()helper inGitAutograderTestLoader, reducing duplicated temp repo and config setup across exercises.clone_repo,fork-repo, andtags-pushtests so exception assertions run in the right place, and the mock exercise path matches the existing loader-based test style.