Skip to content
This repository was archived by the owner on Jan 28, 2026. It is now read-only.

Commit 1cde1d9

Browse files
Fix test suite
1 parent dd1495d commit 1cde1d9

9 files changed

Lines changed: 259 additions & 28 deletions

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ split-on-trailing-comma = false
6565
classmethod-decorators = ["classmethod"]
6666

6767
[tool.ruff.lint.per-file-ignores]
68-
"tests/*" = ["S101"]
68+
"tests/*" = ["PLR2004", "S101"]
6969

7070
[tool.ruff.lint.pydocstyle]
7171
convention = "google"

tests/test_extractors.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,44 @@
11
from pathlib import Path
22

3-
import calendar_extract as mod
43
import numpy as np
54

5+
import extract_dates as mod
6+
67

78
class FakeTextPage:
8-
def extractWORDS(self, delimiters=None):
9-
return [(0, 0, 10, 10, "January"), (11, 0, 20, 10, "2024")]
9+
def extractWORDS(self, delimiters: str | None = None) -> list[tuple]: # noqa: N802, ARG002
10+
return [
11+
(0, 0, 10, 10, "January"),
12+
(11, 0, 20, 10, "2024"),
13+
(30, 0, 40, 10, "February"),
14+
(41, 0, 50, 10, "2024"),
15+
(60, 0, 70, 10, "March"),
16+
(71, 0, 80, 10, "2024"),
17+
]
1018

1119

1220
class FakePage:
13-
def get_pixmap(self):
21+
def get_pixmap(self) -> "PM": # noqa: F821
1422
class PM:
15-
def tobytes(self, fmt) -> bytes:
23+
def tobytes(self, fmt: str) -> bytes: # noqa: ARG002
1624
return b"\x89PNG\r\n\x1a\n"
1725

1826
return PM()
1927

20-
def get_textpage_ocr(self, tessdata=None):
28+
def get_textpage_ocr(self, tessdata=None) -> FakeTextPage: # noqa: ARG002, ANN001
2129
return FakeTextPage()
2230

2331

2432
class FakeDoc:
25-
def __getitem__(self, idx):
33+
def __getitem__(self, idx: int) -> FakePage:
2634
return FakePage()
2735

2836

29-
def test_extract_png_calendars(monkeypatch) -> None:
37+
def test_extract_png_calendars(monkeypatch) -> None: # noqa: ANN001
3038
monkeypatch.setattr(mod.pymupdf, "open", lambda _: FakeDoc())
3139
monkeypatch.setattr(mod.cv2, "imdecode", lambda *_: np.zeros((200, 300, 3)))
3240

3341
calendars = mod.extract_png_calendars(Path("fake.png"))
3442

35-
assert len(calendars) == 1
36-
cal = calendars[0]
37-
assert cal.month == 1
38-
assert cal.year == 2024
43+
assert len(calendars) == 3
44+
assert [(c.month, c.year) for c in calendars] == [(1, 2024), (2, 2024), (3, 2024)]

tests/test_image_helpers.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import cv2
22
import numpy as np
3-
from calendar_extract import keep_only_colours, remove_colours
43

4+
from extract_dates import keep_only_colours, remove_colours
55

6-
def test_remove_colours_masks_pixels(monkeypatch) -> None:
6+
7+
def test_remove_colours_masks_pixels(monkeypatch) -> None: # noqa: ANN001
78
img = np.zeros((2, 2, 3), dtype=np.uint8)
89
img[:] = [10, 10, 10]
910

10-
def fake_in_range(*args, **kwargs):
11+
def fake_in_range(*args, **kwargs) -> np.array: # noqa: ANN002, ANN003
1112
return np.array([[255, 0], [0, 0]], dtype=np.uint8)
1213

1314
monkeypatch.setattr(cv2, "inRange", fake_in_range)
@@ -17,10 +18,10 @@ def fake_in_range(*args, **kwargs):
1718
assert (result[0, 0] == [255, 255, 255]).all()
1819

1920

20-
def test_keep_only_colours(monkeypatch) -> None:
21+
def test_keep_only_colours(monkeypatch) -> None: # noqa: ANN001
2122
img = np.ones((2, 2, 3), dtype=np.uint8) * 50
2223

23-
def fake_in_range(*args, **kwargs):
24+
def fake_in_range(*args, **kwargs) -> np.array: # noqa: ANN002, ANN003
2425
return np.array([[255, 0], [0, 0]], dtype=np.uint8)
2526

2627
monkeypatch.setattr(cv2, "inRange", fake_in_range)

tests/test_main.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import calendar_extract as mod
1+
from pathlib import Path
22

3+
import extract_dates as mod
34

4-
def test_main_writes_output(monkeypatch, tmp_path) -> None:
5-
monkeypatch.setattr(mod.Path, "glob", lambda self, _: [])
5+
6+
def test_main_writes_output(monkeypatch, tmp_path: Path) -> None: # noqa: ANN001
7+
monkeypatch.setattr(mod.Path, "glob", lambda self, pattern: []) # noqa: ARG005
68
monkeypatch.setattr(mod, "extract_png_calendars", lambda *a, **k: [])
79
monkeypatch.setattr(mod, "extract_pdf_calendars", lambda *a, **k: [])
810

tests/test_mappings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from calendar_extract import adjust_mappings
1+
from extract_dates import adjust_mappings
22

33

44
def test_adjust_mappings_single_row() -> None:

tests/test_models.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from datetime import date
22

33
import numpy as np
4-
from calendar_extract import Calendar, Cell
4+
5+
from extract_dates import Calendar, Cell
56

67

78
def test_calendar_equality_and_hash() -> None:

tests/test_parse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from calendar_extract import parse_month
1+
from extract_dates import parse_month
22

33

44
def test_parse_month_valid() -> None:

tests/test_process_calendar.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import numpy as np
2-
from calendar_extract import PNG_COLOURS, process_calendar_squares
32

3+
from extract_dates import PNG_COLOURS, process_calendar_squares
44

5-
def test_process_calendar_single_day(monkeypatch) -> None:
5+
6+
def test_process_calendar_single_day(monkeypatch) -> None: # noqa: ANN001
67
img = np.zeros((100, 700, 3), dtype=np.uint8)
78

8-
def fake_analyze_square(*args, **kwargs):
9+
def fake_analyze_square(*args, **kwargs) -> tuple[int, int, int]: # noqa: ANN002, ANN003
910
return (0, 0, 255) # red (BGR)
1011

11-
monkeypatch.setattr("calendar_extract.analyze_square", fake_analyze_square)
12+
monkeypatch.setattr("extract_dates.analyze_square", fake_analyze_square)
1213

1314
cells = process_calendar_squares(img=img, year=2024, month=1, colours=PNG_COLOURS)
1415

0 commit comments

Comments
 (0)