Selfie
Loading...
Searching...
No Matches
selfie_lib.SelfieImplementations Namespace Reference

Classes

class  BinaryFacet
 
class  BinarySelfie
 
class  DiskSelfie
 
class  FluentFacet
 
class  ReprSelfie
 
class  StringFacet
 
class  StringSelfie
 

Functions

T _check_src (T value)
 
T _to_be_didnt_match (Optional[T] expected, T actual, LiteralFormat[T] fmt)
 
 _assert_equal (Optional[Snapshot] expected, Snapshot actual, SnapshotSystem storage)
 
str _serialize_only_facets (Snapshot snapshot, list[str] keys)
 

Variables

 T = TypeVar("T")
 

Function Documentation

◆ _assert_equal()

selfie_lib.SelfieImplementations._assert_equal ( Optional[Snapshot expected,
Snapshot  actual,
SnapshotSystem   storage 
)
protected

Definition at line 289 of file SelfieImplementations.py.

291):
292 if expected is None:
293 raise storage.fs.assert_failed(message=storage.mode.msg_snapshot_not_found())
294 elif expected == actual:
295 return
296 else:
297 mismatched_keys = sorted(
298 filter(
299 lambda facet: expected.subject_or_facet_maybe(facet)
300 != actual.subject_or_facet_maybe(facet),
301 chain(
302 [""],
303 expected.facets.keys(),
304 (facet for facet in actual.facets if facet not in expected.facets),
305 ),
306 )
307 )
308 expectedFacets = _serialize_only_facets(expected, mismatched_keys)
309 actualFacets = _serialize_only_facets(actual, mismatched_keys)
310 raise storage.fs.assert_failed(
311 message=storage.mode.msg_snapshot_mismatch(
312 expected=expectedFacets, actual=actualFacets
313 ),
314 expected=expectedFacets,
315 actual=actualFacets,
316 )
317
318

◆ _check_src()

T selfie_lib.SelfieImplementations._check_src ( T  value)
protected

Definition at line 256 of file SelfieImplementations.py.

256def _check_src(value: T) -> T:
257 _selfieSystem().mode.can_write(False, recordCall(True), _selfieSystem())
258 return value
259
260

◆ _serialize_only_facets()

str selfie_lib.SelfieImplementations._serialize_only_facets ( Snapshot  snapshot,
list[str]  keys 
)
protected

Definition at line 319 of file SelfieImplementations.py.

319def _serialize_only_facets(snapshot: Snapshot, keys: list[str]) -> str:
320 writer = []
321 for key in keys:
322 if not key:
323 SnapshotFile.writeEntry(writer, "", None, snapshot.subject_or_facet(key))
324 else:
325 value = snapshot.subject_or_facet(key)
326 if value is not None:
327 SnapshotFile.writeEntry(writer, "", key, value)
328
329 EMPTY_KEY_AND_FACET = "╔═ ═╗\n"
330 writer_str = "".join(writer)
331
332 if writer_str.startswith(EMPTY_KEY_AND_FACET):
333 # this codepath is triggered by the `key.isEmpty()` line above
334 return writer_str[len(EMPTY_KEY_AND_FACET) : -1]
335 else:
336 return writer_str[:-1]

◆ _to_be_didnt_match()

T selfie_lib.SelfieImplementations._to_be_didnt_match ( Optional[T expected,
T  actual,
LiteralFormat[T fmt 
)
protected

Definition at line 261 of file SelfieImplementations.py.

261def _to_be_didnt_match(expected: Optional[T], actual: T, fmt: LiteralFormat[T]) -> T:
262 call = recordCall(False)
263 writable = _selfieSystem().mode.can_write(expected is None, call, _selfieSystem())
264 if writable:
265 _selfieSystem().write_inline(LiteralValue(expected, actual, fmt), call)
266 return actual
267 else:
268 if expected is None:
269 raise _selfieSystem().fs.assert_failed(
270 f"Can't call `to_be_TODO` in {Mode.readonly} mode!"
271 )
272 else:
273 expectedStr = repr(expected)
274 actualStr = repr(actual)
275 if expectedStr == actualStr:
276 raise ValueError(
277 f"Value of type {type(actual)} is not `==` to the expected value, but they both have the same `repr` value:\n${expectedStr}"
278 )
279 else:
280 raise _selfieSystem().fs.assert_failed(
281 message=_selfieSystem().mode.msg_snapshot_mismatch(
282 expected=expectedStr, actual=actualStr
283 ),
284 expected=expected,
285 actual=actual,
286 )
287
288

Variable Documentation

◆ T

selfie_lib.SelfieImplementations.T = TypeVar("T")

Definition at line 18 of file SelfieImplementations.py.