Skip to content

Commit

Permalink
test: added missing test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
15r10nk committed May 29, 2024
1 parent f04acde commit a57a96f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
7 changes: 7 additions & 0 deletions inline_snapshot/_code_repr.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ def __repr__(self):
return f"HasRepr({self._type.__qualname__}, {self._str_repr!r})"

def __eq__(self, other):
if isinstance(other, HasRepr):
if other._type is not self._type:
return False
else:
if type(other) is not self._type:
return False

other_repr = code_repr(other)
return other_repr == self._str_repr or other_repr == repr(self)

Expand Down
12 changes: 0 additions & 12 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import ast
import os
import platform
import re
Expand All @@ -19,7 +18,6 @@
import inline_snapshot._external
from .utils import snapshot_env
from inline_snapshot import _inline_snapshot
from inline_snapshot import register_repr
from inline_snapshot._format import format_code
from inline_snapshot._inline_snapshot import Flags
from inline_snapshot._rewrite_code import ChangeRecorder
Expand All @@ -32,16 +30,6 @@
black.files.find_project_root = black.files.find_project_root.__wrapped__ # type: ignore


@register_repr
def _(v: executing.Source):
return f"<source {Path(v.filename).name}>"


@register_repr
def _(v: ast.AST):
return repr(ast.dump(v))


@pytest.fixture()
def check_update(source):
def w(source_code, *, flags="", reported_flags=None, number=1):
Expand Down
10 changes: 9 additions & 1 deletion tests/test_code_repr.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .example import Example
from inline_snapshot import HasRepr
from inline_snapshot import snapshot


Expand Down Expand Up @@ -34,7 +35,7 @@ class color(Enum):
)


def test_hasrepr():
def test_snapshot_generates_hasrepr():

Example(
"""\
Expand Down Expand Up @@ -76,6 +77,13 @@ def test_thing():
)


def test_hasrepr_type():
assert 5 == HasRepr(int, "5")
assert not "a" == HasRepr(int, "5")
assert not HasRepr(float, "nan") == HasRepr(str, "nan")
assert not HasRepr(str, "a") == HasRepr(str, "b")


def test_enum_in_dataclass(check_update):

assert (
Expand Down

0 comments on commit a57a96f

Please sign in to comment.