-
Notifications
You must be signed in to change notification settings - Fork 10
Make E2E tests more comprehensive and less flaky #58
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b68300b
Make E2E tests more comprehensive and less flaky
jovnc 4316e20
Address copilot review comments
jovnc 2f67a71
Clean up code
jovnc c685eb7
Update fixtures for better session management to speed up E2E tests
jovnc c31a65c
Add pytest-order to requirements and update test_progress.py for orde…
jovnc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| click | ||
| pytest | ||
| pytest-order | ||
| mypy | ||
| pyinstaller | ||
| requests | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,28 +1,20 @@ | ||
| import json | ||
| from pathlib import Path | ||
|
|
||
| from ..constants import EXERCISE_NAME, HANDS_ON_NAME | ||
| from ..runner import BinaryRunner | ||
| from ..constants import EXERCISE_NAME | ||
|
|
||
|
|
||
| def test_download_exercise(runner: BinaryRunner, exercises_dir: Path) -> None: | ||
| """Test the download command output successfully performs the download for exercise.""" | ||
| res = runner.run(["download", EXERCISE_NAME], cwd=exercises_dir) | ||
| res.assert_success() | ||
| def test_download_exercise(downloaded_exercise_dir: Path) -> None: | ||
| """download creates the exercise folder with its config and README.""" | ||
| assert downloaded_exercise_dir.is_dir() | ||
|
|
||
| exercise_folder = exercises_dir / EXERCISE_NAME | ||
| assert exercise_folder.is_dir() | ||
|
|
||
| exercise_config = exercise_folder / ".gitmastery-exercise.json" | ||
| exercise_config = downloaded_exercise_dir / ".gitmastery-exercise.json" | ||
| assert exercise_config.is_file() | ||
| assert json.loads(exercise_config.read_text())["exercise_name"] == EXERCISE_NAME | ||
|
|
||
| exercise_readme = exercise_folder / "README.md" | ||
| assert exercise_readme.is_file() | ||
|
|
||
| assert (downloaded_exercise_dir / "README.md").is_file() | ||
|
|
||
| def test_download_hands_on(runner: BinaryRunner, exercises_dir: Path) -> None: | ||
| """Test the download command output successfully performs the download for hands-on.""" | ||
| res = runner.run(["download", HANDS_ON_NAME], cwd=exercises_dir) | ||
| res.assert_success() | ||
|
|
||
| hands_on_folder = exercises_dir / HANDS_ON_NAME | ||
| assert hands_on_folder.is_dir() | ||
| def test_download_hands_on(downloaded_hands_on_dir: Path) -> None: | ||
| """download creates the hands-on folder.""" | ||
|
jovnc marked this conversation as resolved.
|
||
| assert downloaded_hands_on_dir.is_dir() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,36 +1,38 @@ | ||
| import json | ||
| from pathlib import Path | ||
| import pytest | ||
|
|
||
| from ..constants import EXERCISE_NAME | ||
| from ..runner import BinaryRunner | ||
|
|
||
|
|
||
| def test_progress_show(runner: BinaryRunner, exercises_dir: Path) -> None: | ||
| """Test that progress show displays progress.""" | ||
| res = runner.run(["progress", "show"], cwd=exercises_dir) | ||
| def test_progress_show(runner: BinaryRunner, gitmastery_root: Path) -> None: | ||
| """progress show displays the progress header.""" | ||
| res = runner.run(["progress", "show"], cwd=gitmastery_root) | ||
| res.assert_success() | ||
| res.assert_stdout_contains("Your Git-Mastery progress:") | ||
|
|
||
|
|
||
| def test_progress_sync_on_then_off(runner: BinaryRunner, exercises_dir: Path) -> None: | ||
| """Test that progress sync on followed by sync off works correctly.""" | ||
| # Enable sync | ||
| res_on = runner.run(["progress", "sync", "on"], cwd=exercises_dir) | ||
| def test_progress_sync_on_then_off(runner: BinaryRunner, gitmastery_root: Path) -> None: | ||
| """progress sync on/off toggles progress_remote in the config.""" | ||
| res_on = runner.run(["progress", "sync", "on"], cwd=gitmastery_root) | ||
| res_on.assert_success() | ||
| res_on.assert_stdout_contains( | ||
| "You have setup the progress tracker for Git-Mastery!" | ||
| ) | ||
| res_on.assert_stdout_contains("You have setup the progress tracker for Git-Mastery!") | ||
| assert json.loads((gitmastery_root / ".gitmastery.json").read_text())["progress_remote"] is True | ||
|
|
||
| # Disable sync (send 'y' to confirm) | ||
| # send 'y' to confirm | ||
| res_off = runner.run( | ||
| ["progress", "sync", "off"], cwd=exercises_dir, stdin_text="y\n" | ||
| ["progress", "sync", "off"], cwd=gitmastery_root, stdin_text="y\n" | ||
| ) | ||
| res_off.assert_success() | ||
| res_off.assert_stdout_contains("Successfully removed your remote sync") | ||
| assert json.loads((gitmastery_root / ".gitmastery.json").read_text())["progress_remote"] is False | ||
|
|
||
|
|
||
| def test_progress_reset(runner: BinaryRunner, exercises_dir: Path) -> None: | ||
| """Test that progress reset works correctly after verify has run.""" | ||
| exercise_dir = exercises_dir / EXERCISE_NAME | ||
| res = runner.run(["progress", "reset"], cwd=exercise_dir) | ||
| # TODO: verify that the progress has actually been reset | ||
| @pytest.mark.order(after="tests/e2e/commands/test_verify.py::test_verify_exercise") | ||
| def test_progress_reset(runner: BinaryRunner, verified_exercise_dir: Path) -> None: | ||
| """progress reset removes the current exercise's entry from progress.json.""" | ||
| res = runner.run(["progress", "reset"], cwd=verified_exercise_dir) | ||
| res.assert_success() | ||
| progress_json = verified_exercise_dir.parent / "progress" / "progress.json" | ||
| # TODO: need to verify that the exercise itself progress was reset, not just progress.json was cleared | ||
| assert json.loads(progress_json.read_text()) == [] | ||
|
jovnc marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,20 @@ | ||
| import json | ||
| from pathlib import Path | ||
|
|
||
|
|
||
| def test_setup(exercises_dir: Path) -> None: | ||
| """ | ||
| Test that setup creates the progress directory, progress.json, .gitmastery.json and .gitmastery.log | ||
| Setup command already called in conftest.py for test setup | ||
| """ | ||
| progress_dir = exercises_dir / "progress" | ||
| assert progress_dir.is_dir(), f"Expected {progress_dir} to exist" | ||
| def test_setup(setup_gitmastery_root: Path) -> None: | ||
| """setup creates the expected directory structure, config, and empty progress file.""" | ||
| progress_dir = setup_gitmastery_root / "progress" | ||
| assert progress_dir.is_dir() | ||
|
|
||
| progress_file = progress_dir / "progress.json" | ||
| assert progress_file.is_file(), f"Expected {progress_file} to exist" | ||
| assert progress_file.is_file() | ||
| assert json.loads(progress_file.read_text()) == [] | ||
|
|
||
| config_file = exercises_dir / ".gitmastery.json" | ||
| assert config_file.is_file(), f"Expected {config_file} to exist" | ||
| config_file = setup_gitmastery_root / ".gitmastery.json" | ||
| assert config_file.is_file() | ||
| config = json.loads(config_file.read_text()) | ||
| assert config["progress_local"] is True | ||
| assert config["progress_remote"] is False | ||
|
|
||
| log_file = exercises_dir / ".gitmastery.log" | ||
| assert log_file.is_file(), f"Expected {log_file} to exist" | ||
| assert (setup_gitmastery_root / ".gitmastery.log").is_file() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,16 @@ | ||
| import json | ||
| from pathlib import Path | ||
|
|
||
| from ..constants import EXERCISE_NAME | ||
| from ..runner import BinaryRunner | ||
|
|
||
|
|
||
| def test_verify_exercise(runner: BinaryRunner, exercises_dir: Path) -> None: | ||
| """Test that verify runs on a downloaded exercise.""" | ||
| exercise_dir = exercises_dir / EXERCISE_NAME | ||
| res = runner.run(["verify"], cwd=exercise_dir) | ||
| res.assert_success() | ||
| # TODO: check that the correct tests have been run | ||
| res.assert_stdout_contains("Starting verification of") | ||
| res.assert_stdout_contains("Verification completed.") | ||
| def test_verify_exercise(verified_exercise_dir: Path) -> None: | ||
| """verify writes a progress entry with the expected fields.""" | ||
| progress_json = verified_exercise_dir.parent / "progress" / "progress.json" | ||
| entries = json.loads(progress_json.read_text()) | ||
| assert len(entries) == 1 | ||
| entry = entries[0] | ||
|
jovnc marked this conversation as resolved.
|
||
| assert entry["exercise_name"] == EXERCISE_NAME | ||
| assert "started_at" in entry | ||
| assert "completed_at" in entry | ||
| assert "status" in entry | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.