From 2a3797129e0205499729b336ddbd1b878fe47e0b Mon Sep 17 00:00:00 2001 From: Frank Hoffmann <15r10nk-git@polarbit.de> Date: Sun, 22 Sep 2024 21:25:00 +0200 Subject: [PATCH] test: test for #116 --- tests/test_inline_snapshot.py | 52 +++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/tests/test_inline_snapshot.py b/tests/test_inline_snapshot.py index 3f2a09f6..ef7ffbde 100644 --- a/tests/test_inline_snapshot.py +++ b/tests/test_inline_snapshot.py @@ -1176,3 +1176,55 @@ def test_starred_warns_dict(): assert {1:3} == snapshot({**{1:2}}) """ ).run_inline(["--inline-snapshot=fix"]) + + +def test_now_like_dirty_equals(): + # test for cases like https://github.com/15r10nk/inline-snapshot/issues/116 + + Example( + """ +from dirty_equals import DirtyEquals +from inline_snapshot import snapshot + + +def test_time(): + + now = 5 + + class Now(DirtyEquals): + def equals(self, other): + return other == now + + assert now == snapshot(Now()) + + now = 6 + + assert 5 == snapshot(Now()) +""" + ).run_inline( + ["--inline-snapshot=fix"], + changed_files=snapshot( + { + "test_something.py": """\ + +from dirty_equals import DirtyEquals +from inline_snapshot import snapshot + + +def test_time(): + + now = 5 + + class Now(DirtyEquals): + def equals(self, other): + return other == now + + assert now == snapshot(Now()) + + now = 6 + + assert 5 == snapshot(5) +""" + } + ), + )