Skip to content

Commit

Permalink
fix: --inline-snapshot=create/fix/trim/update does not report other c…
Browse files Browse the repository at this point in the history
…ategories
  • Loading branch information
15r10nk committed Nov 6, 2024
1 parent 408c62d commit f91d4af
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 33 deletions.
5 changes: 4 additions & 1 deletion src/inline_snapshot/pytest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def pytest_addoption(parser):


categories = {"create", "update", "trim", "fix"}
flags = {}
flags = set()


def xdist_running(config):
Expand Down Expand Up @@ -279,6 +279,9 @@ def report(flag, message, message_n):
if not changes[flag]:
continue

if not {"review", "report", flag} & flags:
continue

console.rule(f"[yellow bold]{flag.capitalize()} snapshots")

with ChangeRecorder().activate() as cr:
Expand Down
14 changes: 0 additions & 14 deletions tests/test_external.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,6 @@ def test_something():

assert result.report == snapshot(
"""\
-------------------------------- Fix snapshots ---------------------------------
+-------------------------------- test_file.py --------------------------------+
| @@ -4,5 +4,5 @@ |
| |
| from inline_snapshot import external |
| |
| def test_something(): |
| - assert "hello" == snapshot(external("bbbbb*.txt")) |
| + assert "hello" == snapshot("hello") |
| assert 2 == snapshot(1+1) |
+------------------------------------------------------------------------------+
These changes are not applied.
Use --inline-snapshot=fix to apply them, or use the interactive mode with
--inline-snapshot=review
------------------------------- Update snapshots -------------------------------
+-------------------------------- test_file.py --------------------------------+
| @@ -5,4 +5,4 @@ |
Expand Down
82 changes: 67 additions & 15 deletions tests/test_pytest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,21 +236,6 @@ def test_a():
| assert 5 == snapshot(5) |
+------------------------------------------------------------------------------+
These changes will be applied, because you used --inline-snapshot=trim
------------------------------- Update snapshots -------------------------------
+-------------------------------- test_file.py --------------------------------+
| @@ -4,6 +4,6 @@ |
| |
| |
| |
| def test_a(): |
| - assert "5" == snapshot('''5''') |
| + assert "5" == snapshot("5") |
| assert 5 <= snapshot(5) |
| assert 5 == snapshot(5) |
+------------------------------------------------------------------------------+
These changes are not applied.
Use --inline-snapshot=update to apply them, or use the interactive mode with
--inline-snapshot=review
"""
)

Expand Down Expand Up @@ -283,6 +268,73 @@ def test_a():
)


def test_multiple_report(project):
project.setup(
"""\
def test_a():
assert "5" == snapshot('''5''')
assert 5 <= snapshot(8)
assert 5 == snapshot(4)
"""
)

result = project.run("--inline-snapshot=trim,report")

assert result.report == snapshot(
"""\
-------------------------------- Fix snapshots ---------------------------------
+-------------------------------- test_file.py --------------------------------+
| @@ -6,4 +6,4 @@ |
| |
| def test_a(): |
| assert "5" == snapshot('''5''') |
| assert 5 <= snapshot(8) |
| - assert 5 == snapshot(4) |
| + assert 5 == snapshot(5) |
+------------------------------------------------------------------------------+
These changes are not applied.
Use --inline-snapshot=fix to apply them, or use the interactive mode with
--inline-snapshot=review
-------------------------------- Trim snapshots --------------------------------
+-------------------------------- test_file.py --------------------------------+
| @@ -5,5 +5,5 @@ |
| |
| |
| def test_a(): |
| assert "5" == snapshot('''5''') |
| - assert 5 <= snapshot(8) |
| + assert 5 <= snapshot(5) |
| assert 5 == snapshot(4) |
+------------------------------------------------------------------------------+
These changes will be applied, because you used --inline-snapshot=trim
------------------------------- Update snapshots -------------------------------
+-------------------------------- test_file.py --------------------------------+
| @@ -4,6 +4,6 @@ |
| |
| |
| |
| def test_a(): |
| - assert "5" == snapshot('''5''') |
| + assert "5" == snapshot("5") |
| assert 5 <= snapshot(5) |
| assert 5 == snapshot(4) |
+------------------------------------------------------------------------------+
These changes are not applied.
Use --inline-snapshot=update to apply them, or use the interactive mode with
--inline-snapshot=review
"""
)

assert project.source == snapshot(
"""\
def test_a():
assert "5" == snapshot('''5''')
assert 5 <= snapshot(5)
assert 5 == snapshot(4)
"""
)


def test_black_config(project):
project.setup(
"""\
Expand Down
18 changes: 15 additions & 3 deletions tests/test_xdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,31 @@ def test_a():
"""
)

def filter_error_lines(result):
lines = result.stderr.lines
return [
line
for line in lines
if line
not in (
'No entry for terminal type "unknown";',
"using dumb terminal settings.",
)
]

result = project.run("-n=auto", "--inline-snapshot=disable")

assert result.report == snapshot("")

assert result.stderr.lines == snapshot([])
assert filter_error_lines(result) == snapshot([])

assert result.ret == 1

result = project.run("-n=auto", "--inline-snapshot=fix")

assert result.report == snapshot("")

assert result.stderr.lines == snapshot(
assert filter_error_lines(result) == snapshot(
["ERROR: --inline-snapshot=fix can not be combined with xdist", ""]
)

Expand All @@ -80,6 +92,6 @@ def test_a():
"INFO: inline-snapshot was disabled because you used xdist"
)

assert result.stderr.lines == snapshot([])
assert filter_error_lines(result) == snapshot([])

assert result.ret == 0

0 comments on commit f91d4af

Please sign in to comment.