Skip to content

Commit dc65d10

Browse files
authored
Remove botocore dependency by transform any IO-stream (#5)
1 parent b0cd665 commit dc65d10

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

localstack_snapshot/snapshots/prototype.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import io
12
import json
23
import logging
34
import os
@@ -7,7 +8,6 @@
78
from re import Pattern
89
from typing import Dict, List, Optional
910

10-
from botocore.response import StreamingBody
1111
from deepdiff import DeepDiff
1212
from jsonpath_ng import DatumInContext
1313
from jsonpath_ng.ext import parse
@@ -260,11 +260,10 @@ def _assert_all(
260260
def _transform_dict_to_parseable_values(self, original):
261261
"""recursively goes through dict and tries to resolve values to strings (& parse them as json if possible)"""
262262
for k, v in original.items():
263-
if isinstance(v, StreamingBody):
263+
if isinstance(v, io.IOBase):
264264
# update v for json parsing below
265-
original[k] = v = v.read().decode(
266-
"utf-8"
267-
) # TODO: patch boto client so this doesn't break any further read() calls
265+
# TODO: patch boto client so this doesn't break any further read() calls
266+
original[k] = v = v.read().decode("utf-8")
268267
if isinstance(v, list) and v:
269268
for item in v:
270269
if isinstance(item, dict):

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ description = "Extracted snapshot testing lib for LocalStack"
1212
dependencies = [
1313
"jsonpath-ng>1.6",
1414
"deepdiff",
15-
"botocore",
1615
]
1716
requires-python = ">=3.10"
1817
license = {file = "LICENSE"}

tests/test_snapshots.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import io
2+
13
import pytest
24

35
from localstack_snapshot.snapshots import SnapshotSession
@@ -20,6 +22,12 @@ def test_simple_diff_change(self):
2022
sm._assert_all()
2123
ctx.match("Parity snapshot failed")
2224

25+
def test_diff_with_io_stream(self):
26+
sm = SnapshotSession(scope_key="A", verify=True, base_file_path="", update=False)
27+
sm.recorded_state = {"key_a": {"a": "data"}}
28+
sm.match("key_a", {"a": io.BytesIO(b"data")})
29+
sm._assert_all()
30+
2331
def test_multiple_assertmatch_with_same_key_fail(self):
2432
sm = SnapshotSession(scope_key="A", verify=True, base_file_path="", update=False)
2533
sm.recorded_state = {"key_a": {"a": 3}}

0 commit comments

Comments
 (0)