|
4 | 4 | from .SnapshotFile import SnapshotFile
|
5 | 5 | from .SnapshotSystem import DiskStorage, SnapshotSystem, _selfieSystem, Mode
|
6 | 6 | from .WriteTracker import recordCall as recordCall
|
7 |
| -from .Literals import LiteralValue, LiteralString, LiteralFormat, TodoStub |
| 7 | +from .Literals import ( |
| 8 | + LiteralValue, |
| 9 | + LiteralString, |
| 10 | + LiteralFormat, |
| 11 | + TodoStub, |
| 12 | + LiteralInt, |
| 13 | + LiteralBoolean, |
| 14 | +) |
8 | 15 |
|
9 | 16 |
|
10 | 17 | from abc import ABC, abstractmethod
|
11 |
| -from typing import Any, List, Optional |
| 18 | +from typing import Any, List, Optional, Union |
12 | 19 | from itertools import chain
|
13 | 20 |
|
14 | 21 |
|
@@ -140,12 +147,21 @@ def __actual(self) -> str:
|
140 | 147 | def to_be_TODO(self, unused_arg: Any = None) -> str:
|
141 | 148 | return _toBeDidntMatch(None, self.__actual(), LiteralString())
|
142 | 149 |
|
143 |
| - def to_be(self, expected: str) -> str: |
| 150 | + def to_be(self, expected: Union[str, int, bool]) -> str: |
144 | 151 | actual_string = self.__actual()
|
| 152 | + |
| 153 | + # Check if expected is a string |
| 154 | + if not isinstance(expected, str): |
| 155 | + raise TypeError("Expected value must be a string") |
| 156 | + |
145 | 157 | if actual_string == expected:
|
146 | 158 | return _checkSrc(actual_string)
|
147 | 159 | else:
|
148 |
| - return _toBeDidntMatch(expected, actual_string, LiteralString()) |
| 160 | + return _toBeDidntMatch( |
| 161 | + expected, |
| 162 | + actual_string, |
| 163 | + LiteralString(), |
| 164 | + ) |
149 | 165 |
|
150 | 166 |
|
151 | 167 | def _checkSrc[T](value: T) -> T:
|
@@ -218,3 +234,33 @@ def _serializeOnlyFacets(snapshot: Snapshot, keys: List[str]) -> str:
|
218 | 234 | return writer_str[len(EMPTY_KEY_AND_FACET) : -1]
|
219 | 235 | else:
|
220 | 236 | 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 | + # Compare actual to expected; handle match or mismatch. |
| 248 | + if self.actual == expected: |
| 249 | + return _checkSrc(self.actual) |
| 250 | + else: |
| 251 | + return _toBeDidntMatch(expected, self.actual, LiteralInt()) |
| 252 | + |
| 253 | + |
| 254 | +class BooleanSelfie: |
| 255 | + def __init__(self, actual: bool): |
| 256 | + self.actual = actual |
| 257 | + |
| 258 | + def to_be_TODO(self, unused_arg: Any = None): |
| 259 | + return _toBeDidntMatch(None, self.actual, LiteralBoolean()) |
| 260 | + |
| 261 | + def to_be(self, expected: Union[str, int, bool]) -> bool: |
| 262 | + # Compare actual to expected; handle match or mismatch. |
| 263 | + if self.actual == expected: |
| 264 | + return _checkSrc(self.actual) |
| 265 | + else: |
| 266 | + return _toBeDidntMatch(expected, self.actual, LiteralBoolean()) |
0 commit comments