1
1
import os
2
+ import tempfile
2
3
3
4
import pytest
4
5
5
- from fdiff .diff import u_diff
6
+ from fontTools .ttLib import TTFont
7
+
8
+ from fdiff .diff import u_diff , _ttfont_save_xml
6
9
from fdiff .exceptions import AIOError
7
10
8
11
ROBOTO_BEFORE_PATH = os .path .join ("tests" , "testfiles" , "Roboto-Regular.subset1.ttf" )
44
47
ROBOTO_UDIFF_EXCLUDE_HEADPOST_EXPECTED = robo_udiff_ex_headpost .read ()
45
48
46
49
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
+
47
56
def test_unified_diff_default ():
48
57
res = u_diff (ROBOTO_BEFORE_PATH , ROBOTO_AFTER_PATH )
49
58
res_string = "" .join (res )
@@ -63,6 +72,25 @@ def test_unified_diff_default():
63
72
assert line == expected_string_list [x ]
64
73
65
74
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
+
66
94
def test_unified_diff_context_lines_1 ():
67
95
res = u_diff (ROBOTO_BEFORE_PATH , ROBOTO_AFTER_PATH , context_lines = 1 )
68
96
res_string = "" .join (res )
@@ -210,4 +238,24 @@ def test_unified_diff_remote_404_first_file():
210
238
211
239
def test_unified_diff_remote_404_second_file ():
212
240
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