Skip to content

Commit f3a0987

Browse files
committed
Fix remaining 4 Codacy findings on PR #97
- pyflakes F821 token_leak_detector:196 — re-added the typing.Optional import that autoflake stripped before my _har_body_text refactor introduced it - pyflakes F811 test_download_verify:271 — removed duplicate `from pypdf import PdfWriter` (already imported at line 256) - pyflakes F841 test_sri_verify:86 — replaced the unused `_tag = ...` binding with a comment explaining the alg='not' edge case the test doesn't directly assert against - semgrep dangerous-subprocess-use test_test_auto_repair:51 — added `# nosemgrep` to the second MagicMock(return_value=CompletedProcess(...)) fixture (the first one already had it)
1 parent b7f5b18 commit f3a0987

4 files changed

Lines changed: 8 additions & 9 deletions

File tree

je_web_runner/utils/token_leak_detector/detector.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import json
1515
import re
1616
from dataclasses import asdict, dataclass
17-
from typing import Any, Dict, Iterable, List, Pattern, Sequence, Union
17+
from typing import Any, Dict, Iterable, List, Optional, Pattern, Sequence, Union
1818

1919
from je_web_runner.utils.exception.exceptions import WebRunnerException
2020

test/unit_test/test_download_verify.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,8 @@ def _write_minimal_pdf(path: Path, text: str) -> None:
267267
c.save()
268268
path.write_bytes(buf.getvalue())
269269
except ImportError:
270-
# Fallback: stitch together a near-minimal text page via pypdf.
271-
from pypdf import PdfWriter
270+
# Fallback: stitch together a near-minimal text page via pypdf
271+
# (PdfWriter already imported above).
272272
writer = PdfWriter()
273273
writer.add_blank_page(width=200, height=200)
274274
with open(path, "wb") as fp:

test/unit_test/test_sri_verify.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,10 @@ def test_weak_alg(self):
8383
self.assertEqual(verify_tag(tag).verdict, Verdict.WEAK_ALG)
8484

8585
def test_unknown_format(self):
86-
_tag = ResourceTag(
87-
tag="script", url="https://cdn/x.js",
88-
integrity="not-an-integrity",
89-
)
90-
# 'not-an-integrity' parses as alg='not', so it falls into WEAK_ALG
91-
# (not in strong set). Use a value with no dash for UNKNOWN_FORMAT:
86+
# 'not-an-integrity' parses as alg='not', so a ResourceTag built with
87+
# that integrity string would fall into WEAK_ALG (not in strong set).
88+
# We only need the truly unparseable case below, so we don't bind
89+
# a Python variable for the first example.
9290
tag2 = ResourceTag(
9391
tag="script", url="https://cdn/x.js", integrity="garbage",
9492
)

test/unit_test/test_test_auto_repair.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def test_returns_stdout_on_success(self):
4848
self.assertIn("diff text", text)
4949

5050
def test_returns_empty_on_failure(self):
51+
# nosemgrep: dangerous-subprocess-use-audit — fake CompletedProcess for MagicMock; no subprocess is launched.
5152
fake = MagicMock(return_value=subprocess.CompletedProcess(
5253
args=[], returncode=128, stdout="", stderr="not a git repo",
5354
))

0 commit comments

Comments
 (0)