Skip to content

Commit 343ae08

Browse files
committed
Add **kwargs for various subclasses of AbstractSyrupyExtension
1 parent 7730070 commit 343ae08

File tree

4 files changed

+33
-18
lines changed

4 files changed

+33
-18
lines changed

Diff for: src/syrupy/extensions/amber/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def delete_snapshots(
4747
else:
4848
Path(snapshot_location).unlink()
4949

50-
def _read_snapshot_collection(self, snapshot_location: str) -> "SnapshotCollection":
50+
def _read_snapshot_collection(self, snapshot_location: str, **kwargs: Any) -> "SnapshotCollection":
5151
return self.serializer_class.read_file(snapshot_location)
5252

5353
@classmethod
@@ -72,7 +72,7 @@ def _read_snapshot_data_from_location(
7272

7373
@classmethod
7474
def _write_snapshot_collection(
75-
cls, *, snapshot_collection: "SnapshotCollection"
75+
cls, *, snapshot_collection: "SnapshotCollection", **kwargs: Any
7676
) -> None:
7777
cls.serializer_class.write_file(snapshot_collection, merge=True)
7878

Diff for: src/syrupy/extensions/base.py

+17-6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
Optional,
1616
Set,
1717
Tuple,
18+
Any,
1819
)
1920

2021
from syrupy.constants import (
@@ -67,6 +68,7 @@ def serialize(
6768
exclude: Optional["PropertyFilter"] = None,
6869
include: Optional["PropertyFilter"] = None,
6970
matcher: Optional["PropertyMatcher"] = None,
71+
**kwargs: Any,
7072
) -> "SerializedData":
7173
"""
7274
Serializes a python object / data structure into a string
@@ -108,7 +110,7 @@ def is_snapshot_location(self, *, location: str) -> bool:
108110
return location.endswith(self._file_extension)
109111

110112
def discover_snapshots(
111-
self, *, test_location: "PyTestLocation"
113+
self, *, test_location: "PyTestLocation", **kwargs: Any
112114
) -> "SnapshotCollections":
113115
"""
114116
Returns all snapshot collections in test site
@@ -216,7 +218,7 @@ def delete_snapshots(
216218

217219
@abstractmethod
218220
def _read_snapshot_collection(
219-
self, *, snapshot_location: str
221+
self, *, snapshot_location: str, **kwargs: Any
220222
) -> "SnapshotCollection":
221223
"""
222224
Read the snapshot location and construct a snapshot collection object
@@ -235,15 +237,17 @@ def _read_snapshot_data_from_location(
235237
@classmethod
236238
@abstractmethod
237239
def _write_snapshot_collection(
238-
cls, *, snapshot_collection: "SnapshotCollection"
240+
cls, *, snapshot_collection: "SnapshotCollection", **kwargs: Any
239241
) -> None:
240242
"""
241243
Adds the snapshot data to the snapshots in collection location
242244
"""
243245
raise NotImplementedError
244246

245247
@classmethod
246-
def dirname(cls, *, test_location: "PyTestLocation") -> str:
248+
def dirname(
249+
cls, *, test_location: "PyTestLocation", **kwargs: Any
250+
) -> str:
247251
test_dir = Path(test_location.filepath).parent
248252
return str(test_dir.joinpath(SNAPSHOT_DIRNAME))
249253

@@ -259,15 +263,21 @@ class SnapshotReporter(ABC):
259263
_context_line_count = 1
260264

261265
def diff_snapshots(
262-
self, serialized_data: "SerializedData", snapshot_data: "SerializedData"
266+
self,
267+
serialized_data: "SerializedData",
268+
snapshot_data: "SerializedData",
269+
**kwargs: Any,
263270
) -> "SerializedData":
264271
env = {DISABLE_COLOR_ENV_VAR: "true"}
265272
attrs = {"_context_line_count": 0}
266273
with env_context(**env), obj_attrs(self, attrs):
267274
return "\n".join(self.diff_lines(serialized_data, snapshot_data))
268275

269276
def diff_lines(
270-
self, serialized_data: "SerializedData", snapshot_data: "SerializedData"
277+
self,
278+
serialized_data: "SerializedData",
279+
snapshot_data: "SerializedData",
280+
**kwargs: Any,
271281
) -> Iterator[str]:
272282
for line in self.__diff_lines(str(snapshot_data), str(serialized_data)):
273283
yield reset(line)
@@ -407,6 +417,7 @@ def matches(
407417
*,
408418
serialized_data: "SerializableData",
409419
snapshot_data: "SerializableData",
420+
**kwargs: Any,
410421
) -> bool:
411422
"""
412423
Compares serialized data and snapshot data and returns

Diff for: src/syrupy/extensions/json/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ def serialize(
145145
exclude: Optional["PropertyFilter"] = None,
146146
include: Optional["PropertyFilter"] = None,
147147
matcher: Optional["PropertyMatcher"] = None,
148+
**kwargs: Any,
148149
) -> "SerializedData":
149150
data = self._filter(
150151
data=data,

Diff for: src/syrupy/extensions/single_file.py

+13-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
from enum import Enum
22
from gettext import gettext
33
from pathlib import Path
4-
from typing import (
5-
TYPE_CHECKING,
6-
Optional,
7-
Set,
8-
Type,
9-
Union,
10-
)
4+
from typing import TYPE_CHECKING, Optional, Set, Type, Union, Dict, Any
115
from unicodedata import category
126

137
from syrupy.constants import TEXT_ENCODING
@@ -49,6 +43,7 @@ def serialize(
4943
exclude: Optional["PropertyFilter"] = None,
5044
include: Optional["PropertyFilter"] = None,
5145
matcher: Optional["PropertyMatcher"] = None,
46+
**kwargs: Any,
5247
) -> "SerializedData":
5348
return self.get_supported_dataclass()(data)
5449

@@ -74,12 +69,17 @@ def _get_file_basename(
7469
return cls.get_snapshot_name(test_location=test_location, index=index)
7570

7671
@classmethod
77-
def dirname(cls, *, test_location: "PyTestLocation") -> str:
72+
def dirname(
73+
cls, *, test_location: "PyTestLocation", **kwargs: Any
74+
) -> str:
7875
original_dirname = AbstractSyrupyExtension.dirname(test_location=test_location)
7976
return str(Path(original_dirname).joinpath(test_location.basename))
8077

8178
def _read_snapshot_collection(
82-
self, *, snapshot_location: str
79+
self,
80+
*,
81+
snapshot_location: str,
82+
**kwargs: Any,
8383
) -> "SnapshotCollection":
8484
file_ext_len = len(self._file_extension) + 1 if self._file_extension else 0
8585
filename_wo_ext = snapshot_location[:-file_ext_len]
@@ -116,7 +116,10 @@ def get_write_encoding(cls) -> Optional[str]:
116116

117117
@classmethod
118118
def _write_snapshot_collection(
119-
cls, *, snapshot_collection: "SnapshotCollection"
119+
cls,
120+
*,
121+
snapshot_collection: "SnapshotCollection",
122+
**kwargs: Any,
120123
) -> None:
121124
filepath, data = (
122125
snapshot_collection.location,

0 commit comments

Comments
 (0)