|
2 | 2 | # -*- coding: utf-8 -*- |
3 | 3 |
|
4 | 4 | import os |
| 5 | +import sys |
| 6 | +from unittest.mock import MagicMock |
5 | 7 |
|
6 | 8 | import pytest |
7 | 9 |
|
8 | 10 | from fdiff.__main__ import run |
9 | 11 |
|
10 | 12 | ROBOTO_BEFORE_PATH = os.path.join("tests", "testfiles", "Roboto-Regular.subset1.ttf") |
11 | 13 | ROBOTO_AFTER_PATH = os.path.join("tests", "testfiles", "Roboto-Regular.subset2.ttf") |
12 | | -ROBOTO_UDIFF_EXPECTED_PATH = os.path.join("tests", "testfiles", "roboto_udiff_expected.txt") |
13 | | -ROBOTO_UDIFF_COLOR_EXPECTED_PATH = os.path.join("tests", "testfiles", "roboto_udiff_color_expected.txt") |
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") |
| 14 | +ROBOTO_UDIFF_EXPECTED_PATH = os.path.join( |
| 15 | + "tests", "testfiles", "roboto_udiff_expected.txt" |
| 16 | +) |
| 17 | +ROBOTO_UDIFF_COLOR_EXPECTED_PATH = os.path.join( |
| 18 | + "tests", "testfiles", "roboto_udiff_color_expected.txt" |
| 19 | +) |
| 20 | +ROBOTO_UDIFF_1CONTEXT_EXPECTED_PATH = os.path.join( |
| 21 | + "tests", "testfiles", "roboto_udiff_1context_expected.txt" |
| 22 | +) |
| 23 | +ROBOTO_UDIFF_HEADONLY_EXPECTED_PATH = os.path.join( |
| 24 | + "tests", "testfiles", "roboto_udiff_headonly_expected.txt" |
| 25 | +) |
| 26 | +ROBOTO_UDIFF_HEADPOSTONLY_EXPECTED_PATH = os.path.join( |
| 27 | + "tests", "testfiles", "roboto_udiff_headpostonly_expected.txt" |
| 28 | +) |
| 29 | +ROBOTO_UDIFF_EXCLUDE_HEADPOST_EXPECTED_PATH = os.path.join( |
| 30 | + "tests", "testfiles", "roboto_udiff_ex_headpost_expected.txt" |
| 31 | +) |
18 | 32 |
|
19 | 33 | ROBOTO_BEFORE_URL = "https://github.com/source-foundry/fdiff/raw/master/tests/testfiles/Roboto-Regular.subset1.ttf" |
20 | 34 | ROBOTO_AFTER_URL = "https://github.com/source-foundry/fdiff/raw/master/tests/testfiles/Roboto-Regular.subset2.ttf" |
@@ -80,28 +94,41 @@ def test_main_filepath_validations_false_secondfont(capsys): |
80 | 94 | # Mutually exclusive argument tests |
81 | 95 | # |
82 | 96 |
|
| 97 | + |
83 | 98 | def test_main_include_exclude_defined_simultaneously(capsys): |
84 | | - args = ["--include", "head", "--exclude", "head", ROBOTO_BEFORE_PATH, ROBOTO_AFTER_PATH] |
| 99 | + args = [ |
| 100 | + "--include", |
| 101 | + "head", |
| 102 | + "--exclude", |
| 103 | + "head", |
| 104 | + ROBOTO_BEFORE_PATH, |
| 105 | + ROBOTO_AFTER_PATH, |
| 106 | + ] |
85 | 107 |
|
86 | 108 | with pytest.raises(SystemExit) as exit_info: |
87 | 109 | run(args) |
88 | 110 |
|
89 | 111 | captured = capsys.readouterr() |
90 | | - assert captured.err.startswith("[*] Error: --include and --exclude are mutually exclusive options") |
| 112 | + assert captured.err.startswith( |
| 113 | + "[*] Error: --include and --exclude are mutually exclusive options" |
| 114 | + ) |
91 | 115 | assert exit_info.value.code == 1 |
92 | 116 |
|
93 | 117 |
|
94 | 118 | # |
95 | 119 | # Unified diff integration tests |
96 | 120 | # |
97 | 121 |
|
| 122 | + |
98 | 123 | def test_main_run_unified_default_local_files_no_diff(capsys): |
99 | 124 | """Test default behavior when there is no difference in font files under evaluation""" |
100 | 125 | args = [ROBOTO_BEFORE_PATH, ROBOTO_BEFORE_PATH] |
101 | 126 |
|
102 | 127 | run(args) |
103 | 128 | captured = capsys.readouterr() |
104 | | - assert captured.out.startswith("[*] There is no difference between the files.") |
| 129 | + assert captured.out.startswith( |
| 130 | + "[*] There is no difference in the tested OpenType tables" |
| 131 | + ) |
105 | 132 |
|
106 | 133 |
|
107 | 134 | def test_main_run_unified_default_local_files(capsys): |
@@ -180,24 +207,24 @@ def test_main_run_unified_default_404(capsys): |
180 | 207 |
|
181 | 208 |
|
182 | 209 | def test_main_run_unified_color(capsys): |
183 | | - args = ["-c", ROBOTO_BEFORE_PATH, ROBOTO_AFTER_PATH] |
| 210 | + # prior to v3.0.0, the `-c` / `--color` option was required for color output |
| 211 | + # this is the default as of v3.0.0 and the test arguments were |
| 212 | + # modified here |
| 213 | + args = [ROBOTO_BEFORE_PATH, ROBOTO_AFTER_PATH] |
| 214 | + # we also need to mock sys.stdout.isatty because color does not |
| 215 | + # show when this returns False |
| 216 | + sys.stdout.isatty = MagicMock(return_value=True) |
184 | 217 |
|
185 | 218 | run(args) |
186 | 219 | captured = capsys.readouterr() |
187 | | - |
| 220 | + # spot checks for escape code start sequence |
188 | 221 | res_string_list = captured.out.split("\n") |
189 | | - expected_string_list = ROBOTO_UDIFF_COLOR_EXPECTED.split("\n") |
190 | | - |
191 | | - # have to handle the tests for the top two file path lines |
192 | | - # differently than the rest of the comparisons because |
193 | | - # the time is defined using local platform settings |
194 | | - # which makes tests fail on different remote CI testing services |
195 | | - for x, line in enumerate(res_string_list): |
196 | | - # treat top two lines of the diff as comparison of first 10 chars only |
197 | | - if x in (0, 1): |
198 | | - assert line[0:9] == expected_string_list[x][0:9] |
199 | | - else: |
200 | | - assert line == expected_string_list[x] |
| 222 | + assert captured.out.startswith("\x1b") |
| 223 | + assert res_string_list[10].startswith("\x1b") |
| 224 | + assert res_string_list[71].startswith("\x1b") |
| 225 | + assert res_string_list[180].startswith("\x1b") |
| 226 | + assert res_string_list[200].startswith("\x1b") |
| 227 | + assert res_string_list[238].startswith("\x1b") |
201 | 228 |
|
202 | 229 |
|
203 | 230 | def test_main_run_unified_context_lines_1(capsys): |
|
0 commit comments