Skip to content

Commit 5910ea6

Browse files
committed
Try again with an actual Camera to see if that helps.
1 parent 918ac61 commit 5910ea6

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed
Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from selfie_lib import Snapshot, StringSelfie, expect_selfie
1+
from selfie_lib import Camera, Snapshot, StringSelfie, expect_selfie
22
from werkzeug.test import TestResponse
33

44
REDIRECTS = {
@@ -9,14 +9,19 @@
99
}
1010

1111

12-
def web_selfie(response: TestResponse) -> StringSelfie:
12+
def web_camera(response: TestResponse) -> Snapshot:
1313
redirect_reason = REDIRECTS.get(response.status_code)
1414
if redirect_reason is not None:
15-
actual = Snapshot.of(
16-
f"REDIRECT {response.status_code} {redirect_reason} to {response.headers.get("Location", "<unknown>")}"
15+
return Snapshot.of(
16+
f"REDIRECT {response.status_code} {redirect_reason} to "
17+
+ response.headers.get("Location", "<unknown>")
1718
)
1819
else:
19-
actual = Snapshot.of(response.data.decode()).plus_facet(
20-
"status", response.status
21-
)
22-
return expect_selfie(actual)
20+
return Snapshot.of(response.data.decode()).plus_facet("status", response.status)
21+
22+
23+
WEB_CAMERA = Camera.of(web_camera)
24+
25+
26+
def web_selfie(response: TestResponse) -> StringSelfie:
27+
return expect_selfie(response, WEB_CAMERA)

python/selfie-lib/selfie_lib/Selfie.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from typing import Any, TypeVar, overload
22

3+
from .Lens import Camera
34
from .SelfieImplementations import BinarySelfie, DiskSelfie, ReprSelfie, StringSelfie
45
from .Snapshot import Snapshot
56
from .SnapshotSystem import _selfieSystem
@@ -23,11 +24,15 @@ def expect_selfie(actual: bytes) -> BinarySelfie: ...
2324
def expect_selfie(actual: T) -> ReprSelfie[T]: ...
2425

2526

26-
def expect_selfie(
27-
actual: Any,
28-
) -> DiskSelfie:
27+
@overload
28+
def expect_selfie(actual: T, camera: Camera[T]) -> StringSelfie: ...
29+
30+
31+
def expect_selfie(actual: Any, camera: Any = None) -> DiskSelfie:
2932
disk_storage = _selfieSystem().disk_thread_local()
30-
if isinstance(actual, str):
33+
if camera is not None:
34+
return StringSelfie(camera.snapshot(actual), disk_storage)
35+
elif isinstance(actual, str):
3136
return StringSelfie(Snapshot.of(actual), disk_storage)
3237
elif isinstance(actual, Snapshot):
3338
return StringSelfie(actual, disk_storage)

0 commit comments

Comments
 (0)