Skip to content

Commit 27a856c

Browse files
committed
add new diff module tests
1 parent 5ce223c commit 27a856c

File tree

1 file changed

+50
-2
lines changed

1 file changed

+50
-2
lines changed

tests/test_diff.py

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import os
2+
import tempfile
23

34
import pytest
45

5-
from fdiff.diff import u_diff
6+
from fontTools.ttLib import TTFont
7+
8+
from fdiff.diff import u_diff, _ttfont_save_xml
69
from fdiff.exceptions import AIOError
710

811
ROBOTO_BEFORE_PATH = os.path.join("tests", "testfiles", "Roboto-Regular.subset1.ttf")
@@ -44,6 +47,12 @@
4447
ROBOTO_UDIFF_EXCLUDE_HEADPOST_EXPECTED = robo_udiff_ex_headpost.read()
4548

4649

50+
def test_unified_diff_default_no_diff():
51+
res = u_diff(ROBOTO_BEFORE_PATH, ROBOTO_BEFORE_PATH)
52+
res_string = "".join(res)
53+
assert res_string == ""
54+
55+
4756
def test_unified_diff_default():
4857
res = u_diff(ROBOTO_BEFORE_PATH, ROBOTO_AFTER_PATH)
4958
res_string = "".join(res)
@@ -63,6 +72,25 @@ def test_unified_diff_default():
6372
assert line == expected_string_list[x]
6473

6574

75+
def test_unified_diff_without_mp_optimizations():
76+
res = u_diff(ROBOTO_BEFORE_PATH, ROBOTO_AFTER_PATH, use_multiprocess=False)
77+
res_string = "".join(res)
78+
res_string_list = res_string.split("\n")
79+
expected_string_list = ROBOTO_UDIFF_EXPECTED.split("\n")
80+
81+
# have to handle the tests for the top two file path lines
82+
# differently than the rest of the comparisons because
83+
# the time is defined using local platform settings
84+
# which makes tests fail on remote CI testing services vs.
85+
# my local testing platform...
86+
for x, line in enumerate(res_string_list):
87+
# treat top two lines of the diff as comparison of first 10 chars only
88+
if x in (0, 1):
89+
assert line[0:9] == expected_string_list[x][0:9]
90+
else:
91+
assert line == expected_string_list[x]
92+
93+
6694
def test_unified_diff_context_lines_1():
6795
res = u_diff(ROBOTO_BEFORE_PATH, ROBOTO_AFTER_PATH, context_lines=1)
6896
res_string = "".join(res)
@@ -210,4 +238,24 @@ def test_unified_diff_remote_404_first_file():
210238

211239
def test_unified_diff_remote_404_second_file():
212240
with pytest.raises(AIOError):
213-
u_diff(ROBOTO_BEFORE_URL, URL_404)
241+
u_diff(ROBOTO_BEFORE_URL, URL_404)
242+
243+
244+
def test_unified_diff_remote_non_url_exception():
245+
"""This raises an exception in the aiohttp get request call"""
246+
with pytest.raises(AIOError):
247+
u_diff("https:bogus", "https:bogus")
248+
249+
250+
#
251+
#
252+
# Private functions
253+
#
254+
#
255+
256+
def test_ttfont_save_xml():
257+
tt = TTFont(ROBOTO_BEFORE_PATH)
258+
with tempfile.TemporaryDirectory() as tmpdirname:
259+
path = os.path.join(tmpdirname, "test.ttx")
260+
_ttfont_save_xml(tt, path, None, None)
261+
assert os.path.isfile(path)

0 commit comments

Comments
 (0)