Skip to content

Commit a5c2a78

Browse files
authored
Merge pull request #352 from hssahota2/main
2 parents 978ee72 + 1b92aa5 commit a5c2a78

File tree

2 files changed

+55
-7
lines changed

2 files changed

+55
-7
lines changed

Diff for: python/selfie-lib/selfie_lib/Selfie.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
from .SelfieImplementations import StringSelfie
1+
from .SelfieImplementations import StringSelfie, IntSelfie, BooleanSelfie
22
from .Snapshot import Snapshot
33
from .SnapshotSystem import _selfieSystem
44

55
from typing import Union
66

77

8-
def expect_selfie(actual: Union[str, int]) -> "StringSelfie":
8+
def expect_selfie(actual: Union[str, int, bool]):
99
if isinstance(actual, int):
10-
raise NotImplementedError()
10+
return IntSelfie(actual)
1111
elif isinstance(actual, str):
1212
snapshot = Snapshot.of(actual)
1313
diskStorage = _selfieSystem().disk_thread_local()
1414
return StringSelfie(snapshot, diskStorage)
15+
elif isinstance(actual, bool):
16+
return BooleanSelfie(actual)
1517
else:
1618
raise NotImplementedError()

Diff for: python/selfie-lib/selfie_lib/SelfieImplementations.py

+50-4
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,18 @@
44
from .SnapshotFile import SnapshotFile
55
from .SnapshotSystem import DiskStorage, SnapshotSystem, _selfieSystem, Mode
66
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+
)
815

916

1017
from abc import ABC, abstractmethod
11-
from typing import Any, List, Optional
18+
from typing import Any, List, Optional, Union
1219
from itertools import chain
1320

1421

@@ -140,12 +147,21 @@ def __actual(self) -> str:
140147
def to_be_TODO(self, unused_arg: Any = None) -> str:
141148
return _toBeDidntMatch(None, self.__actual(), LiteralString())
142149

143-
def to_be(self, expected: str) -> str:
150+
def to_be(self, expected: Union[str, int, bool]) -> str:
144151
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+
145157
if actual_string == expected:
146158
return _checkSrc(actual_string)
147159
else:
148-
return _toBeDidntMatch(expected, actual_string, LiteralString())
160+
return _toBeDidntMatch(
161+
expected,
162+
actual_string,
163+
LiteralString(),
164+
)
149165

150166

151167
def _checkSrc[T](value: T) -> T:
@@ -218,3 +234,33 @@ def _serializeOnlyFacets(snapshot: Snapshot, keys: List[str]) -> str:
218234
return writer_str[len(EMPTY_KEY_AND_FACET) : -1]
219235
else:
220236
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

Comments
 (0)