-
-
Notifications
You must be signed in to change notification settings - Fork 17
Open
Description
Problem:
snapshot()
can not only be used in assertions but also used as argument for functions or methods (everything callable).
One example:
from inline_snapshot import snapshot
def check_string(string, length, is_upper):
assert len(string) == length
assert string.isupper() == is_upper
def test_string_len():
check_string("abc", length=snapshot(3),is_upper=snapshot(False))
The problem is that you have to use the following code to create the snapshots
def test_string_len():
check_string("abc", length=snapshot(),is_upper=snapshot())
Idea:
I want to move the snapshot inside the function and call it snapshot_arg
which will then manage the value of the argument.
from inline_snapshot import snapshot_arg
def check_string(string, length, is_upper):
assert len(string) == snapshot_arg(length)
assert string.isupper() == snapshot_arg(is_upper)
def test_string_len():
check_string("abc")
inline-snapshot will then create the arguments without the use of snapshot().
def test_string_len():
check_string("abc", length=3,is_upper=False)
inline-snapshot will use the default arguments to decide if a argument has to be created.
There are some rules to follow.
snapshot_arg(arg)
can only be used for arguments.- inline-snapshot will "manage" the argument of the function and try to change the code if it has to.
This can become a problem if you try to use it for existing code. There are maybe ways to make smarter decision here, but not in the first iteration.
possible use cases:
- dirty-equal like expressions like
IsJson()
in Allow fixing whole snapshot regardless of managed/unmanaged values #196 - maybe it is possible to integrate it directly into dirty-equal
- integration into python unittest
self.assertEqual(value, ...)
(... is already supported https://github.com/15r10nk/inline-snapshot/releases/tag/0.20.0) - pandas.assert_frame_equal https://github.com/15r10nk/inline-snapshot-pandas#readme
feedback is very welcome.
Metadata
Metadata
Assignees
Labels
No labels