Skip to content

Commit 9fa30a6

Browse files
authored
Merge pull request #45 from hjwp/black
Black.
2 parents e1c9c44 + 3bb6f9b commit 9fa30a6

File tree

2 files changed

+85
-85
lines changed

2 files changed

+85
-85
lines changed

tests/conftest.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
pytest_plugins = 'pytester'
1+
pytest_plugins = "pytester"

tests/test_pytest_icdiff.py

+84-84
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
import icdiff
2-
from unittest import mock
3-
import pytest
42
import re
53
import sys
64
from pprintpp import pformat
75

8-
YELLOW_ON = '\x1b[1;33m'
9-
COLOR_OFF = '\x1b[m'
10-
GREEN_ON = '\x1b[1;32m'
11-
ANSI_ESCAPE_RE = re.compile(r'(\x9B|\x1B\[)[0-?]*[ -/]*[@-~]')
12-
6+
YELLOW_ON = "\x1b[1;33m"
7+
COLOR_OFF = "\x1b[m"
8+
GREEN_ON = "\x1b[1;32m"
9+
ANSI_ESCAPE_RE = re.compile(r"(\x9B|\x1B\[)[0-?]*[ -/]*[@-~]")
1310

1411

1512
def test_short_dict(testdir):
@@ -20,15 +17,15 @@ def test_short_dict(testdir):
2017
two = {
2118
1: "the number one",
2219
2: "the number three",
23-
6: [1, 2, 3]
20+
6: [1, 2, 3],
2421
}
2522
testdir.makepyfile(
2623
f"""
2724
def test_one():
2825
assert {one!r} == {two!r}
2926
"""
3027
)
31-
output = testdir.runpytest('-vv').stdout.str()
28+
output = testdir.runpytest("-vv").stdout.str()
3229
print(repr(output))
3330
two_left = "'the number two'"
3431
two_right = "'the number three'"
@@ -46,7 +43,7 @@ def test_short_dict_with_colorization(testdir):
4643
two = {
4744
1: "the number one",
4845
2: "the number three",
49-
6: [1, 2, 3]
46+
6: [1, 2, 3],
5047
}
5148
testdir.makepyfile(
5249
f"""
@@ -55,8 +52,8 @@ def test_one():
5552
"""
5653
)
5754
# Force colorization in py TerminalWriter
58-
testdir.monkeypatch.setenv('PY_COLORS', '1')
59-
output = testdir.runpytest('-vv').stdout.str()
55+
testdir.monkeypatch.setenv("PY_COLORS", "1")
56+
output = testdir.runpytest("-vv").stdout.str()
6057
print(repr(output))
6158
two_left = f"'the number t{YELLOW_ON}wo{COLOR_OFF}'"
6259
two_right = f"'the number t{YELLOW_ON}hree{COLOR_OFF}'"
@@ -68,55 +65,55 @@ def test_one():
6865

