Skip to content

Commit af3d0f4

Browse files
committed
Fix linting issue
1 parent fb7f87a commit af3d0f4

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

snappylapy/fixtures.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ def read_test_results(self) -> bytes:
215215

216216
@overload
217217
def __call__(self, data_to_snapshot: dict, name: str | None = None, filetype: str | None = None) -> DictExpect: ...
218+
218219
@overload
219220
def __call__(
220221
self,
@@ -236,7 +237,10 @@ def __call__(
236237

237238
@overload
238239
def __call__(
239-
self, data_to_snapshot: DataframeExpect.DataFrame, name: str | None = None, filetype: str | None = None,
240+
self,
241+
data_to_snapshot: DataframeExpect.DataFrame,
242+
name: str | None = None,
243+
filetype: str | None = None,
240244
) -> DataframeExpect: ...
241245

242246
def __call__(
@@ -261,13 +265,14 @@ def __call__(
261265
}
262266

263267
for typ, func in type_map.items():
264-
if isinstance(data_to_snapshot, typ):
268+
if isinstance(typ, type) and isinstance(data_to_snapshot, typ):
265269
return func(data_to_snapshot, **kwargs)
266270

267-
error_message = f"Unsupported type {type(data_to_snapshot)}. Expected one of: dict, list, str, bytes, DataFrame."
268-
raise TypeError(
269-
error_message,
270-
)
271+
supported_types: list[str] = [
272+
getattr(typ, "__name__", str(typ)) if isinstance(typ, type) else typ for typ in type_map.keys() # noqa: SIM118
273+
]
274+
error_message = f"Unsupported type: {type(data_to_snapshot)}. Supported types: {', '.join(supported_types)}."
275+
raise TypeError(error_message)
271276

272277

273278
class LoadSnapshot:
@@ -312,5 +317,5 @@ def dataframe(self) -> DataframeExpect.DataFrame:
312317
"""Load dataframe snapshot."""
313318
self.settings.depending_filename_extension = "dataframe.json"
314319
return DataframeExpect.DataFrame(
315-
JsonPickleSerializer[DataframeExpect.DataFrame]().deserialize(self._read_snapshot())
320+
JsonPickleSerializer[DataframeExpect.DataFrame]().deserialize(self._read_snapshot()),
316321
)

tests/test_snappylappy_new.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ def test_snapshot_string(expect: Expect):
77
"""Test snapshot with string data."""
88
expect.string("Hello World").to_match_snapshot()
99

10+
def test_unsupported_type(expect: Expect):
11+
"""Test snapshot with unsupported type."""
12+
class Unsupported:
13+
"""An unsupported type for snapshot."""
14+
pass
15+
16+
with pytest.raises(TypeError):
17+
expect(Unsupported())
18+
1019
def test_snapshot_bytes(expect: Expect):
1120
"""Test snapshot with bytes data."""
1221
expect.bytes(b"Hello World", name="bytes_snapshot").to_match_snapshot()

0 commit comments

Comments
 (0)