8
8
ROBOTO_AFTER_PATH = os .path .join ("tests" , "testfiles" , "Roboto-Regular.subset2.ttf" )
9
9
ROBOTO_UDIFF_EXPECTED_PATH = os .path .join ("tests" , "testfiles" , "roboto_udiff_expected.txt" )
10
10
ROBOTO_UDIFF_COLOR_EXPECTED_PATH = os .path .join ("tests" , "testfiles" , "roboto_udiff_color_expected.txt" )
11
+ ROBOTO_UDIFF_1CONTEXT_EXPECTED_PATH = os .path .join ("tests" , "testfiles" , "roboto_udiff_1context_expected.txt" )
11
12
12
13
# Setup: define the expected diff text for unified diff
13
14
with open (ROBOTO_UDIFF_EXPECTED_PATH , "r" ) as robo_udiff :
17
18
with open (ROBOTO_UDIFF_COLOR_EXPECTED_PATH , "r" ) as robo_udiff_color :
18
19
ROBOTO_UDIFF_COLOR_EXPECTED = robo_udiff_color .read ()
19
20
21
+ # Setup: define the expected diff text for unified color diff
22
+ with open (ROBOTO_UDIFF_1CONTEXT_EXPECTED_PATH , "r" ) as robo_udiff_contextlines :
23
+ ROBOTO_UDIFF_1CONTEXT_EXPECTED = robo_udiff_contextlines .read ()
24
+
20
25
21
26
def test_unified_diff_default ():
22
27
res = u_diff (ROBOTO_BEFORE_PATH , ROBOTO_AFTER_PATH )
@@ -37,5 +42,24 @@ def test_unified_diff_default():
37
42
assert line == expected_string_list [x ]
38
43
39
44
45
+ def test_unified_diff_context_lines_1 ():
46
+ res = u_diff (ROBOTO_BEFORE_PATH , ROBOTO_AFTER_PATH , context_lines = 1 )
47
+ res_string = "" .join (res )
48
+ res_string_list = res_string .split ("\n " )
49
+ expected_string_list = ROBOTO_UDIFF_1CONTEXT_EXPECTED .split ("\n " )
50
+
51
+ # have to handle the tests for the top two file path lines
52
+ # differently than the rest of the comparisons because
53
+ # the time is defined using local platform settings
54
+ # which makes tests fail on remote CI testing services vs.
55
+ # my local testing platform...
56
+ for x , line in enumerate (res_string_list ):
57
+ # treat top two lines of the diff as comparison of first 10 chars only
58
+ if x in (0 , 1 ):
59
+ assert line [0 :9 ] == expected_string_list [x ][0 :9 ]
60
+ else :
61
+ assert line == expected_string_list [x ]
62
+
63
+
40
64
41
65
0 commit comments