masque/masque/test/test_label.py

48 lines
1.5 KiB
Python

import pytest
import numpy
from numpy.testing import assert_equal, assert_allclose
from numpy import pi
from ..label import Label
from ..repetition import Grid
def test_label_init():
l = Label("test", offset=(10, 20))
assert l.string == "test"
assert_equal(l.offset, [10, 20])
def test_label_transform():
l = Label("test", offset=(10, 0))
# Rotate 90 deg CCW around (0,0)
l.rotate_around((0, 0), pi/2)
assert_allclose(l.offset, [0, 10], atol=1e-10)
# Translate
l.translate((5, 5))
assert_allclose(l.offset, [5, 15], atol=1e-10)
def test_label_repetition():
rep = Grid(a_vector=(10, 0), a_count=3)
l = Label("rep", offset=(0, 0), repetition=rep)
assert l.repetition is rep
assert_equal(l.get_bounds_single(), [[0, 0], [0, 0]])
# Note: Bounded.get_bounds_nonempty() for labels with repetition doesn't
# seem to automatically include repetition bounds in label.py itself,
# it's handled during pattern bounding.
def test_label_copy():
l1 = Label("test", offset=(1, 2), annotations={"a": [1]})
l2 = copy.deepcopy(l1)
print(f"l1: string={l1.string}, offset={l1.offset}, repetition={l1.repetition}, annotations={l1.annotations}")
print(f"l2: string={l2.string}, offset={l2.offset}, repetition={l2.repetition}, annotations={l2.annotations}")
from ..utils import annotations_eq
print(f"annotations_eq: {annotations_eq(l1.annotations, l2.annotations)}")
assert l1 == l2
assert l1 is not l2
l2.offset[0] = 100
assert l1.offset[0] == 1
import copy