|
20 | 20 |
|
21 | 21 | import pytest |
22 | 22 |
|
23 | | -from ctrlgrid.document import is_document_generator |
24 | 23 | from ctrlgrid.errors import DefinitionError |
25 | 24 | from ctrlgrid.loader import loads |
26 | 25 | from ctrlgrid.media import media_findings |
@@ -145,18 +144,10 @@ def test_every_shipped_preset_is_clean_on_its_own_medium(self) -> None: |
145 | 144 | # A preset is documentation (§ 9.3), and one that warns about itself |
146 | 145 | # teaches the wrong thing. This caught a 0.1pt stroke — 0.83px at |
147 | 146 | # 600 dpi — in two presets on the day it was written. |
148 | | - from ctrlgrid.generators import get |
149 | 147 | from ctrlgrid.loader import load_preset, preset_names |
150 | 148 |
|
151 | 149 | for name in preset_names(): |
152 | 150 | document = load_preset(name) |
153 | | - if is_document_generator(get(document.generator)): |
154 | | - # The media check samples a blade's marks, and a document |
155 | | - # generator has no single pattern area to sample — it owns its |
156 | | - # pages. So `calendar-a4` is not covered here, and nothing else |
157 | | - # covers it either: § 12.1 does not reach document generators |
158 | | - # yet. Recorded rather than quietly skipped. |
159 | | - continue |
160 | 151 | assert media_findings(document, Q) == [], f"{name} warns about itself" |
161 | 152 |
|
162 | 153 |
|
@@ -196,3 +187,73 @@ def test_a_round_to_zero_stops_the_preflight(self, tmp_path: Path) -> None: |
196 | 187 | with pytest.raises(DefinitionError): |
197 | 188 | build(document, PdfWriter(path)) |
198 | 189 | assert not path.exists() |
| 190 | + |
| 191 | + |
| 192 | +class TestDocumentGenerators: |
| 193 | + """§ 12.1 for a generator that owns its pages (§ 7). |
| 194 | +
|
| 195 | + The check reads marks, and a document has no single pattern area to read |
| 196 | + them from — it has pages. Every page is walked, not one per page kind: a |
| 197 | + marked day's own colour appears only on the pages carrying that date, so a |
| 198 | + shortcut would measure January and miss a birthday in May. |
| 199 | + """ |
| 200 | + |
| 201 | + CALENDAR = ( |
| 202 | + "generator: calendar\nyear: 2026\n" |
| 203 | + "holiday_color: '#fce9e4'\n" |
| 204 | + "holidays:\n" |
| 205 | + " - {date: 2026-05-03, label: 'a birthday', color: '#cc4488'}\n" |
| 206 | + "notes: {count: 2}\n" |
| 207 | + ) |
| 208 | + |
| 209 | + def test_a_colour_that_appears_only_on_a_late_page_is_still_found(self) -> None: |
| 210 | + # The birthday is in May; its colour is on no page before it. On a |
| 211 | + # grayscale device it turns to mud, and that has to be said. |
| 212 | + notes = findings(GRAY + self.CALENDAR) |
| 213 | + assert any("#cc4488" in note for note in notes) |
| 214 | + |
| 215 | + def test_the_title_pages_full_sheet_colour_counts_as_a_colour(self) -> None: |
| 216 | + # The fill is a page property the handle paints, not a mark — but on a |
| 217 | + # grayscale screen it is exactly what goes flat. |
| 218 | + notes = findings( |
| 219 | + GRAY + self.CALENDAR + "title_page: {title: '2026', background: '#2f3a48'}\n" |
| 220 | + ) |
| 221 | + assert any("#2f3a48" in note for note in notes) |
| 222 | + |
| 223 | + def test_a_calendar_on_paper_says_nothing(self) -> None: |
| 224 | + from ctrlgrid.loader import load_preset |
| 225 | + |
| 226 | + assert media_findings(load_preset("calendar-a4"), Q) == [] |
| 227 | + |
| 228 | + def test_strict_turns_a_documents_finding_into_an_error(self) -> None: |
| 229 | + document = loads(GRAY + self.CALENDAR, None, source="test") |
| 230 | + with pytest.raises(DefinitionError): |
| 231 | + media_findings(document, Q, strict=True) |
| 232 | + |
| 233 | + |
| 234 | +class TestDocumentsInTheRun: |
| 235 | + """The check has to be *called* on the document path, not merely callable. |
| 236 | +
|
| 237 | + A calendar wants a wide sheet — the twelve mini-months of its year page are |
| 238 | + refused on a portrait e-ink screen (§ 9) — so the medium here is a landscape |
| 239 | + reMarkable 2, which is also the case a user would actually meet. |
| 240 | + """ |
| 241 | + |
| 242 | + ON_A_GRAYSCALE_SCREEN = ( |
| 243 | + "version: 1\npage:\n device: remarkable-2\n orientation: landscape\n" |
| 244 | + " margin: 0mm\n" |
| 245 | + "generator: calendar\nyear: 2026\n" |
| 246 | + "holidays:\n - {date: 2026-05-03, label: 'a birthday', color: '#cc4488'}\n" |
| 247 | + ) |
| 248 | + |
| 249 | + def test_the_preflight_reports_a_documents_findings_as_notices(self) -> None: |
| 250 | + document = loads(self.ON_A_GRAYSCALE_SCREEN, None, source="test") |
| 251 | + geometry, _contexts, _bands, _cover = preflight(document, Q) |
| 252 | + # The link blue and the birthday pink read as one tone there — a real |
| 253 | + # finding, and one nothing said before the check reached documents. |
| 254 | + assert any("#cc4488" in note for note in geometry.notices) |
| 255 | + |
| 256 | + def test_strict_stops_a_document_run_at_the_preflight(self) -> None: |
| 257 | + document = loads(self.ON_A_GRAYSCALE_SCREEN, {"strict": True}, source="test") |
| 258 | + with pytest.raises(DefinitionError): |
| 259 | + preflight(document, Q) |
0 commit comments