You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
inline-snapshot should ideally create snapshots that do not need to be modified by the developer. However, there are cases where the developer may want to use specific looking snapshots.
declare_abbreviation is intended to solve this problem by allowing the developer to specify what the snapshots should look like, and allow inline-snapshot to generate the correct code in the first place.
The idea is as follows:
inline-snapshot checks each snapshot value and inner value (dict/list/... child) to see if it can be abbreviated.
The abbreviation with the shortest representation is used if there are several ways to abbreviate a snapshot.
Below are some examples of what this could look like:
frominline_snapshotimportsnapshot, declare_abbreviation, Abbreviationfromdirty_equalsimportIsNowfromdatetimeimportdatetime, timezone@declare_abbreviationdef_(value, context):
ifvalue==IsNow(tz=timezone.utc):
returnAbbreviation(IsNow, tz=timezone.utc)
defrepeated(num, v):
return [v] *num@declare_abbreviationdef_(value, context):
ifvalue== [value[0]] *len(value):
returnAbbreviation(repeated, len(value), value[0])
deftest():
# the snapshots which will be generated by inline-snapshotassert [0,0,0,0,0] ==snapshot(repeated(5, 0))
assertdatetime.now() ==snapshot(IsNow(tz=timezone.utc))
context should give the developer some information about the context of the value (what the parent object is or what the key is if the value is inside a dictionary)
These abbreviations would be declared globally (in conftest.py).
This is currently just an idea and feedback is very welcome.
The text was updated successfully, but these errors were encountered:
inline-snapshot should ideally create snapshots that do not need to be modified by the developer. However, there are cases where the developer may want to use specific looking snapshots.
declare_abbreviation
is intended to solve this problem by allowing the developer to specify what the snapshots should look like, and allow inline-snapshot to generate the correct code in the first place.The idea is as follows:
Below are some examples of what this could look like:
context
should give the developer some information about the context of the value (what the parent object is or what the key is if the value is inside a dictionary)These abbreviations would be declared globally (in
conftest.py
).This is currently just an idea and feedback is very welcome.
The text was updated successfully, but these errors were encountered: