init commit with repo structure and basic files
This commit is contained in:
parent
41ad34550b
commit
3865dcc402
13 changed files with 393 additions and 0 deletions
1
tests/conftest.py
Normal file
1
tests/conftest.py
Normal file
|
|
@ -0,0 +1 @@
|
|||
from fixtures import * # noqa
|
||||
25
tests/fixtures.py
Normal file
25
tests/fixtures.py
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import os
|
||||
from typing import Callable
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def current_dir(request) -> str:
|
||||
return os.path.dirname(request.module.__file__)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def get_test_image(current_dir) -> Callable[[str], bytes]:
|
||||
def f(name):
|
||||
return open(os.path.join(current_dir, "test_images", name), "rb").read()
|
||||
|
||||
return f
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def save_test_image(current_dir) -> Callable[[str, bytes], None]:
|
||||
def f(name: str, data: bytes):
|
||||
open(os.path.join(current_dir, "test_images", name), "wb").write(data)
|
||||
|
||||
return f
|
||||
29
tests/labeler/domain/test_objects.py
Normal file
29
tests/labeler/domain/test_objects.py
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
import math
|
||||
|
||||
from labeler.domain.objects import Dimension, MediaDefinition
|
||||
|
||||
|
||||
def test_dimension():
|
||||
dimension = Dimension(mm=25.4)
|
||||
|
||||
assert dimension.mm == 25.4
|
||||
assert dimension.inch == 1.0
|
||||
|
||||
assert dimension.in_pixels(dpi=300) == 300
|
||||
|
||||
assert dimension + Dimension(mm=10) == Dimension(mm=35.4)
|
||||
assert dimension * 2 == Dimension(mm=50.8)
|
||||
|
||||
assert dimension / 2 == Dimension(mm=12.7)
|
||||
|
||||
|
||||
def test_infinite_media():
|
||||
media = MediaDefinition(
|
||||
width=Dimension(mm=12),
|
||||
length=Dimension(mm=math.inf),
|
||||
minimal_margin_vertical=Dimension(mm=1),
|
||||
minimal_margin_horizontal=Dimension(mm=2),
|
||||
dpi=300,
|
||||
)
|
||||
|
||||
assert media.printable_length == Dimension(mm=math.inf)
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 1.5 KiB |
BIN
tests/labeler/infra/test_images/multiline_label_test.png
Normal file
BIN
tests/labeler/infra/test_images/multiline_label_test.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.7 KiB |
BIN
tests/labeler/infra/test_images/no_fixed_width.png
Normal file
BIN
tests/labeler/infra/test_images/no_fixed_width.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.5 KiB |
BIN
tests/labeler/infra/test_images/simple_label_test.png
Normal file
BIN
tests/labeler/infra/test_images/simple_label_test.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.6 KiB |
50
tests/labeler/infra/test_renderer.py
Normal file
50
tests/labeler/infra/test_renderer.py
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
from labeler.domain.objects import LabelDefinition, Dimension
|
||||
from labeler.infra.renderer import PILRenderer
|
||||
|
||||
|
||||
def test_simple_label(get_test_image):
|
||||
renderer = PILRenderer()
|
||||
expected_label = get_test_image("simple_label_test.png")
|
||||
|
||||
definition = LabelDefinition(
|
||||
text="dolphin", length=Dimension(mm=40), width=Dimension(mm=10), dpi=600
|
||||
)
|
||||
|
||||
label = renderer.render_label(definition)
|
||||
|
||||
assert label.bytes == expected_label
|
||||
|
||||
|
||||
def test_multiline_label(get_test_image):
|
||||
label_text = "dolphin\nis\nawesome"
|
||||
expected_label = get_test_image("multiline_label_test.png")
|
||||
|
||||
renderer = PILRenderer()
|
||||
definition = LabelDefinition(
|
||||
text=label_text, length=Dimension(mm=40), width=Dimension(mm=10), dpi=600
|
||||
)
|
||||
|
||||
label = renderer.render_label(definition)
|
||||
assert label.bytes == expected_label
|
||||
|
||||
|
||||
def test_simple_label_no_fixed_width(get_test_image, save_test_image):
|
||||
renderer = PILRenderer()
|
||||
expected_label = get_test_image("no_fixed_width.png")
|
||||
|
||||
definition = LabelDefinition(text="dolphin", width=Dimension(mm=10), dpi=600)
|
||||
|
||||
label = renderer.render_label(definition)
|
||||
assert label.bytes == expected_label
|
||||
|
||||
|
||||
def test_multiline_label_no_fixed_width(get_test_image, save_test_image):
|
||||
renderer = PILRenderer()
|
||||
expected_label = get_test_image("multiline_no_fixed_width.png")
|
||||
|
||||
definition = LabelDefinition(
|
||||
text="dolphin\nis\nawesome", width=Dimension(mm=10), dpi=600
|
||||
)
|
||||
|
||||
label = renderer.render_label(definition)
|
||||
assert label.bytes == expected_label
|
||||
Loading…
Add table
Add a link
Reference in a new issue