Skip to content

Commit

Permalink
feat(amber): expose serialize_custom_iterable method of AmberDataSeri…
Browse files Browse the repository at this point in the history
…alizer (#788)
  • Loading branch information
noahnu authored Aug 16, 2023
1 parent f4bc845 commit d210cf1
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/syrupy/extensions/amber/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ def serialize_iterable(
open_paren, close_paren = ("[", "]")

values = list(data)
return cls.__serialize_iterable(
return cls.serialize_custom_iterable(
data=data,
resolve_entries=(range(len(values)), item_getter, None),
open_paren=open_paren,
Expand All @@ -296,7 +296,7 @@ def serialize_iterable(

@classmethod
def serialize_set(cls, data: Set["SerializableData"], **kwargs: Any) -> str:
return cls.__serialize_iterable(
return cls.serialize_custom_iterable(
data=data,
resolve_entries=(cls.sort(data), lambda _, p: p, None),
open_paren="{",
Expand All @@ -306,7 +306,7 @@ def serialize_set(cls, data: Set["SerializableData"], **kwargs: Any) -> str:

@classmethod
def serialize_namedtuple(cls, data: NamedTuple, **kwargs: Any) -> str:
return cls.__serialize_iterable(
return cls.serialize_custom_iterable(
data=data,
resolve_entries=(cls.sort(data._fields), attr_getter, None),
separator="=",
Expand All @@ -321,7 +321,7 @@ def serialize_dict(
data.keys() if isinstance(data, (OrderedDict,)) else cls.sort(data.keys())
)

return cls.__serialize_iterable(
return cls.serialize_custom_iterable(
data=data,
resolve_entries=(keys, item_getter, None),
open_paren="{",
Expand All @@ -336,7 +336,7 @@ def serialize_unknown(cls, data: Any, *, depth: int = 0, **kwargs: Any) -> str:
if data.__class__.__repr__ != object.__repr__:
return cls.__serialize_plain(data=data, depth=depth)

return cls.__serialize_iterable(
return cls.serialize_custom_iterable(
data=data,
resolve_entries=(
(name for name in cls.sort(dir(data)) if not name.startswith("_")),
Expand Down Expand Up @@ -379,7 +379,7 @@ def __serialize_plain(
return cls.with_indent(repr(data), depth)

@classmethod
def __serialize_iterable(
def serialize_custom_iterable(
cls,
*,
data: "SerializableData",
Expand All @@ -393,6 +393,9 @@ def __serialize_iterable(
serialize_key: bool = False,
**kwargs: Any,
) -> str:
"""
Utility to serialize a custom iterable.
"""
kwargs["depth"] = depth + 1

keys, get_value, include_value = resolve_entries
Expand Down

0 comments on commit d210cf1

Please sign in to comment.