test(preprocessing,data): fix CodeQL alerts in tests#375
Merged
Conversation
Resolve the three open code-scanning alerts on the default branch: - py/uninitialized-local-variable (#211, #212) in test_target_corruption.py: `mask` was assigned inside a `try` whose `except` called `pytest.fail()`. CodeQL does not model `pytest.fail` as NoReturn, so it saw `mask` as possibly-unbound at the trailing `assert not mask.any()`. Drop the try/except wrapper and call detect_target_corruption directly — a raise already fails the test with a full traceback, which is the "must not raise" guarantee these cases assert. - py/import-and-import-from (#213) in test_entsoe_loader.py: the module was imported both as `import ... as entsoe_loader` and via `from ... import (...)`. Drop the from-import and reference the loaders through the module alias. The alias must stay regardless — monkeypatch.setattr(entsoe_loader, "get_data_home", ...) patches the name in the loader's own namespace, which is where it is looked up. Test-only change; no shipped behavior affected. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Resolves the three open code-scanning alerts on the default branch.
py/uninitialized-local-variable(error)tests/preprocessing/test_target_corruption.pytry/except pytest.fail()wrapper arounddetect_target_corruption. CodeQL doesn't modelpytest.failasNoReturn, so it flaggedmaskas possibly-unbound at the trailingassert not mask.any(). A raise now fails the test with a full traceback — which is the "must not raise" guarantee these cases assert.py/import-and-import-from(note)tests/test_entsoe_loader.pyfrom ... import (...)and reference the loaders via the module alias. The alias must stay —monkeypatch.setattr(entsoe_loader, "get_data_home", ...)patches the name in the loader's own namespace, where it's looked up.Test-only change; no shipped behavior affected.
Verification
uv run pytest tests/— 2599 passed, 1 skippeduv run ruff check src/ tests/— clean🤖 Generated with Claude Code