Skip to content

Commit d090afd

Browse files
committed
[diff] add unit tests for external_diff function
1 parent c9f0c9c commit d090afd

File tree

4 files changed

+575
-2
lines changed

4 files changed

+575
-2
lines changed

lib/fdiff/diff.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
# Private functions
2222
#
2323
#
24-
24+
# TODO: add docstrings for all private functions
2525

2626
def _async_fetch_files(dirpath, urls):
2727
loop = asyncio.get_event_loop()
@@ -252,7 +252,7 @@ def external_diff(
252252
if len(output) == 0 and exit_status is not None:
253253
err = process.stderr.read()
254254
if err:
255-
raise AIOError(err)
255+
raise IOError(err)
256256
yield output, exit_status
257257
break
258258
else:

tests/test_diff_unix_only.py

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import os
2+
import sys
3+
import pytest
4+
5+
from fdiff.diff import external_diff
6+
7+
# these tests rely on a PATH install of `diff` executable on Unix
8+
# they are not executed on Windows platforms
9+
if sys.platform.startswith("win"):
10+
pytest.skip("skipping windows-only tests", allow_module_level=True)
11+
12+
ROBOTO_BEFORE_PATH = os.path.join("tests", "testfiles", "Roboto-Regular.subset1.ttf")
13+
ROBOTO_AFTER_PATH = os.path.join("tests", "testfiles", "Roboto-Regular.subset2.ttf")
14+
ROBOTO_EXTDIFF_EXPECTED_PATH = os.path.join("tests", "testfiles", "roboto_udiff_expected.txt")
15+
ROBOTO_EXTDIFF_COLOR_EXPECTED_PATH = os.path.join("tests", "testfiles", "roboto_udiff_color_expected.txt")
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+
21+
# Setup: define the expected diff text for unified diff
22+
with open(ROBOTO_EXTDIFF_EXPECTED_PATH, "r") as robo_extdiff:
23+
ROBOTO_EXTDIFF_EXPECTED = robo_extdiff.read()
24+
25+
# Setup: define the expected diff text for unified color diff
26+
with open(ROBOTO_EXTDIFF_COLOR_EXPECTED_PATH, "r") as robo_extdiff_color:
27+
ROBOTO_EXTDIFF_COLOR_EXPECTED = robo_extdiff_color.read()
28+
29+
30+
def test_external_diff_default():
31+
res = external_diff("diff -u", ROBOTO_BEFORE_PATH, ROBOTO_AFTER_PATH)
32+
expected_string_list = ROBOTO_EXTDIFF_EXPECTED.split("\n")
33+
34+
# have to handle the tests for the top two file path lines
35+
# differently than the rest of the comparisons because
36+
# the time is defined using local platform settings
37+
# which makes tests fail on remote CI testing services vs.
38+
# my local testing platform...
39+
for x, line in enumerate(res):
40+
# treat top two lines of the diff as comparison of first 3 chars only
41+
if x in (0, 1):
42+
assert line[0][0:2] == expected_string_list[x][0:2]
43+
elif x in range(2, 10):
44+
assert line[0] == expected_string_list[x] + os.linesep
45+
else:
46+
# skip lines beyond first 10
47+
pass
48+
49+
50+
def test_external_diff_without_mp_optimizations():
51+
res = external_diff("diff -u", ROBOTO_BEFORE_PATH, ROBOTO_AFTER_PATH, use_multiprocess=False)
52+
expected_string_list = ROBOTO_EXTDIFF_EXPECTED.split("\n")
53+
54+
# have to handle the tests for the top two file path lines
55+
# differently than the rest of the comparisons because
56+
# the time is defined using local platform settings
57+
# which makes tests fail on remote CI testing services vs.
58+
# my local testing platform...
59+
for x, line in enumerate(res):
60+
# treat top two lines of the diff as comparison of first 3 chars only
61+
if x in (0, 1):
62+
assert line[0][0:2] == expected_string_list[x][0:2]
63+
elif x in range(2, 10):
64+
assert line[0] == expected_string_list[x] + os.linesep
65+
else:
66+
# skip lines beyond first 10
67+
pass
68+
69+
70+
def test_external_diff_remote_fonts():
71+
res = external_diff("diff -u", ROBOTO_BEFORE_URL, ROBOTO_AFTER_URL)
72+
expected_string_list = ROBOTO_EXTDIFF_EXPECTED.split("\n")
73+
74+
# have to handle the tests for the top two file path lines
75+
# differently than the rest of the comparisons because
76+
# the time is defined using local platform settings
77+
# which makes tests fail on remote CI testing services vs.
78+
# my local testing platform...
79+
for x, line in enumerate(res):
80+
# treat top two lines of the diff as comparison of first 3 chars only
81+
if x in (0, 1):
82+
assert line[0][0:2] == expected_string_list[x][0:2]
83+
elif x in range(2, 10):
84+
assert line[0] == expected_string_list[x] + os.linesep
85+
else:
86+
# skip lines beyond first 10
87+
pass
Lines changed: 243 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,243 @@
1+
--- /var/folders/x7/vs8mbwmx1hg1vcb53nlygt0m0000gn/T/tmp6mjzf6a2/left.ttx 2019-12-17 22:47:31.000000000 -0500
2+
+++ /var/folders/x7/vs8mbwmx1hg1vcb53nlygt0m0000gn/T/tmp6mjzf6a2/right.ttx 2019-12-17 22:47:31.000000000 -0500
3+
@@ -4,34 +4,34 @@
4+
 <GlyphOrder>
5+
<!-- The 'id' attribute is only for humans; it is ignored when parsed. -->
6+
<GlyphID id="0" name=".notdef"/>
7+
- <GlyphID id="1" name=".null"/>
8+
- <GlyphID id="2" name="uni0002"/>
9+
- <GlyphID id="3" name="uni0009"/>
10+
+ <GlyphID id="1" name="glyph00001"/>
11+
+ <GlyphID id="2" name="glyph00002"/>
12+
+ <GlyphID id="3" name="glyph00003"/>
13+
 <GlyphID id="4" name="space"/>
14+
<GlyphID id="5" name="exclam"/>
15+
<GlyphID id="6" name="quotedbl"/>
16+
<GlyphID id="7" name="numbersign"/>
17+
<GlyphID id="8" name="dollar"/>
18+
<GlyphID id="9" name="percent"/>
19+
- <GlyphID id="10" name="dollar.smcp"/>
20+
+ <GlyphID id="10" name="glyph00010"/>
21+
 </GlyphOrder>
22+
23+
<head>
24+
<!-- Most of this table will be recalculated by the compiler -->
25+
<tableVersion value="1.0"/>
26+
<fontRevision value="2.138"/>
27+
- <checkSumAdjustment value="0x2c16bb4a"/>
28+
+ <checkSumAdjustment value="0x5813354c"/>
29+
 <magicNumber value="0x5f0f3cf5"/>
30+
<flags value="00000000 00011001"/>
31+
<unitsPerEm value="2048"/>
32+
<created value="Fri Sep 12 10:29:34 2008"/>
33+
- <modified value="Thu May 25 10:49:57 2017"/>
34+
- <xMin value="-1825"/>
35+
- <yMin value="-555"/>
36+
- <xMax value="4188"/>
37+
- <yMax value="2163"/>
38+
+ <modified value="Thu Sep 5 18:07:11 2019"/>
39+
+ <xMin value="68"/>
40+
+ <yMin value="-237"/>
41+
+ <xMax value="1411"/>
42+
+ <yMax value="1692"/>
43+
 <macStyle value="00000000 00000000"/>
44+
- <lowestRecPPEM value="9"/>
45+
+ <lowestRecPPEM value="8"/>
46+
 <fontDirectionHint value="2"/>
47+
<indexToLocFormat value="0"/>
48+
<glyphDataFormat value="0"/>
49+
@@ -42,10 +42,10 @@
50+
 <ascent value="1900"/>
51+
<descent value="-500"/>
52+
<lineGap value="0"/>
53+
- <advanceWidthMax value="4368"/>
54+
- <minLeftSideBearing value="-1825"/>
55+
- <minRightSideBearing value="-1034"/>
56+
- <xMaxExtent value="4187"/>
57+
+ <advanceWidthMax value="1500"/>
58+
+ <minLeftSideBearing value="69"/>
59+
+ <minRightSideBearing value="26"/>
60+
+ <xMaxExtent value="1411"/>
61+
 <caretSlopeRise value="1"/>
62+
<caretSlopeRun value="0"/>
63+
<caretOffset value="0"/>
64+
@@ -61,10 +61,10 @@
65+
 <!-- Most of this table will be recalculated by the compiler -->
66+
<tableVersion value="0x10000"/>
67+
<numGlyphs value="11"/>
68+
- <maxPoints value="232"/>
69+
- <maxContours value="22"/>
70+
- <maxCompositePoints value="84"/>
71+
- <maxCompositeContours value="7"/>
72+
+ <maxPoints value="60"/>
73+
+ <maxContours value="5"/>
74+
+ <maxCompositePoints value="0"/>
75+
+ <maxCompositeContours value="0"/>
76+
 <maxZones value="1"/>
77+
<maxTwilightPoints value="0"/>
78+
<maxStorage value="0"/>
79+
@@ -72,8 +72,8 @@
80+
 <maxInstructionDefs value="0"/>
81+
<maxStackElements value="0"/>
82+
<maxSizeOfInstructions value="0"/>
83+
- <maxComponentElements value="6"/>
84+
- <maxComponentDepth value="2"/>
85+
+ <maxComponentElements value="0"/>
86+
+ <maxComponentDepth value="0"/>
87+
 </maxp>
88+
89+
<OS_2>
90+
@@ -131,16 +131,16 @@
91+

92+
<hmtx>
93+
<mtx name=".notdef" width="908" lsb="100"/>
94+
- <mtx name=".null" width="0" lsb="0"/>
95+
 <mtx name="dollar" width="1151" lsb="110"/>
96+
- <mtx name="dollar.smcp" width="1056" lsb="68"/>
97+
 <mtx name="exclam" width="528" lsb="161"/>
98+
+ <mtx name="glyph00001" width="0" lsb="0"/>
99+
+ <mtx name="glyph00002" width="0" lsb="0"/>
100+
+ <mtx name="glyph00003" width="508" lsb="0"/>
101+
+ <mtx name="glyph00010" width="1056" lsb="69"/>
102+
 <mtx name="numbersign" width="1261" lsb="119"/>
103+
<mtx name="percent" width="1500" lsb="105"/>
104+
<mtx name="quotedbl" width="656" lsb="137"/>
105+
<mtx name="space" width="508" lsb="0"/>
106+
- <mtx name="uni0002" width="0" lsb="0"/>
107+
- <mtx name="uni0009" width="508" lsb="0"/>
108+
 </hmtx>
109+
110+
<cmap>
111+
@@ -218,8 +218,6 @@
112+
 <instructions/>
113+
</TTGlyph>
114+
115+
- <TTGlyph name=".null"/><!-- contains no outline data -->
116+
-
117+
 <TTGlyph name="dollar" xMin="110" yMin="-208" xMax="1042" yMax="1692">
118+
<contour>
119+
<pt x="1042" y="377" on="1"/>
120+
@@ -270,7 +268,37 @@
121+
 <instructions/>
122+
</TTGlyph>
123+
124+
- <TTGlyph name="dollar.smcp" xMin="68" yMin="-237" xMax="990" yMax="1395">
125+
+ <TTGlyph name="exclam" xMin="161" yMin="-12" xMax="380" yMax="1456">
126+
+ <contour>
127+
+ <pt x="361" y="1456" on="1"/>
128+
+ <pt x="348" y="411" on="1"/>
129+
+ <pt x="181" y="411" on="1"/>
130+
+ <pt x="167" y="1456" on="1"/>
131+
+ </contour>
132+
+ <contour>
133+
+ <pt x="161" y="93" on="1"/>
134+
+ <pt x="161" y="138" on="0"/>
135+
+ <pt x="216" y="200" on="0"/>
136+
+ <pt x="270" y="200" on="1"/>
137+
+ <pt x="323" y="200" on="0"/>
138+
+ <pt x="380" y="138" on="0"/>
139+
+ <pt x="380" y="93" on="1"/>
140+
+ <pt x="380" y="50" on="0"/>
141+
+ <pt x="323" y="-12" on="0"/>
142+
+ <pt x="270" y="-12" on="1"/>
143+
+ <pt x="216" y="-12" on="0"/>
144+
+ <pt x="161" y="50" on="0"/>
145+
+ </contour>
146+
+ <instructions/>
147+
+ </TTGlyph>
148+
+
149+
+ <TTGlyph name="glyph00001"/><!-- contains no outline data -->
150+
+
151+
+ <TTGlyph name="glyph00002"/><!-- contains no outline data -->
152+
+
153+
+ <TTGlyph name="glyph00003"/><!-- contains no outline data -->
154+
+
155+
+ <TTGlyph name="glyph00010" xMin="68" yMin="-237" xMax="990" yMax="1395">
156+
 <contour>
157+
<pt x="990" y="300" on="1"/>
158+
<pt x="990" y="168" on="0"/>
159+
@@ -320,30 +348,6 @@
160+
 <instructions/>
161+
</TTGlyph>
162+
163+
- <TTGlyph name="exclam" xMin="161" yMin="-12" xMax="380" yMax="1456">
164+
- <contour>
165+
- <pt x="361" y="1456" on="1"/>
166+
- <pt x="348" y="411" on="1"/>
167+
- <pt x="181" y="411" on="1"/>
168+
- <pt x="167" y="1456" on="1"/>
169+
- </contour>
170+
- <contour>
171+
- <pt x="161" y="93" on="1"/>
172+
- <pt x="161" y="138" on="0"/>
173+
- <pt x="216" y="200" on="0"/>
174+
- <pt x="270" y="200" on="1"/>
175+
- <pt x="323" y="200" on="0"/>
176+
- <pt x="380" y="138" on="0"/>
177+
- <pt x="380" y="93" on="1"/>
178+
- <pt x="380" y="50" on="0"/>
179+
- <pt x="323" y="-12" on="0"/>
180+
- <pt x="270" y="-12" on="1"/>
181+
- <pt x="216" y="-12" on="0"/>
182+
- <pt x="161" y="50" on="0"/>
183+
- </contour>
184+
- <instructions/>
185+
- </TTGlyph>
186+
-
187+
 <TTGlyph name="numbersign" xMin="119" yMin="0" xMax="1235" yMax="1456">
188+
<contour>
189+
<pt x="686" y="0" on="1"/>
190+
@@ -478,10 +482,6 @@
191+

192+
<TTGlyph name="space"/><!-- contains no outline data -->
193+
194+
- <TTGlyph name="uni0002"/><!-- contains no outline data -->
195+
-
196+
- <TTGlyph name="uni0009"/><!-- contains no outline data -->
197+
-
198+
 </glyf>
199+
200+
<name>
201+
@@ -529,33 +529,6 @@
202+
 </namerecord>
203+
</name>
204+
205+
- <post>
206+
- <formatType value="2.0"/>
207+
- <italicAngle value="0.0"/>
208+
- <underlinePosition value="-150"/>
209+
- <underlineThickness value="100"/>
210+
- <isFixedPitch value="0"/>
211+
- <minMemType42 value="0"/>
212+
- <maxMemType42 value="0"/>
213+
- <minMemType1 value="0"/>
214+
- <maxMemType1 value="0"/>
215+
- <psNames>
216+
- <!-- This file uses unique glyph names based on the information
217+
- found in the 'post' table. Since these names might not be unique,
218+
- we have to invent artificial names in case of clashes. In order to
219+
- be able to retain the original information, we need a name to
220+
- ps name mapping for those cases where they differ. That's what
221+
- you see below.
222+
- -->
223+
- </psNames>
224+
- <extraNames>
225+
- <!-- following are the name that are not taken from the standard Mac glyph order -->
226+
- <psName name="uni0002"/>
227+
- <psName name="uni0009"/>
228+
- <psName name="dollar.smcp"/>
229+
- </extraNames>
230+
- </post>
231+
-
232+
 <GDEF>
233+
<Version value="0x00010002"/>
234+
<MarkGlyphSetsDef>
235+
@@ -757,7 +730,7 @@
236+
 <LookupFlag value="0"/>
237+
<!-- SubTableCount=1 -->
238+
<SingleSubst index="0" Format="1">
239+
- <Substitution in="dollar" out="dollar.smcp"/>
240+
+ <Substitution in="dollar" out="glyph00010"/>
241+
 </SingleSubst>
242+
</Lookup>
243+
</LookupList>

0 commit comments

Comments
 (0)