map-machine/test/test_label.py
Sergey Vartanov c5bb1529f5 Speed up tests.
Load scheme and shape extractor just once for a test group.
2021-05-21 04:22:12 +03:00

46 lines
1.1 KiB
Python

"""
Test label generation for nodes.
Author: Sergey Vartanov (me@enzet.ru).
"""
from typing import List
from roentgen.scheme import Scheme
from roentgen.text import Label
SCHEME: Scheme = Scheme("scheme/default.yml")
def construct_labels(tags) -> List[Label]:
"""
Construct labels from OSM node tags.
"""
return SCHEME.construct_text(tags, "all")
def test_1_label() -> None:
"""
Test tags that should be converted into single label.
"""
labels = construct_labels({"name": "Name"})
assert len(labels) == 1
assert labels[0].text == "Name"
def test_1_label_unknown_tags() -> None:
"""
Test tags with some unknown tags that should be converted into single label.
"""
labels = construct_labels({"name": "Name", "aaa": "bbb"})
assert len(labels) == 1
assert labels[0].text == "Name"
def test_2_labels() -> None:
"""
Test tags that should be converted into two labels.
"""
labels = construct_labels({"name": "Name", "ref": "5"})
assert len(labels) == 2
assert labels[0].text == "Name"
assert labels[1].text == "5"