Skip to content

Commit ec59cc5

Browse files
committed
Add command line options from icdiff
--cols, --show-all-spaces, --highlight, --line-numbers, --tabsize, --truncate, --strip-trailing-cr
1 parent 277b8d0 commit ec59cc5

File tree

1 file changed

+56
-2
lines changed

1 file changed

+56
-2
lines changed

pytest_icdiff.py

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from pprintpp import pformat
44
import icdiff
55

6-
COLS = shutil.get_terminal_size().columns
6+
AUTO_COLS = shutil.get_terminal_size().columns
77
MARGIN_L = 10
88
GUTTER = 2
99
MARGINS = MARGIN_L + GUTTER + 1
@@ -14,6 +14,50 @@
1414
# f.write('\n')
1515

1616

17+
def pytest_addoption(parser):
18+
parser.addoption(
19+
"--cols",
20+
action="store",
21+
default=None,
22+
help="pytest-icdiff: specify the width of the screen, in case autodetection fails you",
23+
)
24+
parser.addoption(
25+
"--show-all-spaces",
26+
default=False,
27+
action="store_true",
28+
help="pytest-icdiff: color all non-matching whitespace including that which is not needed for drawing the eye to changes. Slow, ugly, displays all changes",
29+
)
30+
parser.addoption(
31+
"--highlight",
32+
default=False,
33+
action="store_true",
34+
help="pytest-icdiff: color by changing the background color instead of the foreground color. Very fast, ugly, displays all changes",
35+
)
36+
parser.addoption(
37+
"--line-numbers",
38+
default=False,
39+
action="store_true",
40+
help="pytest-icdiff: generate output with line numbers. Not compatible with the 'exclude-lines' option.",
41+
)
42+
parser.addoption(
43+
"--tabsize",
44+
default=2,
45+
help="pytest-icdiff: tab stop spacing",
46+
)
47+
parser.addoption(
48+
"--truncate",
49+
default=False,
50+
action="store_true",
51+
help="pytest-icdiff: truncate long lines instead of wrapping them",
52+
)
53+
parser.addoption(
54+
"--strip-trailing-cr",
55+
default=False,
56+
action="store_true",
57+
help="pytest-icdiff: strip any trailing carriage return at the end of an input line",
58+
)
59+
60+
1761
def pytest_assertrepr_compare(config, op, left, right):
1862
if op != "==":
1963
return
@@ -24,7 +68,9 @@ def pytest_assertrepr_compare(config, op, left, right):
2468
except TypeError:
2569
pass
2670

71+
COLS = int(config.getoption("--cols") or AUTO_COLS)
2772
half_cols = COLS / 2 - MARGINS
73+
TABSIZE = int(config.getoption("--tabsize") or 2)
2874

2975
pretty_left = pformat(left, indent=2, width=half_cols).splitlines()
3076
pretty_right = pformat(right, indent=2, width=half_cols).splitlines()
@@ -40,7 +86,15 @@ def pytest_assertrepr_compare(config, op, left, right):
4086
pretty_left = pformat(left, indent=2, width=max_side).splitlines()
4187
pretty_right = pformat(right, indent=2, width=max_side).splitlines()
4288

43-
differ = icdiff.ConsoleDiff(cols=diff_cols, tabsize=2)
89+
differ = icdiff.ConsoleDiff(
90+
cols=diff_cols,
91+
show_all_spaces=config.getoption("--show-all-spaces"),
92+
highlight=config.getoption("--highlight"),
93+
line_numbers=config.getoption("--line-numbers"),
94+
tabsize=TABSIZE,
95+
truncate=config.getoption("--truncate"),
96+
strip_trailing_cr=config.getoption("--strip-trailing-cr"),
97+
)
4498

4599
if not config.get_terminal_writer().hasmarkup:
46100
# colorization is disabled in Pytest - either due to the terminal not

0 commit comments

Comments
 (0)