6966
def test_long_dict(testdir):
7067
one = {
71-
'currency': 'USD',
72-
'default_UK_warehouse': 'xforce',
73-
'default_incoterm': 'EXW',
74-
'name': 'John Doe',
75-
'payment_term': '30% deposit, 70% balance',
76-
'reference': '42551456-a1b3-49bd-beed-b168d9a5ac83',
77-
'website': 'http://megasofas.example.com',
78-
'main_contact': {
79-
'city': 'Madeira',
80-
'country': 'PT',
81-
'email': '[email protected]',
82-
'fax': '012356 789039',
83-
'mobile': '012356 789039',
84-
'name': 'Almeida & Filhos - Example, S.A.',
85-
'phone': '253444802010',
86-
'postcode': '4815-123',
87-
'street': "Senhora Test D'Ajuda, 432",
88-
'street2': 'Moreira de Conegos'
68+
"currency": "USD",
69+
"default_UK_warehouse": "xforce",
70+
"default_incoterm": "EXW",
71+
"name": "John Doe",
72+
"payment_term": "30% deposit, 70% balance",
73+
"reference": "42551456-a1b3-49bd-beed-b168d9a5ac83",
74+
"website": "http://megasofas.example.com",
75+
"main_contact": {
76+
"city": "Madeira",
77+
"country": "PT",
78+
"email": "[email protected]",
79+
"fax": "012356 789039",
80+
"mobile": "012356 789039",
81+
"name": "Almeida & Filhos - Example, S.A.",
82+
"phone": "253444802010",
83+
"postcode": "4815-123",
84+
"street": "Senhora Test D'Ajuda, 432",
85+
"street2": "Moreira de Conegos",
8986
},
9087
}
9188
two = {
92-
'currency': 'USD',
93-
'default_UK_warehouse': 'iforce',
94-
'default_incoterm': 'EXW',
95-
'freight_forwarder': 'flexport',
96-
'name': 'John Doe',
97-
'payment_term': '30% deposit, 70% balance',
98-
'reference': '42551456-a1b3-49bd-beed-b168d9a5ac83',
99-
'website': 'http://megasofas.example.com',
100-
'main_contact': {
101-
'name': 'Almeida & Filhos - Example, S.A.',
102-
'email': '[email protected]',
103-
'street': "Senhora Test D'Ajuda, 432",
104-
'street2': 'Moreira de Conegos',
105-
'postcode': '4815-123',
106-
'city': 'Madeira',
107-
'country': 'PT',
108-
'phone': '253444802010',
109-
'fax': '012356 789039',
110-
'mobile': '012356 789039'
111-
}
89+
"currency": "USD",
90+
"default_UK_warehouse": "iforce",
91+
"default_incoterm": "EXW",
92+
"freight_forwarder": "flexport",
93+
"name": "John Doe",
94+
"payment_term": "30% deposit, 70% balance",
95+
"reference": "42551456-a1b3-49bd-beed-b168d9a5ac83",
96+
"website": "http://megasofas.example.com",
97+
"main_contact": {
98+
"name": "Almeida & Filhos - Example, S.A.",
99+
"email": "[email protected]",
100+
"street": "Senhora Test D'Ajuda, 432",
101+
"street2": "Moreira de Conegos",
102+
"postcode": "4815-123",
103+
"city": "Madeira",
104+
"country": "PT",
105+
"phone": "253444802010",
106+
"fax": "012356 789039",
107+
"mobile": "012356 789039",
108+
},
112109
}
113110
testdir.makepyfile(
114111
f"""
115112
def test_two():
116113
assert {one!r} == {two!r}
117114
"""
118115
)
119-
output = testdir.runpytest('-vv', '--color=yes').stdout.str()
116+
output = testdir.runpytest("-vv", "--color=yes").stdout.str()
120117
expected_l = f"'default_UK_warehouse': '{YELLOW_ON}x{COLOR_OFF}force'"
121118
expected_r = f"'default_UK_warehouse': '{YELLOW_ON}i{COLOR_OFF}force'"
122119
expected_missing = f"{GREEN_ON} 'freight_forwarder': 'flexport',{COLOR_OFF}"
@@ -127,7 +124,7 @@ def test_two():
127124

128125
def test_only_works_for_equals(testdir):
129126
testdir.makepyfile(
130-
f"""
127+
"""
131128
def test_in():
132129
assert 1 in [2, 3, 4]
133130
@@ -146,29 +143,31 @@ def _assert_line_in_ignoring_whitespace(expected, block):
146143
for line in block.splitlines():
147144
if all(part in line for part in parts):
148145
return True
149-
assert False, f'could not find {expected} in:\n{block}'
146+
assert False, f"could not find {expected} in:\n{block}"
150147

151148

152149
def test_prepends_icdiff_output_lines_with_color_off(testdir):
153-
one = ['hello', 'hello']
154-
two = ['bello', 'hella']
150+
one = ["hello", "hello"]
151+
two = ["bello", "hella"]
155152
testdir.makepyfile(
156153
f"""
157154
def test_thing():
158155
assert {one!r} == {two!r}
159156
"""
160157
)
161-
output = testdir.runpytest('--color=yes').stdout.str()
162-
expected = list(icdiff.ConsoleDiff().make_table(
163-
pformat(one, width=1).splitlines(),
164-
pformat(two, width=1).splitlines(),
165-
))
166-
print('\n'.join(repr(l) for l in output.splitlines()))
158+
output = testdir.runpytest("--color=yes").stdout.str()
159+
expected = list(
160+
icdiff.ConsoleDiff().make_table(
161+
pformat(one, width=1).splitlines(),
162+
pformat(two, width=1).splitlines(),
163+
)
164+
)
165+
print("\n".join(repr(l) for l in output.splitlines()))
167166
_assert_line_in_ignoring_whitespace(expected[0], output)
168167

169168

170169
def strip_color_codes(s):
171-
return re.sub(r'\x1b\[[0-9;]*m', '', s)
170+
return re.sub(r"\x1b\[[0-9;]*m", "", s)
172171

173172

174173
def test_avoids_single_line_diffs(testdir):
@@ -180,7 +179,7 @@ def test_one():
180179
assert {one!r} == {two!r}
181180
"""
182181
)
183-
output = testdir.runpytest('-vv').stdout.str()
182+
output = testdir.runpytest("-vv").stdout.str()
184183
print(repr(output))
185184
assert "1: '1', 1: '1'," in strip_color_codes(output)
186185

@@ -193,22 +192,24 @@ def test_a():
193192
"""
194193
)
195194
output = testdir.runpytest().stdout.str()
196-
drilldown_expression = 'where 3 = len([1, 2, 3])'
195+
drilldown_expression = "where 3 = len([1, 2, 3])"
197196
assert drilldown_expression in output
198197

199198

200199
def test_long_lines_in_comparators_are_wrapped_sensibly_multiline(testdir):
201-
left = {1: "hello " * 20, 2: 'two'}
202-
right = {1: "hella " * 20, 2: 'two'}
200+
left = {1: "hello " * 20, 2: "two"}
201+
right = {1: "hella " * 20, 2: "two"}
203202
testdir.makepyfile(
204203
f"""
205204
def test_one():
206205
assert {left!r} == {right!r}
207206
"""
208207
)
209-
output = testdir.runpytest('-vv', '--color=yes').stdout.str()
210-
comparison_line = next(l for l in output.splitlines() if '1:' in l and "assert" not in l)
211-
assert comparison_line.count('hell') < 13
208+
output = testdir.runpytest("-vv", "--color=yes").stdout.str()
209+
comparison_line = next(
210+
l for l in output.splitlines() if "1:" in l and "assert" not in l
211+
)
212+
assert comparison_line.count("hell") < 13
212213

213214

214215
def test_long_lines_in_comparators_are_wrapped_sensibly_singleline(testdir):
@@ -220,12 +221,11 @@ def test_one():
220221
assert {left!r} == {right!r}
221222
"""
222223
)
223-
output = testdir.runpytest('-vv', '--color=yes').stdout.str()
224+
output = testdir.runpytest("-vv", "--color=yes").stdout.str()
224225
comparison_line = next(
225-
l for l in output.splitlines()
226-
if "hell" in l and "assert" not in l
226+
l for l in output.splitlines() if "hell" in l and "assert" not in l
227227
)
228-
assert comparison_line.count('hell') < 15
228+
assert comparison_line.count("hell") < 15
229229

230230

231231
def test_columns_are_calculated_outside_hook(testdir):
@@ -246,51 +246,51 @@ def test_one():
246246
assert {left!r} == {right!r}
247247
"""
248248
)
249-
testdir.monkeypatch.setenv('COLUMNS', '50')
249+
testdir.monkeypatch.setenv("COLUMNS", "50")
250250
# testdir._method = 'subprocess'
251251
output = testdir.runpytest(
252-
'-vv', '--color=yes',
252+
"-vv",
253+
"--color=yes",
253254
).stdout.str()
254255
comparison_line = next(
255-
l for l in output.splitlines()
256-
if 'hell' in l and "assert" not in l
256+
l for l in output.splitlines() if "hell" in l and "assert" not in l
257257
)
258-
assert comparison_line.count('hell') > 5
258+
assert comparison_line.count("hell") > 5
259259

