Skip to content

Commit

Permalink
Run black
Browse files Browse the repository at this point in the history
  • Loading branch information
hjwp committed Nov 8, 2023
1 parent e817937 commit 3bb6f9b
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 85 deletions.
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pytest_plugins = 'pytester'
pytest_plugins = "pytester"
168 changes: 84 additions & 84 deletions tests/test_pytest_icdiff.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import icdiff
from unittest import mock
import pytest
import re
from pprintpp import pformat

YELLOW_ON = '\x1b[1;33m'
COLOR_OFF = '\x1b[m'
GREEN_ON = '\x1b[1;32m'
ANSI_ESCAPE_RE = re.compile(r'(\x9B|\x1B\[)[0-?]*[ -/]*[@-~]')

YELLOW_ON = "\x1b[1;33m"
COLOR_OFF = "\x1b[m"
GREEN_ON = "\x1b[1;32m"
ANSI_ESCAPE_RE = re.compile(r"(\x9B|\x1B\[)[0-?]*[ -/]*[@-~]")


def test_short_dict(testdir):
Expand All @@ -19,15 +16,15 @@ def test_short_dict(testdir):
two = {
1: "the number one",
2: "the number three",
6: [1, 2, 3]
6: [1, 2, 3],
}
testdir.makepyfile(
f"""
def test_one():
assert {one!r} == {two!r}
"""
)
output = testdir.runpytest('-vv').stdout.str()
output = testdir.runpytest("-vv").stdout.str()
print(repr(output))
two_left = "'the number two'"
two_right = "'the number three'"
Expand All @@ -45,7 +42,7 @@ def test_short_dict_with_colorization(testdir):
two = {
1: "the number one",
2: "the number three",
6: [1, 2, 3]
6: [1, 2, 3],
}
testdir.makepyfile(
f"""
Expand All @@ -54,8 +51,8 @@ def test_one():
"""
)
# Force colorization in py TerminalWriter
testdir.monkeypatch.setenv('PY_COLORS', '1')
output = testdir.runpytest('-vv').stdout.str()
testdir.monkeypatch.setenv("PY_COLORS", "1")
output = testdir.runpytest("-vv").stdout.str()
print(repr(output))
two_left = f"'the number t{YELLOW_ON}wo{COLOR_OFF}'"
two_right = f"'the number t{YELLOW_ON}hree{COLOR_OFF}'"
Expand All @@ -67,55 +64,55 @@ def test_one():

