Problem
`exclusion_detector.py` sits at ~59% coverage — the lowest of any file in `bankstatements_core`. There are no tests for this class at all. It actively drags overall coverage down.
File
`packages/parser-core/src/bankstatements_core/templates/detectors/exclusion_detector.py`
Uncovered paths (from coverage report)
| Lines |
Description |
| Line 27 |
`name` property |
| Lines 57–60 |
`crop()` exception fallback → `first_page.extract_text()` |
| Lines 64–66 |
`if not text` branch (no text in header area) |
| Lines 81–110 |
Template loop: no-exclusion-rules skip, keyword matching, excluded/allowed branches |
Why it is hard to test
`ExclusionDetector.detect()` takes a `pdfplumber.page.Page` as its second argument. `Page` is tightly coupled to an open PDF file handle — not easily instantiated in isolation.
Approach
Use `unittest.mock.MagicMock` to simulate `pdfplumber.page.Page`:
```python
from unittest.mock import MagicMock
def make_page(text: str, crop_raises: bool = False) -> MagicMock:
page = MagicMock()
page.width = 800
cropped = MagicMock()
if crop_raises:
page.crop.side_effect = AttributeError("crop failed")
else:
cropped.extract_text.return_value = text
page.crop.return_value = cropped
page.extract_text.return_value = text # fallback
return page
```
Tests to add
Create `packages/parser-core/tests/detectors/test_exclusion_detector.py` covering:
Expected outcome
Coverage on `exclusion_detector.py` rises from 59% to ≥ 90%. Overall project coverage stays at or above 94%.
Problem
`exclusion_detector.py` sits at ~59% coverage — the lowest of any file in `bankstatements_core`. There are no tests for this class at all. It actively drags overall coverage down.
File
`packages/parser-core/src/bankstatements_core/templates/detectors/exclusion_detector.py`
Uncovered paths (from coverage report)
Why it is hard to test
`ExclusionDetector.detect()` takes a `pdfplumber.page.Page` as its second argument. `Page` is tightly coupled to an open PDF file handle — not easily instantiated in isolation.
Approach
Use `unittest.mock.MagicMock` to simulate `pdfplumber.page.Page`:
```python
from unittest.mock import MagicMock
def make_page(text: str, crop_raises: bool = False) -> MagicMock:
page = MagicMock()
page.width = 800
cropped = MagicMock()
if crop_raises:
page.crop.side_effect = AttributeError("crop failed")
else:
cropped.extract_text.return_value = text
page.crop.return_value = cropped
page.extract_text.return_value = text # fallback
return page
```
Tests to add
Create `packages/parser-core/tests/detectors/test_exclusion_detector.py` covering:
Expected outcome
Coverage on `exclusion_detector.py` rises from 59% to ≥ 90%. Overall project coverage stays at or above 94%.