Skip to content

Commit a5c6685

Browse files
authored
fix: resolve GitHub Code scanning alerts #10 and #21 (#20)
## Summary - Resolve GitHub Code scanning alert #10 (unreachable code warning) - Resolve GitHub Code scanning alert #21 (mixed import style warning) - Refactor test functions to improve code structure and maintainability ## Test plan - [x] All 478 tests pass - [x] Code formatting and style checks pass (ruff format, ruff check) - [x] Type checking passes (mypy) - [x] REUSE compliance check passes - [x] Build verification successful (wheel and sdist) - [x] All pre-commit hooks pass ## Changes Made ### Alert #10: Unreachable Code Warning - **File**: `tests/test_unified_exception_handling.py` - **Issue**: CodeQL detected unreachable code at line 455, caused by static analyzer not understanding pytest.raises context manager control flow - **Solution**: Refactored `test_error_handling_with_existing_py7zz_errors` function into four separate test functions: - `test_file_not_found_error_raising` - `test_compression_error_raising` - `test_extraction_error_raising` - `test_existing_py7zz_errors_inheritance` - **Benefits**: Eliminates CodeQL warning, improves test readability and structure, follows "one test, one concern" best practice ### Alert #21: Mixed Import Style Warning - **File**: `tests/test_pypi_version_validation.py` - **Issue**: Mixed usage of `import py7zz` and `from py7zz.version import ...` causing code style inconsistency - **Solution**: Removed `from py7zz.version import ...` statement and consistently use `py7zz.version.*` format - **Benefits**: Consistent code style, clearer function origins, follows Python best practices ## Technical Details - All existing functionality preserved during refactoring - Test coverage remains unchanged - Full backward compatibility maintained - Follows project code style conventions ## Verification Complete CI simulation passed, including: - Quick checks (format, lint, type checking) - REUSE compliance verification - Build verification (wheel + sdist) - Comprehensive test suite (478 tests) - All pre-commit hooks These fixes will automatically resolve the corresponding security alerts in the next CodeQL scan.
2 parents a17269f + fffb059 commit a5c6685

File tree

3 files changed

+14
-19
lines changed

3 files changed

+14
-19
lines changed

scripts/quick-check.sh

100644100755
File mode changed.

tests/test_pypi_version_validation.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -265,25 +265,16 @@ def test_version_type_identification(self):
265265
assert parsed["version_type"] in ["stable", "alpha", "beta", "rc", "dev"]
266266

267267
# Test version type functions
268-
from py7zz.version import (
269-
get_version_type,
270-
is_alpha_version,
271-
is_beta_version,
272-
is_dev_version,
273-
is_rc_version,
274-
is_stable_version,
275-
)
276-
277-
version_type = get_version_type(version)
268+
version_type = py7zz.version.get_version_type(version)
278269
assert version_type in ["stable", "alpha", "beta", "rc", "dev"]
279270

280271
# Test that exactly one version type function returns True
281272
type_checks = [
282-
is_stable_version(version),
283-
is_alpha_version(version),
284-
is_beta_version(version),
285-
is_rc_version(version),
286-
is_dev_version(version),
273+
py7zz.version.is_stable_version(version),
274+
py7zz.version.is_alpha_version(version),
275+
py7zz.version.is_beta_version(version),
276+
py7zz.version.is_rc_version(version),
277+
py7zz.version.is_dev_version(version),
287278
]
288279
assert sum(type_checks) == 1, "Exactly one version type should be True"
289280

tests/test_unified_exception_handling.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -446,19 +446,23 @@ def test_complex_error_context_tracking(self):
446446
assert info["context"]["progress"] == "3/5"
447447
assert len(info["suggestions"]) == 2
448448

449-
def test_error_handling_with_existing_py7zz_errors(self):
450-
"""Test error handling integration with existing py7zz error types."""
451-
# Test that existing error types still work
449+
def test_file_not_found_error_raising(self):
450+
"""Test that FileNotFoundError can be raised and caught properly."""
452451
with pytest.raises(py7zz.FileNotFoundError):
453452
raise py7zz.FileNotFoundError("test.txt")
454453

454+
def test_compression_error_raising(self):
455+
"""Test that CompressionError can be raised and caught properly."""
455456
with pytest.raises(py7zz.CompressionError):
456457
raise py7zz.CompressionError("Compression failed")
457458

459+
def test_extraction_error_raising(self):
460+
"""Test that ExtractionError can be raised and caught properly."""
458461
with pytest.raises(py7zz.ExtractionError):
459462
raise py7zz.ExtractionError("Extraction failed")
460463

461-
# Test that they're still Py7zzError instances
464+
def test_existing_py7zz_errors_inheritance(self):
465+
"""Test that existing error types are still Py7zzError instances."""
462466
error = py7zz.CompressionError("Test")
463467
assert isinstance(error, py7zz.Py7zzError)
464468

0 commit comments

Comments
 (0)