def test_long_dict(testdir):
one = {
'currency': 'USD',
'default_UK_warehouse': 'xforce',
'default_incoterm': 'EXW',
'name': 'John Doe',
'payment_term': '30% deposit, 70% balance',
'reference': '42551456-a1b3-49bd-beed-b168d9a5ac83',
'website': 'http://megasofas.example.com',
'main_contact': {
'city': 'Madeira',
'country': 'PT',
'email': '[email protected]',
'fax': '012356 789039',
'mobile': '012356 789039',
'name': 'Almeida & Filhos - Example, S.A.',
'phone': '253444802010',
'postcode': '4815-123',
'street': "Senhora Test D'Ajuda, 432",
'street2': 'Moreira de Conegos'
"currency": "USD",
"default_UK_warehouse": "xforce",
"default_incoterm": "EXW",
"name": "John Doe",
"payment_term": "30% deposit, 70% balance",
"reference": "42551456-a1b3-49bd-beed-b168d9a5ac83",
"website": "http://megasofas.example.com",
"main_contact": {
"city": "Madeira",
"country": "PT",
"email": "[email protected]",
"fax": "012356 789039",
"mobile": "012356 789039",
"name": "Almeida & Filhos - Example, S.A.",
"phone": "253444802010",
"postcode": "4815-123",
"street": "Senhora Test D'Ajuda, 432",
"street2": "Moreira de Conegos",
},
}
two = {
'currency': 'USD',
'default_UK_warehouse': 'iforce',
'default_incoterm': 'EXW',
'freight_forwarder': 'flexport',
'name': 'John Doe',
'payment_term': '30% deposit, 70% balance',
'reference': '42551456-a1b3-49bd-beed-b168d9a5ac83',
'website': 'http://megasofas.example.com',
'main_contact': {
'name': 'Almeida & Filhos - Example, S.A.',
'email': '[email protected]',
'street': "Senhora Test D'Ajuda, 432",
'street2': 'Moreira de Conegos',
'postcode': '4815-123',
'city': 'Madeira',
'country': 'PT',
'phone': '253444802010',
'fax': '012356 789039',
'mobile': '012356 789039'
}
"currency": "USD",
"default_UK_warehouse": "iforce",
"default_incoterm": "EXW",
"freight_forwarder": "flexport",
"name": "John Doe",
"payment_term": "30% deposit, 70% balance",
"reference": "42551456-a1b3-49bd-beed-b168d9a5ac83",
"website": "http://megasofas.example.com",
"main_contact": {
"name": "Almeida & Filhos - Example, S.A.",
"email": "[email protected]",
"street": "Senhora Test D'Ajuda, 432",
"street2": "Moreira de Conegos",
"postcode": "4815-123",
"city": "Madeira",
"country": "PT",
"phone": "253444802010",
"fax": "012356 789039",
"mobile": "012356 789039",
},
}
testdir.makepyfile(
f"""
def test_two():
assert {one!r} == {two!r}
"""
)
output = testdir.runpytest('-vv', '--color=yes').stdout.str()
output = testdir.runpytest("-vv", "--color=yes").stdout.str()
expected_l = f"'default_UK_warehouse': '{YELLOW_ON}x{COLOR_OFF}force'"
expected_r = f"'default_UK_warehouse': '{YELLOW_ON}i{COLOR_OFF}force'"
expected_missing = f"{GREEN_ON} 'freight_forwarder': 'flexport',{COLOR_OFF}"
Expand All @@ -126,7 +123,7 @@ def test_two():

def test_only_works_for_equals(testdir):
testdir.makepyfile(
f"""
"""
def test_in():
assert 1 in [2, 3, 4]
Expand All @@ -145,29 +142,31 @@ def _assert_line_in_ignoring_whitespace(expected, block):
for line in block.splitlines():
if all(part in line for part in parts):
return True
assert False, f'could not find {expected} in:\n{block}'
assert False, f"could not find {expected} in:\n{block}"


def test_prepends_icdiff_output_lines_with_color_off(testdir):
one = ['hello', 'hello']
two = ['bello', 'hella']
one = ["hello", "hello"]
two = ["bello", "hella"]
testdir.makepyfile(
f"""
def test_thing():
assert {one!r} == {two!r}
"""
)
output = testdir.runpytest('--color=yes').stdout.str()
expected = list(icdiff.ConsoleDiff().make_table(
pformat(one, width=1).splitlines(),
pformat(two, width=1).splitlines(),
))
print('\n'.join(repr(l) for l in output.splitlines()))
output = testdir.runpytest("--color=yes").stdout.str()
expected = list(
icdiff.ConsoleDiff().make_table(
pformat(one, width=1).splitlines(),
pformat(two, width=1).splitlines(),
)
)
print("\n".join(repr(l) for l in output.splitlines()))
_assert_line_in_ignoring_whitespace(expected[0], output)


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


def test_avoids_single_line_diffs(testdir):
Expand All @@ -179,7 +178,7 @@ def test_one():
assert {one!r} == {two!r}
"""
)
output = testdir.runpytest('-vv').stdout.str()
output = testdir.runpytest("-vv").stdout.str()
print(repr(output))
assert "1: '1', 1: '1'," in strip_color_codes(output)

Expand All @@ -192,22 +191,24 @@ def test_a():
"""
)
output = testdir.runpytest().stdout.str()
drilldown_expression = 'where 3 = len([1, 2, 3])'
drilldown_expression = "where 3 = len([1, 2, 3])"
assert drilldown_expression in output


def test_long_lines_in_comparators_are_wrapped_sensibly_multiline(testdir):
left = {1: "hello " * 20, 2: 'two'}
right = {1: "hella " * 20, 2: 'two'}
left = {1: "hello " * 20, 2: "two"}
right = {1: "hella " * 20, 2: "two"}
testdir.makepyfile(
f"""
def test_one():
assert {left!r} == {right!r}
"""
)
output = testdir.runpytest('-vv', '--color=yes').stdout.str()
comparison_line = next(l for l in output.splitlines() if '1:' in l and "assert" not in l)
assert comparison_line.count('hell') < 13
output = testdir.runpytest("-vv", "--color=yes").stdout.str()
comparison_line = next(
l for l in output.splitlines() if "1:" in l and "assert" not in l
)
assert comparison_line.count("hell") < 13


def test_long_lines_in_comparators_are_wrapped_sensibly_singleline(testdir):
Expand All @@ -219,12 +220,11 @@ def test_one():
assert {left!r} == {right!r}
"""
)
output = testdir.runpytest('-vv', '--color=yes').stdout.str()
output = testdir.runpytest("-vv", "--color=yes").stdout.str()
comparison_line = next(
l for l in output.splitlines()
if "hell" in l and "assert" not in l
l for l in output.splitlines() if "hell" in l and "assert" not in l
)
assert comparison_line.count('hell') < 15
assert comparison_line.count("hell") < 15


def test_columns_are_calculated_outside_hook(testdir):
Expand All @@ -245,50 +245,50 @@ def test_one():
assert {left!r} == {right!r}
"""
)
testdir.monkeypatch.setenv('COLUMNS', '50')
testdir.monkeypatch.setenv("COLUMNS", "50")
# testdir._method = 'subprocess'
output = testdir.runpytest(
'-vv', '--color=yes',
"-vv",
"--color=yes",
).stdout.str()
comparison_line = next(
l for l in output.splitlines()
if 'hell' in l and "assert" not in l
l for l in output.splitlines() if "hell" in l and "assert" not in l
)
assert comparison_line.count('hell') > 5
assert comparison_line.count("hell") > 5


def test_small_numbers_are_specialcased(testdir):
testdir.makepyfile(
f"""
"""
def test_one():
assert 404 == 400
"""
)
output = testdir.runpytest('-vv', '--color=yes').stdout.str()
output = testdir.runpytest("-vv", "--color=yes").stdout.str()
assert "assert 404 == 400" in output
assert "E assert 404 == 400" in output


def test_larger_numbers_are_sane(testdir):
testdir.makepyfile(
f"""
"""
def test_one():
assert 123456 == 1234567
"""
)
output = testdir.runpytest('-vv', '--color=yes').stdout.str()
output = testdir.runpytest("-vv", "--color=yes").stdout.str()
assert f"123456 123456{GREEN_ON}7" in output


def test_really_long_diffs_use_context_mode(testdir):
testdir.makepyfile(
f"""
"""
def test_one():
one = list(range(100))
two = list(range(20)) + ["X"] + list(range(20, 50)) + ["Y"] + list(range(53, 100))
assert one == two
"""
)
output = testdir.runpytest('-vv', '--color=yes', '-r=no').stdout.str()
output = testdir.runpytest("-vv", "--color=yes", "-r=no").stdout.str()
assert len(output.splitlines()) < 50
assert "---" in output # context split marker

0 comments on commit 3bb6f9b

Please sign in to comment.