Replies: 4 comments 12 replies
-
|
Matcher which (ab)use Matcher which use methods like Do you have a special library in mind which should be supported by inline-snapshot? |
Beta Was this translation helpful? Give feedback.
-
|
Another use case I found for #329: from inline_snapshot import snapshot
from pathlib import Path, PosixPath
def test_path():
assert Path() == snapshot(PosixPath("."))
assert PosixPath() == snapshot(PosixPath(".")) |
Beta Was this translation helpful? Give feedback.
-
|
I played a bit more with the customize branch at work this week and a few things I noticed: Didn't have much luck with [project.entry-points.inline-snapshot]
my_plugin = "mymodule.InlineSnapshotSomethingPlugin"But this was working fine: [project.entry-points.inline-snapshot]
my_plugin = "mymodule"I think you might have changed the code since then. I guess that because these aren't pytest plugins we can't count on -p no:my_plugin and other related options to work I ran into trouble trying to use I guess this is the reason why there isn't a At some point I got it wrong and I returned something equivalent to builder.create_list([{...}, {...}])when I meant builder.create_list([builder.create_dict({...}), builder.create_dict({...})])The UsageError assertion in |
Beta Was this translation helpful? Give feedback.
-
|
Another fun one is trying to use create_code with the 3.14 template strings. They don't implement from string.templatelib import Template, Interpolation
from inline_snapshot.plugin import Builder, customize
from typing import Literal
def convert(value: object, conversion: Literal["a", "r", "s"] | None) -> object:
if conversion == "a":
return ascii(value)
elif conversion == "r":
return repr(value)
elif conversion == "s":
return str(value)
return value
def f(template: Template) -> str:
parts = []
for item in template:
match item:
case str() as s:
parts.append(s)
case Interpolation(value, _, conversion, format_spec):
value = convert(value, conversion)
value = format(value, format_spec)
parts.append(value)
return "".join(parts)
class InlineSnapshotPlugin:
@customize
def tstr_handler(self, value, builder: Builder):
if not isinstance(value, str):
return
return builder.create_call(f, [builder.create_code(f't"{value}"')])from .conftest import f
from inline_snapshot import snapshot
def test_template():
assert "c" == snapshot(f(t"b"))By modifying inline-snapshot, it almost works: Almost because asttokens does not return quite the right range for the template string. |
Beta Was this translation helpful? Give feedback.





Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I think it would be interesting to have a way to turn a matcher type into a inline-snapshot enabled object.
The simplest example of a matcher type I can think of:
Some notes/considerations:
__eq__, others implements a method likematchesin the above exampleIsNegativecould be turned intoIsPositive.wdyt?
Beta Was this translation helpful? Give feedback.
All reactions