|
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 | 11 | ROBOTO_UDIFF_1CONTEXT_EXPECTED_PATH = os.path.join("tests", "testfiles", "roboto_udiff_1context_expected.txt")
|
| 12 | +ROBOTO_UDIFF_HEADONLY_EXPECTED_PATH = os.path.join("tests", "testfiles", "roboto_udiff_headonly_expected.txt") |
| 13 | +ROBOTO_UDIFF_HEADPOSTONLY_EXPECTED_PATH = os.path.join("tests", "testfiles", "roboto_udiff_headpostonly_expected.txt") |
| 14 | +ROBOTO_UDIFF_EXCLUDE_HEADPOST_EXPECTED_PATH = os.path.join("tests", "testfiles", "roboto_udiff_ex_headpost_expected.txt") |
12 | 15 |
|
13 | 16 | # Setup: define the expected diff text for unified diff
|
14 | 17 | with open(ROBOTO_UDIFF_EXPECTED_PATH, "r") as robo_udiff:
|
|
22 | 25 | with open(ROBOTO_UDIFF_1CONTEXT_EXPECTED_PATH, "r") as robo_udiff_contextlines:
|
23 | 26 | ROBOTO_UDIFF_1CONTEXT_EXPECTED = robo_udiff_contextlines.read()
|
24 | 27 |
|
| 28 | +# Setup: define the expected diff text for head table only diff |
| 29 | +with open(ROBOTO_UDIFF_HEADONLY_EXPECTED_PATH, "r") as robo_udiff_headonly: |
| 30 | + ROBOTO_UDIFF_HEADONLY_EXPECTED = robo_udiff_headonly.read() |
| 31 | + |
| 32 | +# Setup: define the expected diff text for head and post table only diff |
| 33 | +with open(ROBOTO_UDIFF_HEADPOSTONLY_EXPECTED_PATH, "r") as robo_udiff_headpostonly: |
| 34 | + ROBOTO_UDIFF_HEADPOSTONLY_EXPECTED = robo_udiff_headpostonly.read() |
| 35 | + |
| 36 | +# Setup: define the expected diff text for head and post table only diff |
| 37 | +with open(ROBOTO_UDIFF_EXCLUDE_HEADPOST_EXPECTED_PATH, "r") as robo_udiff_ex_headpost: |
| 38 | + ROBOTO_UDIFF_EXCLUDE_HEADPOST_EXPECTED = robo_udiff_ex_headpost.read() |
| 39 | + |
25 | 40 |
|
26 | 41 | def test_unified_diff_default():
|
27 | 42 | res = u_diff(ROBOTO_BEFORE_PATH, ROBOTO_AFTER_PATH)
|
@@ -61,5 +76,68 @@ def test_unified_diff_context_lines_1():
|
61 | 76 | assert line == expected_string_list[x]
|
62 | 77 |
|
63 | 78 |
|
| 79 | +def test_unified_diff_head_table_only(): |
| 80 | + res = u_diff(ROBOTO_BEFORE_PATH, ROBOTO_AFTER_PATH, include_tables=["head"]) |
| 81 | + res_string = "".join(res) |
| 82 | + res_string_list = res_string.split("\n") |
| 83 | + expected_string_list = ROBOTO_UDIFF_HEADONLY_EXPECTED.split("\n") |
| 84 | + |
| 85 | + # have to handle the tests for the top two file path lines |
| 86 | + # differently than the rest of the comparisons because |
| 87 | + # the time is defined using local platform settings |
| 88 | + # which makes tests fail on remote CI testing services vs. |
| 89 | + # my local testing platform... |
| 90 | + for x, line in enumerate(res_string_list): |
| 91 | + # treat top two lines of the diff as comparison of first 10 chars only |
| 92 | + if x in (0, 1): |
| 93 | + assert line[0:9] == expected_string_list[x][0:9] |
| 94 | + else: |
| 95 | + assert line == expected_string_list[x] |
| 96 | + |
| 97 | + |
| 98 | +def test_unified_diff_headpost_table_only(): |
| 99 | + res = u_diff(ROBOTO_BEFORE_PATH, ROBOTO_AFTER_PATH, include_tables=["head", "post"]) |
| 100 | + res_string = "".join(res) |
| 101 | + res_string_list = res_string.split("\n") |
| 102 | + expected_string_list = ROBOTO_UDIFF_HEADPOSTONLY_EXPECTED.split("\n") |
| 103 | + |
| 104 | + # have to handle the tests for the top two file path lines |
| 105 | + # differently than the rest of the comparisons because |
| 106 | + # the time is defined using local platform settings |
| 107 | + # which makes tests fail on remote CI testing services vs. |
| 108 | + # my local testing platform... |
| 109 | + for x, line in enumerate(res_string_list): |
| 110 | + # treat top two lines of the diff as comparison of first 10 chars only |
| 111 | + if x in (0, 1): |
| 112 | + assert line[0:9] == expected_string_list[x][0:9] |
| 113 | + else: |
| 114 | + assert line == expected_string_list[x] |
| 115 | + |
| 116 | + |
| 117 | +def test_unified_diff_exclude_headpost_tables(): |
| 118 | + res = u_diff(ROBOTO_BEFORE_PATH, ROBOTO_AFTER_PATH, exclude_tables=["head", "post"]) |
| 119 | + res_string = "".join(res) |
| 120 | + res_string_list = res_string.split("\n") |
| 121 | + expected_string_list = ROBOTO_UDIFF_EXCLUDE_HEADPOST_EXPECTED.split("\n") |
| 122 | + |
| 123 | + # have to handle the tests for the top two file path lines |
| 124 | + # differently than the rest of the comparisons because |
| 125 | + # the time is defined using local platform settings |
| 126 | + # which makes tests fail on remote CI testing services vs. |
| 127 | + # my local testing platform... |
| 128 | + for x, line in enumerate(res_string_list): |
| 129 | + # treat top two lines of the diff as comparison of first 10 chars only |
| 130 | + if x in (0, 1): |
| 131 | + assert line[0:9] == expected_string_list[x][0:9] |
| 132 | + else: |
| 133 | + assert line == expected_string_list[x] |
| 134 | + |
| 135 | + |
| 136 | +def test_unified_diff_include_with_bad_table_definition(): |
| 137 | + with pytest.raises(KeyError): |
| 138 | + u_diff(ROBOTO_BEFORE_PATH, ROBOTO_AFTER_PATH, include_tables=["bogus"]) |
64 | 139 |
|
65 | 140 |
|
| 141 | +def test_unified_diff_exclude_with_bad_table_definition(): |
| 142 | + with pytest.raises(KeyError): |
| 143 | + u_diff(ROBOTO_BEFORE_PATH, ROBOTO_AFTER_PATH, exclude_tables=["bogus"]) |
0 commit comments