| 1 | import pytest |
| 2 | import tempfile |
| 3 | import subprocess |
| 4 | import os |
| 5 | from fontTools.ttLib import TTFont |
| 6 | from gftools.builder.dependencies import GFTOOLS_DEPENDENCIES_KEY |
| 7 | |
| 8 | |
| 9 | TEST_FONT = os.path.join("data", "test", "Lora-Regular.ttf") |
| 10 | |
| 11 | |
| 12 | @pytest.mark.parametrize("fp", [TEST_FONT]) |
| 13 | def test_write_and_read_dependencies(fp): |
| 14 | with tempfile.TemporaryDirectory() as tmp: |
| 15 | font_out = os.path.join(tmp, "font.ttf") |
| 16 | requirements_out = os.path.join(tmp, "requirements.txt") |
| 17 | subprocess.run( |
| 18 | ["gftools", "font-dependencies", "write", TEST_FONT, "-o", font_out] |
| 19 | ) |
| 20 | ttfont = TTFont(font_out) |
| 21 | assert "Debg" in ttfont |
| 22 | assert GFTOOLS_DEPENDENCIES_KEY in ttfont["Debg"].data |
| 23 | |
| 24 | subprocess.run( |
| 25 | ["gftools", "font-dependencies", "read", font_out, "-o", requirements_out] |
| 26 | ) |
| 27 | with open(requirements_out, encoding="utf-8") as doc: |
| 28 | doc_text = doc.read() |
| 29 | assert "fonttools" in doc_text |