Skip to content

test(preprocessing,data): fix CodeQL alerts in tests#375

Merged
bartzbeielstein merged 1 commit into
developfrom
test/fix-codeql-alerts
Jun 13, 2026
Merged

test(preprocessing,data): fix CodeQL alerts in tests#375
bartzbeielstein merged 1 commit into
developfrom
test/fix-codeql-alerts

Conversation

@bartzbeielstein

Copy link
Copy Markdown
Collaborator

Resolves the three open code-scanning alerts on the default branch.

Alert Rule File Fix
#211, #212 py/uninitialized-local-variable (error) tests/preprocessing/test_target_corruption.py Dropped the try/except pytest.fail() wrapper around detect_target_corruption. CodeQL doesn't model pytest.fail as NoReturn, so it flagged mask as possibly-unbound at the trailing assert not mask.any(). A raise now fails the test with a full traceback — which is the "must not raise" guarantee these cases assert.
#213 py/import-and-import-from (note) tests/test_entsoe_loader.py Dropped the from ... 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 skipped
  • uv run ruff check src/ tests/ — clean

🤖 Generated with Claude Code

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>
@bartzbeielstein bartzbeielstein merged commit 05ad147 into develop Jun 13, 2026
9 checks passed
@bartzbeielstein bartzbeielstein deleted the test/fix-codeql-alerts branch June 13, 2026 06:25
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.

1 participant