-
Notifications
You must be signed in to change notification settings - Fork 67
fix: replace list.remove() during iteration with comprehension filtering #443
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,224 @@ | ||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||
| Tests for the list-mutation-during-iteration fixes in DataFileClass. | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| Validates that deleteScenarioCaseRuns and deleteCaseRun correctly | ||||||||||||||||||||||||||||||
| remove *all* matching entries, not just the first one — the old code | ||||||||||||||||||||||||||||||
| called list.remove() inside a for-loop, which skips elements when | ||||||||||||||||||||||||||||||
| the list shrinks mid-iteration. | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| These tests are self-contained and do not require Flask or the app. | ||||||||||||||||||||||||||||||
| They test the pure-Python logic by constructing the DataFile object | ||||||||||||||||||||||||||||||
| with mocked filesystem paths. | ||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| import json | ||||||||||||||||||||||||||||||
| import sys | ||||||||||||||||||||||||||||||
| from pathlib import Path | ||||||||||||||||||||||||||||||
| from unittest.mock import patch, MagicMock | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| import pytest | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # Ensure the API directory is on sys.path so we can import the classes | ||||||||||||||||||||||||||||||
| API_DIR = str(Path(__file__).resolve().parent.parent / "API") | ||||||||||||||||||||||||||||||
| if API_DIR not in sys.path: | ||||||||||||||||||||||||||||||
| sys.path.insert(0, API_DIR) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
Comment on lines
+15
to
+26
|
||||||||||||||||||||||||||||||
| import sys | |
| from pathlib import Path | |
| from unittest.mock import patch, MagicMock | |
| import pytest | |
| # Ensure the API directory is on sys.path so we can import the classes | |
| API_DIR = str(Path(__file__).resolve().parent.parent / "API") | |
| if API_DIR not in sys.path: | |
| sys.path.insert(0, API_DIR) | |
| from pathlib import Path | |
| from unittest.mock import patch, MagicMock | |
| import pytest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MagicMockis imported here but never used in this test module. Please drop the unused import to keep the test code minimal and avoid confusion about intended mocking.