260260

261261
def test_small_numbers_are_specialcased(testdir):
262262
testdir.makepyfile(
263-
f"""
263+
"""
264264
def test_one():
265265
assert 404 == 400
266266
"""
267267
)
268-
output = testdir.runpytest('-vv', '--color=yes').stdout.str()
268+
output = testdir.runpytest("-vv", "--color=yes").stdout.str()
269269
assert "assert 404 == 400" in output
270270
assert "E assert 404 == 400" in output
271271

272272

273273
def test_larger_numbers_are_sane(testdir):
274274
testdir.makepyfile(
275-
f"""
275+
"""
276276
def test_one():
277277
assert 123456 == 1234567
278278
"""
279279
)
280-
output = testdir.runpytest('-vv', '--color=yes').stdout.str()
280+
output = testdir.runpytest("-vv", "--color=yes").stdout.str()
281281
assert f"123456 123456{GREEN_ON}7" in output
282282

283283

284284
def test_really_long_diffs_use_context_mode(testdir):
285285
testdir.makepyfile(
286-
f"""
286+
"""
287287
def test_one():
288288
one = list(range(100))
289289
two = list(range(20)) + ["X"] + list(range(20, 50)) + ["Y"] + list(range(53, 100))
290290
assert one == two
291291
"""
292292
)
293-
output = testdir.runpytest('-vv', '--color=yes', '-r=no').stdout.str()
293+
output = testdir.runpytest("-vv", "--color=yes", "-r=no").stdout.str()
294294
assert len(output.splitlines()) < 50
295295
assert "---" in output # context split marker
296296

0 commit comments

Comments
 (0)