From 3d296e1e524e90a6f2d22f550a6e7847d4805c92 Mon Sep 17 00:00:00 2001 From: Noah Date: Wed, 25 Jan 2023 19:30:17 -0500 Subject: [PATCH] refactor: simplify data serializer for ambr (#676) * refactor: simplify data serializer for ambr * feat: introduce concept of a tainted snapshot BREAKING CHANGE: Serializers may now throw a TaintedSnapshotError which will tell the user to regenerate the snapshot even if the underlying data has not changed. This is to support rolling out more subtle changes to the serializers, such as the introduction of serializer metadata. BREAKING CHANGE: Renamed DataSerializer to AmberDataSerializer. --- src/syrupy/assertion.py | 96 +++++++++----- src/syrupy/data.py | 5 + src/syrupy/exceptions.py | 15 +++ src/syrupy/extensions/amber/__init__.py | 23 ++-- src/syrupy/extensions/amber/serializer.py | 119 +++++++++++++----- src/syrupy/matchers.py | 6 +- .../test_custom_snapshot_directory.ambr | 1 + .../test_custom_object_repr.ambr | 1 + .../test_custom_snapshot_name.ambr | 1 + .../test_custom_snapshot_name_suffix.ambr | 1 + tests/syrupy/__snapshots__/test_doctest.ambr | 1 + .../extensions/__snapshots__/test_base.ambr | 1 + .../__snapshots__/test_amber_filters.ambr | 1 + .../__snapshots__/test_amber_matchers.ambr | 1 + .../__snapshots__/test_amber_serializer.ambr | 1 + .../test_amber_snapshot_diff.ambr | 1 + .../extensions/amber/test_amber_serializer.py | 10 +- .../image/__snapshots__/test_image_png.ambr | 1 + .../image/__snapshots__/test_image_svg.ambr | 1 + .../extensions/json/test_json_serializer.py | 10 +- 20 files changed, 209 insertions(+), 87 deletions(-) diff --git a/src/syrupy/assertion.py b/src/syrupy/assertion.py index c32fa695..35c301dd 100644 --- a/src/syrupy/assertion.py +++ b/src/syrupy/assertion.py @@ -12,10 +12,14 @@ Dict, List, Optional, + Tuple, Type, ) -from .exceptions import SnapshotDoesNotExist +from .exceptions import ( + SnapshotDoesNotExist, + TaintedSnapshotError, +) from .extensions.amber.serializer import Repr if TYPE_CHECKING: @@ -125,13 +129,15 @@ def __repr(self) -> "SerializableData": SnapshotAssertionRepr = namedtuple( # type: ignore "SnapshotAssertion", ["name", "num_executions"] ) - assertion_result = self.executions.get( - (self._custom_index and self._execution_name_index.get(self._custom_index)) - or self.num_executions - 1 - ) + execution_index = ( + self._custom_index and self._execution_name_index.get(self._custom_index) + ) or self.num_executions - 1 + assertion_result = self.executions.get(execution_index) return ( Repr(str(assertion_result.final_data)) - if assertion_result + if execution_index in self.executions + and assertion_result + and assertion_result.final_data is not None else SnapshotAssertionRepr( name=self.name, num_executions=self.num_executions, @@ -179,15 +185,23 @@ def _serialize(self, data: "SerializableData") -> "SerializedData": def get_assert_diff(self) -> List[str]: assertion_result = self._execution_results[self.num_executions - 1] if assertion_result.exception: - lines = [ - line - for lines in traceback.format_exception( - assertion_result.exception.__class__, - assertion_result.exception, - assertion_result.exception.__traceback__, - ) - for line in lines.splitlines() - ] + if isinstance(assertion_result.exception, (TaintedSnapshotError,)): + lines = [ + gettext( + "This snapshot needs to be regenerated. " + "This is typically due to a major Syrupy update." + ) + ] + else: + lines = [ + line + for lines in traceback.format_exception( + assertion_result.exception.__class__, + assertion_result.exception, + assertion_result.exception.__traceback__, + ) + for line in lines.splitlines() + ] # Rotate to place exception with message at first line return lines[-1:] + lines[:-1] snapshot_data = assertion_result.recalled_data @@ -232,7 +246,7 @@ def __call__( return self def __repr__(self) -> str: - return str(self._serialize(self.__repr)) + return str(self.__repr) def __eq__(self, other: "SerializableData") -> bool: return self._assert(other) @@ -250,29 +264,36 @@ def _assert(self, data: "SerializableData") -> bool: assertion_success = False assertion_exception = None try: - snapshot_data = self._recall_data(index=self.index) + snapshot_data, tainted = self._recall_data(index=self.index) serialized_data = self._serialize(data) snapshot_diff = getattr(self, "_snapshot_diff", None) if snapshot_diff is not None: - snapshot_data_diff = self._recall_data(index=snapshot_diff) + snapshot_data_diff, _ = self._recall_data(index=snapshot_diff) if snapshot_data_diff is None: raise SnapshotDoesNotExist() serialized_data = self.extension.diff_snapshots( serialized_data=serialized_data, snapshot_data=snapshot_data_diff, ) - matches = snapshot_data is not None and self.extension.matches( - serialized_data=serialized_data, snapshot_data=snapshot_data + matches = ( + not tainted + and snapshot_data is not None + and self.extension.matches( + serialized_data=serialized_data, snapshot_data=snapshot_data + ) ) assertion_success = matches - if not matches and self.update_snapshots: - self.session.queue_snapshot_write( - extension=self.extension, - test_location=self.test_location, - data=serialized_data, - index=self.index, - ) - assertion_success = True + if not matches: + if self.update_snapshots: + self.session.queue_snapshot_write( + extension=self.extension, + test_location=self.test_location, + data=serialized_data, + index=self.index, + ) + assertion_success = True + elif tainted: + raise TaintedSnapshotError return assertion_success except Exception as e: assertion_exception = e @@ -301,12 +322,19 @@ def _post_assert(self) -> None: while self._post_assert_actions: self._post_assert_actions.pop()() - def _recall_data(self, index: "SnapshotIndex") -> Optional["SerializableData"]: + def _recall_data( + self, index: "SnapshotIndex" + ) -> Tuple[Optional["SerializableData"], bool]: try: - return self.extension.read_snapshot( - test_location=self.test_location, - index=index, - session_id=str(id(self.session)), + return ( + self.extension.read_snapshot( + test_location=self.test_location, + index=index, + session_id=str(id(self.session)), + ), + False, ) except SnapshotDoesNotExist: - return None + return None, False + except TaintedSnapshotError as e: + return e.snapshot_data, True diff --git a/src/syrupy/data.py b/src/syrupy/data.py index b74f2141..3d710f97 100644 --- a/src/syrupy/data.py +++ b/src/syrupy/data.py @@ -23,6 +23,8 @@ class Snapshot: name: str data: Optional["SerializedData"] = None + # A tainted snapshot needs to be regenerated + tainted: Optional[bool] = field(default=None) @dataclass(frozen=True) @@ -42,6 +44,9 @@ class SnapshotCollection: location: str _snapshots: Dict[str, "Snapshot"] = field(default_factory=dict) + # A tainted collection needs to be regenerated + tainted: Optional[bool] = field(default=None) + @property def has_snapshots(self) -> bool: return bool(self._snapshots) diff --git a/src/syrupy/exceptions.py b/src/syrupy/exceptions.py index bac4a744..e63dc38e 100644 --- a/src/syrupy/exceptions.py +++ b/src/syrupy/exceptions.py @@ -1,6 +1,21 @@ +from typing import Optional + +from syrupy.types import SerializedData + + class SnapshotDoesNotExist(Exception): """Snapshot does not exist""" class FailedToLoadModuleMember(Exception): """Failed to load specific member in a module""" + + +class TaintedSnapshotError(Exception): + """The snapshot needs to be regenerated.""" + + snapshot_data: Optional["SerializedData"] + + def __init__(self, snapshot_data: Optional["SerializedData"] = None) -> None: + super().__init__() + self.snapshot_data = snapshot_data diff --git a/src/syrupy/extensions/amber/__init__.py b/src/syrupy/extensions/amber/__init__.py index f6ca5773..4b54ee2d 100644 --- a/src/syrupy/extensions/amber/__init__.py +++ b/src/syrupy/extensions/amber/__init__.py @@ -8,9 +8,10 @@ ) from syrupy.data import SnapshotCollection +from syrupy.exceptions import TaintedSnapshotError from syrupy.extensions.base import AbstractSyrupyExtension -from .serializer import DataSerializer +from .serializer import AmberDataSerializer if TYPE_CHECKING: from syrupy.types import SerializableData @@ -28,29 +29,29 @@ def serialize(self, data: "SerializableData", **kwargs: Any) -> str: Returns the serialized form of 'data' to be compared with the snapshot data written to disk. """ - return DataSerializer.serialize(data, **kwargs) + return AmberDataSerializer.serialize(data, **kwargs) def delete_snapshots( self, snapshot_location: str, snapshot_names: Set[str] ) -> None: - snapshot_collection_to_update = DataSerializer.read_file(snapshot_location) + snapshot_collection_to_update = AmberDataSerializer.read_file(snapshot_location) for snapshot_name in snapshot_names: snapshot_collection_to_update.remove(snapshot_name) if snapshot_collection_to_update.has_snapshots: - DataSerializer.write_file(snapshot_collection_to_update) + AmberDataSerializer.write_file(snapshot_collection_to_update) else: Path(snapshot_location).unlink() def _read_snapshot_collection(self, snapshot_location: str) -> "SnapshotCollection": - return DataSerializer.read_file(snapshot_location) + return AmberDataSerializer.read_file(snapshot_location) @staticmethod @lru_cache() def __cacheable_read_snapshot( snapshot_location: str, cache_key: str ) -> "SnapshotCollection": - return DataSerializer.read_file(snapshot_location) + return AmberDataSerializer.read_file(snapshot_location) def _read_snapshot_data_from_location( self, snapshot_location: str, snapshot_name: str, session_id: str @@ -59,13 +60,17 @@ def _read_snapshot_data_from_location( snapshot_location=snapshot_location, cache_key=session_id ) snapshot = snapshots.get(snapshot_name) - return snapshot.data if snapshot else None + tainted = bool(snapshots.tainted or (snapshot and snapshot.tainted)) + data = snapshot.data if snapshot else None + if tainted: + raise TaintedSnapshotError(snapshot_data=data) + return data @classmethod def _write_snapshot_collection( cls, *, snapshot_collection: "SnapshotCollection" ) -> None: - DataSerializer.write_file(snapshot_collection, merge=True) + AmberDataSerializer.write_file(snapshot_collection, merge=True) -__all__ = ["AmberSnapshotExtension", "DataSerializer"] +__all__ = ["AmberSnapshotExtension", "AmberDataSerializer"] diff --git a/src/syrupy/extensions/amber/serializer.py b/src/syrupy/extensions/amber/serializer.py index 3409429b..5a319939 100644 --- a/src/syrupy/extensions/amber/serializer.py +++ b/src/syrupy/extensions/amber/serializer.py @@ -9,6 +9,7 @@ Any, Callable, Dict, + Generator, Iterable, NamedTuple, Optional, @@ -62,13 +63,29 @@ def item_getter(o: "SerializableData", p: "PropertyName") -> "SerializableData": return o[p] -class DataSerializer: +class MalformedAmberFile(Exception): + """ + The Amber file is malformed. It should be deleted and regenerated. + """ + + +class MissingVersionError(Exception): + """ + Missing Amber version marker. + """ + + +class AmberDataSerializer: + VERSION = 1 + _indent: str = " " _max_depth: int = 99 - _marker_comment: str = "# " - _marker_divider: str = f"{_marker_comment}---" - _marker_name: str = f"{_marker_comment}name:" - _marker_crn: str = "\r\n" + _marker_prefix = "# " + + class Marker: + Version = "serializer version" + Name = "name" + Divider = "---" @classmethod def write_file( @@ -84,45 +101,85 @@ def write_file( snapshot_collection = base_snapshot with open(filepath, "w", encoding=TEXT_ENCODING, newline=None) as f: + f.write(f"{cls._marker_prefix}{cls.Marker.Version}: {cls.VERSION}\n") for snapshot in sorted(snapshot_collection, key=lambda s: s.name): snapshot_data = str(snapshot.data) if snapshot_data is not None: - f.write(f"{cls._marker_name} {snapshot.name}\n") + f.write(f"{cls._marker_prefix}{cls.Marker.Name}: {snapshot.name}\n") for data_line in snapshot_data.splitlines(keepends=True): f.write(cls.with_indent(data_line, 1)) - f.write(f"\n{cls._marker_divider}\n") + f.write(f"\n{cls._marker_prefix}{cls.Marker.Divider}\n") @classmethod - def read_file(cls, filepath: str) -> "SnapshotCollection": - """ - Read the raw snapshot data (str) from the snapshot file into a dict - of snapshot name to raw data. This does not attempt any deserialization - of the snapshot data. - """ - name_marker_len = len(cls._marker_name) + def __read_file_with_markers( + cls, filepath: str + ) -> Generator["Snapshot", None, None]: + marker_offset = len(cls._marker_prefix) indent_len = len(cls._indent) - snapshot_collection = SnapshotCollection(location=filepath) + + test_name = None + snapshot_data = "" + tainted = False + missing_version = True + try: with open(filepath, "r", encoding=TEXT_ENCODING, newline=None) as f: - test_name = None - snapshot_data = "" - for line in f: - if line.startswith(cls._marker_name): - test_name = line[name_marker_len:].strip(f" {cls._marker_crn}") - snapshot_data = "" - continue - elif test_name is not None: - if line.startswith(cls._indent): - snapshot_data += line[indent_len:] - elif line.startswith(cls._marker_divider) and snapshot_data: - snapshot_collection.add( - Snapshot( + for line_no, line in enumerate(f): + if line.startswith(cls._marker_prefix): + marker_key, *marker_rest = line[marker_offset:].split( + ":", maxsplit=1 + ) + marker_key = marker_key.rstrip(" \r\n") + marker_value = marker_rest[0] if marker_rest else None + + if marker_key == cls.Marker.Version: + if line_no: + raise MalformedAmberFile( + "Version must be specified at the top of the file." + ) + if not marker_value or int(marker_value) != cls.VERSION: + tainted = True + continue + missing_version = False + + if marker_key == cls.Marker.Name: + if not marker_value: + raise MalformedAmberFile("Missing snapshot name.") + + test_name = marker_value.strip(" \r\n") + continue + if marker_key == cls.Marker.Divider: + if test_name and snapshot_data: + yield Snapshot( name=test_name, data=snapshot_data.rstrip(os.linesep), + tainted=tainted, ) - ) + test_name = None + snapshot_data = "" + elif test_name is not None and line.startswith(cls._indent): + snapshot_data += line[indent_len:] except FileNotFoundError: pass + else: + if missing_version: + raise MissingVersionError + + @classmethod + def read_file(cls, filepath: str) -> "SnapshotCollection": + """ + Read the raw snapshot data (str) from the snapshot file into a dict + of snapshot name to raw data. This does not attempt any deserialization + of the snapshot data. + """ + snapshot_collection = SnapshotCollection(location=filepath) + try: + for snapshot in cls.__read_file_with_markers(filepath): + if snapshot.tainted: + snapshot_collection.tainted = True + snapshot_collection.add(snapshot) + except MissingVersionError: + snapshot_collection.tainted = True return snapshot_collection @@ -141,7 +198,7 @@ def serialize( should not break when running the tests on a unix based system and vice versa. """ serialized = cls._serialize(data, exclude=exclude, matcher=matcher) - return serialized.replace(cls._marker_crn, "\n").replace("\r", "\n") + return serialized.replace("\r\n", "\n").replace("\r", "\n") @classmethod def _serialize( @@ -191,7 +248,7 @@ def serialize_number( @classmethod def serialize_string(cls, data: str, *, depth: int = 0, **kwargs: Any) -> str: - if all(c not in data for c in cls._marker_crn): + if all(c not in data for c in "\r\n"): return cls.__serialize_plain(data=data, depth=depth) return cls.__serialize_lines( diff --git a/src/syrupy/matchers.py b/src/syrupy/matchers.py index 42689323..ec1dd71e 100644 --- a/src/syrupy/matchers.py +++ b/src/syrupy/matchers.py @@ -8,7 +8,7 @@ ) from syrupy.extensions.amber.serializer import ( - DataSerializer, + AmberDataSerializer, Repr, ) @@ -52,7 +52,7 @@ def path_type_matcher( if _path_match(path_str, pattern): for type_to_match in mapping[pattern]: if isinstance(data, type_to_match): - return Repr(DataSerializer.object_type(data)) + return Repr(AmberDataSerializer.object_type(data)) if strict: raise PathTypeError( gettext( @@ -62,7 +62,7 @@ def path_type_matcher( ) for type_to_match in types: if isinstance(data, type_to_match): - return Repr(DataSerializer.object_type(data)) + return Repr(AmberDataSerializer.object_type(data)) return data return path_type_matcher diff --git a/tests/examples/__snaps_example__/test_custom_snapshot_directory.ambr b/tests/examples/__snaps_example__/test_custom_snapshot_directory.ambr index 03976d12..7be3ff8a 100644 --- a/tests/examples/__snaps_example__/test_custom_snapshot_directory.ambr +++ b/tests/examples/__snaps_example__/test_custom_snapshot_directory.ambr @@ -1,3 +1,4 @@ +# serializer version: 1 # name: test_case_1 'Syrupy is amazing!' # --- diff --git a/tests/examples/__snapshots__/test_custom_object_repr.ambr b/tests/examples/__snapshots__/test_custom_object_repr.ambr index 2cb487e7..1fdea199 100644 --- a/tests/examples/__snapshots__/test_custom_object_repr.ambr +++ b/tests/examples/__snapshots__/test_custom_object_repr.ambr @@ -1,3 +1,4 @@ +# serializer version: 1 # name: test_snapshot_custom_class MyCustomClass( prop1=1, diff --git a/tests/examples/__snapshots__/test_custom_snapshot_name.ambr b/tests/examples/__snapshots__/test_custom_snapshot_name.ambr index 24dd5540..c972a025 100644 --- a/tests/examples/__snapshots__/test_custom_snapshot_name.ambr +++ b/tests/examples/__snapshots__/test_custom_snapshot_name.ambr @@ -1,3 +1,4 @@ +# serializer version: 1 # name: test_canadian_name🇨🇦 'Name should be test_canadian_name🇨🇦.' # --- diff --git a/tests/examples/__snapshots__/test_custom_snapshot_name_suffix.ambr b/tests/examples/__snapshots__/test_custom_snapshot_name_suffix.ambr index 26c024eb..50b345df 100644 --- a/tests/examples/__snapshots__/test_custom_snapshot_name_suffix.ambr +++ b/tests/examples/__snapshots__/test_custom_snapshot_name_suffix.ambr @@ -1,3 +1,4 @@ +# serializer version: 1 # name: test_snapshot_custom_snapshot_name_suffix[test_is_amazing] 'Syrupy is amazing!' # --- diff --git a/tests/syrupy/__snapshots__/test_doctest.ambr b/tests/syrupy/__snapshots__/test_doctest.ambr index 4de8a0f5..0b3e9696 100644 --- a/tests/syrupy/__snapshots__/test_doctest.ambr +++ b/tests/syrupy/__snapshots__/test_doctest.ambr @@ -1,3 +1,4 @@ +# serializer version: 1 # name: DocTestClass DocTestClass( obj_attr='test class attr', diff --git a/tests/syrupy/extensions/__snapshots__/test_base.ambr b/tests/syrupy/extensions/__snapshots__/test_base.ambr index ae4f37b3..6326362b 100644 --- a/tests/syrupy/extensions/__snapshots__/test_base.ambr +++ b/tests/syrupy/extensions/__snapshots__/test_base.ambr @@ -1,3 +1,4 @@ +# serializer version: 1 # name: TestSnapshotReporter.test_diff_lines[-0-SnapshotReporterNoContext] ''' ... diff --git a/tests/syrupy/extensions/amber/__snapshots__/test_amber_filters.ambr b/tests/syrupy/extensions/amber/__snapshots__/test_amber_filters.ambr index 6c53156e..f35f2e8f 100644 --- a/tests/syrupy/extensions/amber/__snapshots__/test_amber_filters.ambr +++ b/tests/syrupy/extensions/amber/__snapshots__/test_amber_filters.ambr @@ -1,3 +1,4 @@ +# serializer version: 1 # name: test_filters_error_prop[path_filter] WithNested( include_me='prop value', diff --git a/tests/syrupy/extensions/amber/__snapshots__/test_amber_matchers.ambr b/tests/syrupy/extensions/amber/__snapshots__/test_amber_matchers.ambr index d4558392..0fee642b 100644 --- a/tests/syrupy/extensions/amber/__snapshots__/test_amber_matchers.ambr +++ b/tests/syrupy/extensions/amber/__snapshots__/test_amber_matchers.ambr @@ -1,3 +1,4 @@ +# serializer version: 1 # name: test_matches_expected_type dict({ 'date_created': datetime, diff --git a/tests/syrupy/extensions/amber/__snapshots__/test_amber_serializer.ambr b/tests/syrupy/extensions/amber/__snapshots__/test_amber_serializer.ambr index 9ce2c540..d6854f03 100644 --- a/tests/syrupy/extensions/amber/__snapshots__/test_amber_serializer.ambr +++ b/tests/syrupy/extensions/amber/__snapshots__/test_amber_serializer.ambr @@ -1,3 +1,4 @@ +# serializer version: 1 # name: TestClass.TestNestedClass.test_nested_class_method[x] 'parameterized nested class method x' # --- diff --git a/tests/syrupy/extensions/amber/__snapshots__/test_amber_snapshot_diff.ambr b/tests/syrupy/extensions/amber/__snapshots__/test_amber_snapshot_diff.ambr index e9e87972..b2de431d 100644 --- a/tests/syrupy/extensions/amber/__snapshots__/test_amber_snapshot_diff.ambr +++ b/tests/syrupy/extensions/amber/__snapshots__/test_amber_snapshot_diff.ambr @@ -1,3 +1,4 @@ +# serializer version: 1 # name: test_snapshot_diff dict({ 'field_0': True, diff --git a/tests/syrupy/extensions/amber/test_amber_serializer.py b/tests/syrupy/extensions/amber/test_amber_serializer.py index 58b13f8c..57d54172 100644 --- a/tests/syrupy/extensions/amber/test_amber_serializer.py +++ b/tests/syrupy/extensions/amber/test_amber_serializer.py @@ -5,7 +5,7 @@ import pytest -from syrupy.extensions.amber.serializer import DataSerializer +from syrupy.extensions.amber.serializer import AmberDataSerializer def test_non_snapshots(snapshot): @@ -30,10 +30,10 @@ def test_snapshot_markers(snapshot): Test snapshot markers do not break serialization when in snapshot data """ marker_strings = ( - DataSerializer._marker_comment, - f"{DataSerializer._indent}{DataSerializer._marker_comment}", - DataSerializer._marker_divider, - DataSerializer._marker_name, + AmberDataSerializer._marker_prefix, + f"{AmberDataSerializer._indent}{AmberDataSerializer._marker_prefix}", + f"{AmberDataSerializer._marker_prefix}{AmberDataSerializer.Marker.Divider}", + f"{AmberDataSerializer._marker_prefix}{AmberDataSerializer.Marker.Name}:", ) assert snapshot == "\n".join(marker_strings) diff --git a/tests/syrupy/extensions/image/__snapshots__/test_image_png.ambr b/tests/syrupy/extensions/image/__snapshots__/test_image_png.ambr index 03ca82c6..4f90a9da 100644 --- a/tests/syrupy/extensions/image/__snapshots__/test_image_png.ambr +++ b/tests/syrupy/extensions/image/__snapshots__/test_image_png.ambr @@ -1,3 +1,4 @@ +# serializer version: 1 # name: test_multiple_snapshot_extensions.1 b'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x002\x00\x00\x002\x04\x03\x00\x00\x00\xec\x11\x95\x82\x00\x00\x00\x1bPLTE\xcc\xcc\xcc\x96\x96\x96\xaa\xaa\xaa\xb7\xb7\xb7\xb1\xb1\xb1\x9c\x9c\x9c\xbe\xbe\xbe\xa3\xa3\xa3\xc5\xc5\xc5\x05\xa4\xf2?\x00\x00\x00\tpHYs\x00\x00\x0e\xc4\x00\x00\x0e\xc4\x01\x95+\x0e\x1b\x00\x00\x00AIDAT8\x8dc`\x18\x05\xa3\x80\xfe\x80I\xd9\xdc\x00F\xa2\x02\x16\x86\x88\x00\xa6\x16\x10\x89.\xc3\x1a" \xc0\x11\x01"\xd1e\xd8\x12#\x028"@$\x86=*\xe6\x06L- \x92zn\x1f\x05\xc3\x1b\x00\x00\xe5\xfb\x08g\r"af\x00\x00\x00\x00IEND\xaeB`\x82' # --- diff --git a/tests/syrupy/extensions/image/__snapshots__/test_image_svg.ambr b/tests/syrupy/extensions/image/__snapshots__/test_image_svg.ambr index 84618e01..88e61f7b 100644 --- a/tests/syrupy/extensions/image/__snapshots__/test_image_svg.ambr +++ b/tests/syrupy/extensions/image/__snapshots__/test_image_svg.ambr @@ -1,3 +1,4 @@ +# serializer version: 1 # name: test_multiple_snapshot_extensions.1 '50 x 50' # --- diff --git a/tests/syrupy/extensions/json/test_json_serializer.py b/tests/syrupy/extensions/json/test_json_serializer.py index dde6d49b..e957c09e 100644 --- a/tests/syrupy/extensions/json/test_json_serializer.py +++ b/tests/syrupy/extensions/json/test_json_serializer.py @@ -5,7 +5,7 @@ import pytest -from syrupy.extensions.amber.serializer import DataSerializer +from syrupy.extensions.amber.serializer import AmberDataSerializer from syrupy.extensions.json import JSONSnapshotExtension @@ -33,10 +33,10 @@ def test_snapshot_markers(snapshot_json): Test snapshot markers do not break serialization when in snapshot data """ marker_strings = ( - DataSerializer._marker_comment, - f"{DataSerializer._indent}{DataSerializer._marker_comment}", - DataSerializer._marker_divider, - DataSerializer._marker_name, + AmberDataSerializer._marker_prefix, + f"{AmberDataSerializer._indent}{AmberDataSerializer._marker_prefix}", + f"{AmberDataSerializer._marker_prefix}{AmberDataSerializer.Marker.Divider}", + f"{AmberDataSerializer._marker_prefix}{AmberDataSerializer.Marker.Name}:", ) assert snapshot_json == "\n".join(marker_strings)