|
1 | 1 | import json |
2 | 2 | from dataclasses import astuple |
3 | 3 | from io import BytesIO |
4 | | -from typing import Generator |
| 4 | +from pathlib import Path |
5 | 5 | from types import MappingProxyType |
| 6 | +from typing import Generator |
6 | 7 | from uuid import UUID |
7 | 8 |
|
8 | | -import fitz |
9 | 9 | import pytest |
10 | 10 | from celery.contrib.testing.tasks import ping # noqa: F401 |
11 | 11 | from flask import Flask |
12 | 12 | from flask.testing import FlaskClient |
13 | 13 | from flask_babel import Babel |
14 | 14 | from numpy.typing import NDArray |
15 | | -from PIL import Image, ImageOps |
16 | 15 | from testcontainers.postgres import PostgresContainer |
17 | 16 | from testcontainers.redis import RedisContainer |
18 | 17 |
|
|
27 | 26 | # are registered correctly. |
28 | 27 | from sketch_map_tool.routes import app as smt_flask_app |
29 | 28 | from sketch_map_tool.upload_processing import clip |
| 29 | +from sketch_map_tool.upload_processing.qr_code_reader import read_qr_code |
30 | 30 | from tests import FIXTURE_DIR |
31 | 31 | from tests import vcr_app as vcr |
32 | | -from sketch_map_tool.upload_processing.qr_code_reader import read_qr_code |
33 | 32 |
|
34 | 33 |
|
35 | 34 | # |
@@ -261,31 +260,19 @@ def map_frame(uuid_create, flask_app, tmp_path_factory) -> BytesIO: |
261 | 260 |
|
262 | 261 |
|
263 | 262 | @pytest.fixture(scope="session") |
264 | | -def sketch_map_marked(uuid_create, sketch_map, tmp_path_factory) -> bytes: |
265 | | - """Sketch map with markings as PNG.""" |
266 | | - # TODO: increase resolution of PNG |
267 | | - path = tmp_path_factory.getbasetemp() / uuid_create / "sketch-map-marked.png" |
268 | | - |
269 | | - # Convert PDF to PNG |
270 | | - pdf = fitz.open(stream=sketch_map) # type: ignore |
271 | | - pag = pdf.load_page(0) |
272 | | - mat = fitz.Matrix(2, 2) |
273 | | - pag.get_pixmap(matrix=mat).save(path, output="png") |
274 | | - |
275 | | - # Draw shapes on PNG (Sketch Map) |
276 | | - img1 = Image.open(path) # Sketch Map (primary image) |
277 | | - img2 = Image.open( |
278 | | - FIXTURE_DIR / "upload-processing" / "markings-transparent.png" |
279 | | - ) # Markings (overlay image) |
280 | | - img2 = ImageOps.cover(img2, img1.size) # type: ignore |
281 | | - img1.paste(img2, (0, 0), mask=img2) # Overlay images starting at 0, 0 |
282 | | - |
283 | | - # Displaying the image |
284 | | - # img1.show() |
285 | | - |
286 | | - # TODO: what should be the return type of the fixture? |
287 | | - img1.save(path) |
288 | | - with open(path, "rb") as file: |
| 263 | +def sketch_map_marked_path(layer) -> Path: |
| 264 | + """Photo of the sketch map with markings.""" |
| 265 | + return FIXTURE_DIR / f"sketch-map-marked-{layer}.jpg" |
| 266 | + |
| 267 | + |
| 268 | +@pytest.fixture(scope="session") |
| 269 | +def sketch_map_marked(sketch_map_marked_path) -> bytes: |
| 270 | + """Photo of the sketch map with markings.""" |
| 271 | + # NOTE: If you want to change the markings of this fixture: |
| 272 | + # (1) Run tests. (2) Print PDF written to tmp dir by uuid_create fixture. |
| 273 | + # (3) Put markings on printout. (4) Make a photo. |
| 274 | + # (5) put photo file in fixture dir. |
| 275 | + with open(sketch_map_marked_path, "rb") as file: |
289 | 276 | return file.read() |
290 | 277 |
|
291 | 278 |
|
@@ -352,9 +339,13 @@ def read_qr_code_(image): |
352 | 339 |
|
353 | 340 |
|
354 | 341 | @pytest.fixture(scope="session") |
355 | | -def vector(uuid_digitize, tmp_path_factory) -> bytes: |
356 | | - path = tmp_path_factory.getbasetemp() / uuid_digitize / "vector.geojson" |
357 | | - with open(path, "rb") as file: |
| 342 | +def vector_path(uuid_digitize, tmp_path_factory) -> Path: |
| 343 | + return tmp_path_factory.getbasetemp() / uuid_digitize / "vector.geojson" |
| 344 | + |
| 345 | + |
| 346 | +@pytest.fixture(scope="session") |
| 347 | +def vector(vector_path) -> bytes: |
| 348 | + with open(vector_path, "rb") as file: |
358 | 349 | return file.read() |
359 | 350 |
|
360 | 351 |
|
|
0 commit comments