mirror of
https://github.com/enzet/map-machine.git
synced 2025-05-13 00:56:54 +02:00
Add text test.
This commit is contained in:
parent
e113ef09e4
commit
ffcabd0ab8
2 changed files with 50 additions and 36 deletions
43
test/test_label.py
Normal file
43
test/test_label.py
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
"""
|
||||||
|
Author: Sergey Vartanov (me@enzet.ru).
|
||||||
|
"""
|
||||||
|
from typing import List
|
||||||
|
|
||||||
|
from roentgen.scheme import Scheme
|
||||||
|
from roentgen.text import Label
|
||||||
|
|
||||||
|
|
||||||
|
def construct_labels(tags) -> List[Label]:
|
||||||
|
"""
|
||||||
|
Construct labels from OSM node tags.
|
||||||
|
"""
|
||||||
|
scheme = Scheme("scheme/default.yml")
|
||||||
|
return scheme.construct_text(tags, True)
|
||||||
|
|
||||||
|
|
||||||
|
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"
|
|
@ -1,43 +1,14 @@
|
||||||
"""
|
"""
|
||||||
|
Test text generation.
|
||||||
|
|
||||||
Author: Sergey Vartanov (me@enzet.ru).
|
Author: Sergey Vartanov (me@enzet.ru).
|
||||||
"""
|
"""
|
||||||
from typing import List
|
from roentgen.text import format_voltage
|
||||||
|
|
||||||
from roentgen.scheme import Scheme
|
|
||||||
from roentgen.text import Label
|
|
||||||
|
|
||||||
|
|
||||||
def construct_labels(tags) -> List[Label]:
|
def test_voltage() -> None:
|
||||||
"""
|
"""
|
||||||
Construct labels from OSM node tags.
|
Test voltage tag value processing.
|
||||||
"""
|
"""
|
||||||
scheme = Scheme("scheme/default.yml")
|
assert format_voltage("42") == "42 V"
|
||||||
return scheme.construct_text(tags, True)
|
assert format_voltage("42000") == "42 kV"
|
||||||
|
|
||||||
|
|
||||||
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"
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue