|
12 | 12 | ROBOTO_UDIFF_EXPECTED_PATH = os.path.join("tests", "testfiles", "roboto_udiff_expected.txt")
|
13 | 13 | ROBOTO_UDIFF_COLOR_EXPECTED_PATH = os.path.join("tests", "testfiles", "roboto_udiff_color_expected.txt")
|
14 | 14 | ROBOTO_UDIFF_1CONTEXT_EXPECTED_PATH = os.path.join("tests", "testfiles", "roboto_udiff_1context_expected.txt")
|
| 15 | +ROBOTO_UDIFF_HEADONLY_EXPECTED_PATH = os.path.join("tests", "testfiles", "roboto_udiff_headonly_expected.txt") |
| 16 | +ROBOTO_UDIFF_HEADPOSTONLY_EXPECTED_PATH = os.path.join("tests", "testfiles", "roboto_udiff_headpostonly_expected.txt") |
| 17 | +ROBOTO_UDIFF_EXCLUDE_HEADPOST_EXPECTED_PATH = os.path.join("tests", "testfiles", "roboto_udiff_ex_headpost_expected.txt") |
15 | 18 |
|
16 | 19 |
|
17 | 20 | # Setup: define the expected diff text for unified diff
|
|
27 | 30 | with open(ROBOTO_UDIFF_1CONTEXT_EXPECTED_PATH, "r") as robo_udiff_contextlines:
|
28 | 31 | ROBOTO_UDIFF_1CONTEXT_EXPECTED = robo_udiff_contextlines.read()
|
29 | 32 |
|
| 33 | +# Setup: define the expected diff text for head table only diff |
| 34 | +with open(ROBOTO_UDIFF_HEADONLY_EXPECTED_PATH, "r") as robo_udiff_headonly: |
| 35 | + ROBOTO_UDIFF_HEADONLY_EXPECTED = robo_udiff_headonly.read() |
| 36 | + |
| 37 | +# Setup: define the expected diff text for head and post table only diff |
| 38 | +with open(ROBOTO_UDIFF_HEADPOSTONLY_EXPECTED_PATH, "r") as robo_udiff_headpostonly: |
| 39 | + ROBOTO_UDIFF_HEADPOSTONLY_EXPECTED = robo_udiff_headpostonly.read() |
| 40 | + |
| 41 | +# Setup: define the expected diff text for head and post table only diff |
| 42 | +with open(ROBOTO_UDIFF_EXCLUDE_HEADPOST_EXPECTED_PATH, "r") as robo_udiff_ex_headpost: |
| 43 | + ROBOTO_UDIFF_EXCLUDE_HEADPOST_EXPECTED = robo_udiff_ex_headpost.read() |
| 44 | + |
30 | 45 | #
|
31 | 46 | # File path validations tests
|
32 | 47 | #
|
@@ -54,6 +69,20 @@ def test_main_filepath_validations_false_secondfont(capsys):
|
54 | 69 | assert exit_info.value.code == 1
|
55 | 70 |
|
56 | 71 |
|
| 72 | +# |
| 73 | +# Mutually exclusive argument tests |
| 74 | +# |
| 75 | + |
| 76 | +def test_main_include_exclude_defined_simultaneously(capsys): |
| 77 | + args = ["--include", "head", "--exclude", "head", ROBOTO_BEFORE_PATH, ROBOTO_AFTER_PATH] |
| 78 | + |
| 79 | + with pytest.raises(SystemExit) as exit_info: |
| 80 | + run(args) |
| 81 | + captured = capsys.readouterr() |
| 82 | + assert captured.error.startswith("[*] Error: --include and --exclude are mutually exclusive options") |
| 83 | + assert exit_info.value.code == 1 |
| 84 | + |
| 85 | + |
57 | 86 | #
|
58 | 87 | # Unified diff integration tests
|
59 | 88 | #
|
@@ -119,3 +148,106 @@ def test_main_run_unified_context_lines_1(capsys):
|
119 | 148 | assert line[0:9] == expected_string_list[x][0:9]
|
120 | 149 | else:
|
121 | 150 | assert line == expected_string_list[x]
|
| 151 | + |
| 152 | + |
| 153 | +def test_main_run_unified_head_table_only(capsys): |
| 154 | + args = ["--include", "head", ROBOTO_BEFORE_PATH, ROBOTO_AFTER_PATH] |
| 155 | + |
| 156 | + run(args) |
| 157 | + captured = capsys.readouterr() |
| 158 | + |
| 159 | + res_string_list = captured.out.split("\n") |
| 160 | + expected_string_list = ROBOTO_UDIFF_HEADONLY_EXPECTED.split("\n") |
| 161 | + |
| 162 | + # have to handle the tests for the top two file path lines |
| 163 | + # differently than the rest of the comparisons because |
| 164 | + # the time is defined using local platform settings |
| 165 | + # which makes tests fail on different remote CI testing services |
| 166 | + for x, line in enumerate(res_string_list): |
| 167 | + # treat top two lines of the diff as comparison of first 10 chars only |
| 168 | + if x in (0, 1): |
| 169 | + assert line[0:9] == expected_string_list[x][0:9] |
| 170 | + else: |
| 171 | + assert line == expected_string_list[x] |
| 172 | + |
| 173 | + |
| 174 | +def test_main_run_unified_head_post_tables_only(capsys): |
| 175 | + args = ["--include", "head,post", ROBOTO_BEFORE_PATH, ROBOTO_AFTER_PATH] |
| 176 | + |
| 177 | + run(args) |
| 178 | + captured = capsys.readouterr() |
| 179 | + |
| 180 | + res_string_list = captured.out.split("\n") |
| 181 | + expected_string_list = ROBOTO_UDIFF_HEADPOSTONLY_EXPECTED.split("\n") |
| 182 | + |
| 183 | + # have to handle the tests for the top two file path lines |
| 184 | + # differently than the rest of the comparisons because |
| 185 | + # the time is defined using local platform settings |
| 186 | + # which makes tests fail on different remote CI testing services |
| 187 | + for x, line in enumerate(res_string_list): |
| 188 | + # treat top two lines of the diff as comparison of first 10 chars only |
| 189 | + if x in (0, 1): |
| 190 | + assert line[0:9] == expected_string_list[x][0:9] |
| 191 | + else: |
| 192 | + assert line == expected_string_list[x] |
| 193 | + |
| 194 | + |
| 195 | +def test_main_run_unified_exclude_head_post_tables(capsys): |
| 196 | + args = ["--exclude", "head,post", ROBOTO_BEFORE_PATH, ROBOTO_AFTER_PATH] |
| 197 | + |
| 198 | + run(args) |
| 199 | + captured = capsys.readouterr() |
| 200 | + |
| 201 | + res_string_list = captured.out.split("\n") |
| 202 | + expected_string_list = ROBOTO_UDIFF_EXCLUDE_HEADPOST_EXPECTED.split("\n") |
| 203 | + |
| 204 | + # have to handle the tests for the top two file path lines |
| 205 | + # differently than the rest of the comparisons because |
| 206 | + # the time is defined using local platform settings |
| 207 | + # which makes tests fail on different remote CI testing services |
| 208 | + for x, line in enumerate(res_string_list): |
| 209 | + # treat top two lines of the diff as comparison of first 10 chars only |
| 210 | + if x in (0, 1): |
| 211 | + assert line[0:9] == expected_string_list[x][0:9] |
| 212 | + else: |
| 213 | + assert line == expected_string_list[x] |
| 214 | + |
| 215 | + |
| 216 | +def test_main_include_with_bad_table_definition(capsys): |
| 217 | + args = ["--include", "bogus", ROBOTO_BEFORE_PATH, ROBOTO_AFTER_PATH] |
| 218 | + |
| 219 | + with pytest.raises(SystemExit) as exit_info: |
| 220 | + run(args) |
| 221 | + captured = capsys.readouterr() |
| 222 | + assert captured.error.startswith("[*] ERROR:") |
| 223 | + assert exit_info.value.code == 1 |
| 224 | + |
| 225 | + |
| 226 | +def test_main_include_with_bad_table_definition_in_multi_table_request(capsys): |
| 227 | + args = ["--include", "head,bogus", ROBOTO_BEFORE_PATH, ROBOTO_AFTER_PATH] |
| 228 | + |
| 229 | + with pytest.raises(SystemExit) as exit_info: |
| 230 | + run(args) |
| 231 | + captured = capsys.readouterr() |
| 232 | + assert captured.error.startswith("[*] ERROR:") |
| 233 | + assert exit_info.value.code == 1 |
| 234 | + |
| 235 | + |
| 236 | +def test_main_exclude_with_bad_table_definition(capsys): |
| 237 | + args = ["--exclude", "bogus", ROBOTO_BEFORE_PATH, ROBOTO_AFTER_PATH] |
| 238 | + |
| 239 | + with pytest.raises(SystemExit) as exit_info: |
| 240 | + run(args) |
| 241 | + captured = capsys.readouterr() |
| 242 | + assert captured.error.startswith("[*] ERROR:") |
| 243 | + assert exit_info.value.code == 1 |
| 244 | + |
| 245 | + |
| 246 | +def test_main_exclude_with_bad_table_definition_in_multi_table_request(capsys): |
| 247 | + args = ["--exclude", "head,bogus", ROBOTO_BEFORE_PATH, ROBOTO_AFTER_PATH] |
| 248 | + |
| 249 | + with pytest.raises(SystemExit) as exit_info: |
| 250 | + run(args) |
| 251 | + captured = capsys.readouterr() |
| 252 | + assert captured.error.startswith("[*] ERROR:") |
| 253 | + assert exit_info.value.code == 1 |
0 commit comments