Skip to content

Commit

Permalink
Test: th2 round trip
Browse files Browse the repository at this point in the history
  • Loading branch information
speleo3 committed Dec 16, 2023
1 parent c2e1c7c commit ec6ee6c
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
49 changes: 49 additions & 0 deletions tests/data/label-align.th2
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
encoding utf-8
##XTHERION## xth_me_area_adjust 0 0 290.000000 260.000000
##XTHERION## xth_me_area_zoom_to 100



scrap scrap1 -projection plan -scale [0 0 96 0 0 0 200 0 inch]

line u:unknown -clip off
228.018 201.9699
228.018 60.5
endline

line u:unknown -clip off
0.5 96.7525
273.0948 96.7525
endline

line u:unknown -clip off
0.5 151.6229
273.0948 151.6229
endline

line u:unknown -clip off
107.2873 201.9699
107.2873 60.5
endline

point 107.288 151.623 label -align bl -text bottom-left

point 107.288 96.753 label -align l -text left

point 107.288 96.753 label -align t -text top

point 228.018 96.753 label -text center

point 107.288 96.753 label -align b -text bottom

point 107.288 96.753 label -align r -text right

point 107.288 151.623 label -align br -text bottom-right

point 107.288 151.623 label -align tr -text top-right

point 107.288 151.623 label -align tl -text top-left

endscrap


45 changes: 45 additions & 0 deletions tests/test_th2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import sys
import pytest
import subprocess
import importlib
from pathlib import Path
from typing import AnyStr

TESTS_DATA = Path(__file__).resolve().parent / "data"


def _find_script(name: str) -> str:
spec = importlib.util.find_spec(name)
assert spec is not None
assert spec.origin is not None
return spec.origin


def _non_empty_lines(buf: AnyStr) -> list[AnyStr]:
return [line for line in buf.splitlines() if line]


def _assert_non_empty_lines_equal(left: AnyStr, right: AnyStr):
assert _non_empty_lines(left) == _non_empty_lines(right)


script_th2_input = _find_script("th2_input")
script_th2_output = _find_script("th2_output")


@pytest.mark.parametrize("stem", [
("label-align"),
])
def test_th2_round_trip(stem):
path_input = TESTS_DATA / f"{stem}.th2"
svgcontent = subprocess.check_output([
sys.executable,
script_th2_input,
str(path_input),
])
th2content, stderr = subprocess.Popen(
[sys.executable, script_th2_output],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
).communicate(svgcontent)
_assert_non_empty_lines_equal(path_input.read_bytes(), th2content)

0 comments on commit ec6ee6c

Please sign in to comment.