|
5 | 5 | from .SnapshotSystem import DiskStorage, SnapshotSystem, _selfieSystem, Mode |
6 | 6 | from .WriteTracker import recordCall as recordCall |
7 | 7 | from .Literals import ( |
8 | | - LiteralValue, |
9 | | - LiteralString, |
10 | 8 | LiteralFormat, |
| 9 | + LiteralRepr, |
| 10 | + LiteralString, |
| 11 | + LiteralValue, |
11 | 12 | TodoStub, |
12 | | - LiteralInt, |
13 | | - LiteralBoolean, |
14 | 13 | ) |
15 | 14 |
|
16 | 15 |
|
17 | 16 | from abc import ABC, abstractmethod |
18 | | -from typing import Any, List, Optional, Union |
| 17 | +from typing import Any, List, Optional |
19 | 18 | from itertools import chain |
20 | 19 |
|
21 | 20 |
|
| 21 | +class ReprSelfie[T]: |
| 22 | + def __init__(self, actual: T): |
| 23 | + self.actual = actual |
| 24 | + |
| 25 | + def to_be_TODO(self, unused_arg: Optional[T] = None) -> T: |
| 26 | + return _toBeDidntMatch(None, self.actual, LiteralRepr()) |
| 27 | + |
| 28 | + def to_be(self, expected: T) -> T: |
| 29 | + if self.actual == expected: |
| 30 | + return _checkSrc(self.actual) |
| 31 | + else: |
| 32 | + return _toBeDidntMatch(expected, self.actual, LiteralRepr()) |
| 33 | + |
| 34 | + |
22 | 35 | class FluentFacet(ABC): |
23 | 36 | @abstractmethod |
24 | 37 | def facet(self, facet: str) -> "StringFacet": |
@@ -95,7 +108,7 @@ def facet_binary(self, facet: str) -> "BinaryFacet": |
95 | 108 | raise NotImplementedError() |
96 | 109 |
|
97 | 110 |
|
98 | | -class StringSelfie(DiskSelfie, StringFacet): |
| 111 | +class StringSelfie(DiskSelfie, StringFacet, ReprSelfie[str]): |
99 | 112 | def __init__( |
100 | 113 | self, |
101 | 114 | actual: Snapshot, |
@@ -147,7 +160,7 @@ def __actual(self) -> str: |
147 | 160 | def to_be_TODO(self, unused_arg: Any = None) -> str: |
148 | 161 | return _toBeDidntMatch(None, self.__actual(), LiteralString()) |
149 | 162 |
|
150 | | - def to_be(self, expected: Union[str, int, bool]) -> str: |
| 163 | + def to_be(self, expected: str) -> str: |
151 | 164 | actual_string = self.__actual() |
152 | 165 |
|
153 | 166 | # Check if expected is a string |
@@ -234,39 +247,3 @@ def _serializeOnlyFacets(snapshot: Snapshot, keys: List[str]) -> str: |
234 | 247 | return writer_str[len(EMPTY_KEY_AND_FACET) : -1] |
235 | 248 | else: |
236 | 249 | return writer_str[:-1] |
237 | | - |
238 | | - |
239 | | -class IntSelfie: |
240 | | - def __init__(self, actual: int): |
241 | | - self.actual = actual |
242 | | - |
243 | | - def to_be_TODO(self, unused_arg: Any = None): |
244 | | - return _toBeDidntMatch(None, self.actual, LiteralInt()) |
245 | | - |
246 | | - def to_be(self, expected: Union[str, int, bool]) -> int: |
247 | | - if not isinstance(expected, int): |
248 | | - raise TypeError("Expected value must be an int") |
249 | | - |
250 | | - # Compare actual to expected; handle match or mismatch. |
251 | | - if self.actual == expected: |
252 | | - return _checkSrc(self.actual) |
253 | | - else: |
254 | | - return _toBeDidntMatch(expected, self.actual, LiteralInt()) |
255 | | - |
256 | | - |
257 | | -class BooleanSelfie: |
258 | | - def __init__(self, actual: bool): |
259 | | - self.actual = actual |
260 | | - |
261 | | - def to_be_TODO(self, unused_arg: Any = None): |
262 | | - return _toBeDidntMatch(None, self.actual, LiteralBoolean()) |
263 | | - |
264 | | - def to_be(self, expected: Union[str, int, bool]) -> bool: |
265 | | - if not isinstance(expected, bool): |
266 | | - raise TypeError("Expected value must be a bool") |
267 | | - |
268 | | - # Compare actual to expected; handle match or mismatch. |
269 | | - if self.actual == expected: |
270 | | - return _checkSrc(self.actual) |
271 | | - else: |
272 | | - return _toBeDidntMatch(expected, self.actual, LiteralBoolean()) |
0 commit comments