3
3
import pytest
4
4
5
5
from fdiff .diff import u_diff
6
+ from fdiff .exceptions import AIOError
6
7
7
8
ROBOTO_BEFORE_PATH = os .path .join ("tests" , "testfiles" , "Roboto-Regular.subset1.ttf" )
8
9
ROBOTO_AFTER_PATH = os .path .join ("tests" , "testfiles" , "Roboto-Regular.subset2.ttf" )
13
14
ROBOTO_UDIFF_HEADPOSTONLY_EXPECTED_PATH = os .path .join ("tests" , "testfiles" , "roboto_udiff_headpostonly_expected.txt" )
14
15
ROBOTO_UDIFF_EXCLUDE_HEADPOST_EXPECTED_PATH = os .path .join ("tests" , "testfiles" , "roboto_udiff_ex_headpost_expected.txt" )
15
16
17
+ ROBOTO_BEFORE_URL = "https://github.com/source-foundry/fdiff/raw/master/tests/testfiles/Roboto-Regular.subset1.ttf"
18
+ ROBOTO_AFTER_URL = "https://github.com/source-foundry/fdiff/raw/master/tests/testfiles/Roboto-Regular.subset2.ttf"
19
+
20
+ URL_404 = "https://httpbin.org/status/404"
21
+
16
22
# Setup: define the expected diff text for unified diff
17
23
with open (ROBOTO_UDIFF_EXPECTED_PATH , "r" ) as robo_udiff :
18
24
ROBOTO_UDIFF_EXPECTED = robo_udiff .read ()
@@ -141,3 +147,67 @@ def test_unified_diff_include_with_bad_table_definition():
141
147
def test_unified_diff_exclude_with_bad_table_definition ():
142
148
with pytest .raises (KeyError ):
143
149
u_diff (ROBOTO_BEFORE_PATH , ROBOTO_AFTER_PATH , exclude_tables = ["bogus" ])
150
+
151
+
152
+ def test_unified_diff_remote_fonts ():
153
+ res = u_diff (ROBOTO_BEFORE_URL , ROBOTO_AFTER_URL )
154
+ res_string = "" .join (res )
155
+ res_string_list = res_string .split ("\n " )
156
+ expected_string_list = ROBOTO_UDIFF_EXPECTED .split ("\n " )
157
+
158
+ # have to handle the tests for the top two file path lines
159
+ # differently than the rest of the comparisons
160
+ for x , line in enumerate (res_string_list ):
161
+ # treat top two lines of the diff as comparison of first 10 chars only
162
+ if x == 0 :
163
+ assert line [0 :9 ] == "--- https"
164
+ elif x == 1 :
165
+ assert line [0 :9 ] == "+++ https"
166
+ else :
167
+ assert line == expected_string_list [x ]
168
+
169
+
170
+ def test_unified_diff_remote_and_local_fonts ():
171
+ res = u_diff (ROBOTO_BEFORE_URL , ROBOTO_AFTER_PATH )
172
+ res_string = "" .join (res )
173
+ res_string_list = res_string .split ("\n " )
174
+ expected_string_list = ROBOTO_UDIFF_EXPECTED .split ("\n " )
175
+
176
+ # have to handle the tests for the top two file path lines
177
+ # differently than the rest of the comparisons
178
+ for x , line in enumerate (res_string_list ):
179
+ # treat top two lines of the diff as comparison of first 10 chars only
180
+ if x == 0 :
181
+ assert line [0 :9 ] == "--- https"
182
+ elif x == 1 :
183
+ assert line [0 :9 ] == expected_string_list [x ][0 :9 ]
184
+ else :
185
+ assert line == expected_string_list [x ]
186
+
187
+
188
+ def test_unified_diff_local_and_remote_fonts ():
189
+ res = u_diff (ROBOTO_BEFORE_PATH , ROBOTO_AFTER_URL )
190
+ res_string = "" .join (res )
191
+ res_string_list = res_string .split ("\n " )
192
+ expected_string_list = ROBOTO_UDIFF_EXPECTED .split ("\n " )
193
+
194
+ # have to handle the tests for the top two file path lines
195
+ # differently than the rest of the comparisons
196
+ for x , line in enumerate (res_string_list ):
197
+ # treat top two lines of the diff as comparison of first 10 chars only
198
+ if x == 0 :
199
+ assert line [0 :9 ] == expected_string_list [x ][0 :9 ]
200
+ elif x == 1 :
201
+ assert line [0 :9 ] == "+++ https"
202
+ else :
203
+ assert line == expected_string_list [x ]
204
+
205
+
206
+ def test_unified_diff_remote_404_first_file ():
207
+ with pytest .raises (AIOError ):
208
+ u_diff (URL_404 , ROBOTO_AFTER_URL )
209
+
210
+
211
+ def test_unified_diff_remote_404_second_file ():
212
+ with pytest .raises (AIOError ):
213
+ u_diff (ROBOTO_BEFORE_URL , URL_404 )
0 commit comments