|
1 | 1 | from pathlib import Path |
2 | 2 |
|
3 | | -import calendar_extract as mod |
4 | 3 | import numpy as np |
5 | 4 |
|
| 5 | +import extract_dates as mod |
| 6 | + |
6 | 7 |
|
7 | 8 | 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 | + ] |
10 | 18 |
|
11 | 19 |
|
12 | 20 | class FakePage: |
13 | | - def get_pixmap(self): |
| 21 | + def get_pixmap(self) -> "PM": # noqa: F821 |
14 | 22 | class PM: |
15 | | - def tobytes(self, fmt) -> bytes: |
| 23 | + def tobytes(self, fmt: str) -> bytes: # noqa: ARG002 |
16 | 24 | return b"\x89PNG\r\n\x1a\n" |
17 | 25 |
|
18 | 26 | return PM() |
19 | 27 |
|
20 | | - def get_textpage_ocr(self, tessdata=None): |
| 28 | + def get_textpage_ocr(self, tessdata=None) -> FakeTextPage: # noqa: ARG002, ANN001 |
21 | 29 | return FakeTextPage() |
22 | 30 |
|
23 | 31 |
|
24 | 32 | class FakeDoc: |
25 | | - def __getitem__(self, idx): |
| 33 | + def __getitem__(self, idx: int) -> FakePage: |
26 | 34 | return FakePage() |
27 | 35 |
|
28 | 36 |
|
29 | | -def test_extract_png_calendars(monkeypatch) -> None: |
| 37 | +def test_extract_png_calendars(monkeypatch) -> None: # noqa: ANN001 |
30 | 38 | monkeypatch.setattr(mod.pymupdf, "open", lambda _: FakeDoc()) |
31 | 39 | monkeypatch.setattr(mod.cv2, "imdecode", lambda *_: np.zeros((200, 300, 3))) |
32 | 40 |
|
33 | 41 | calendars = mod.extract_png_calendars(Path("fake.png")) |
34 | 42 |
|
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)] |
0 commit comments