Skip to content

Commit b1752a4

Browse files
committed
add non-default context line unit test
1 parent 99be971 commit b1752a4

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

tests/test_diff.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
ROBOTO_AFTER_PATH = os.path.join("tests", "testfiles", "Roboto-Regular.subset2.ttf")
99
ROBOTO_UDIFF_EXPECTED_PATH = os.path.join("tests", "testfiles", "roboto_udiff_expected.txt")
1010
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")
1112

1213
# Setup: define the expected diff text for unified diff
1314
with open(ROBOTO_UDIFF_EXPECTED_PATH, "r") as robo_udiff:
@@ -17,6 +18,10 @@
1718
with open(ROBOTO_UDIFF_COLOR_EXPECTED_PATH, "r") as robo_udiff_color:
1819
ROBOTO_UDIFF_COLOR_EXPECTED = robo_udiff_color.read()
1920

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+
2025

2126
def test_unified_diff_default():
2227
res = u_diff(ROBOTO_BEFORE_PATH, ROBOTO_AFTER_PATH)
@@ -37,5 +42,24 @@ def test_unified_diff_default():
3742
assert line == expected_string_list[x]
3843

3944

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+
4064

4165

0 commit comments

Comments
 (0)