Selfie
Loading...
Searching...
No Matches
selfie_lib.CacheSelfie.CacheSelfie Class Reference
Inheritance diagram for selfie_lib.CacheSelfie.CacheSelfie:

Public Member Functions

 __init__ (self, DiskStorage disk, Roundtrip[T, str] roundtrip, Callable[..., T] generator)
 
T to_match_disk (self, str sub="")
 
T to_match_disk_TODO (self, str sub="")
 
T to_be_TODO (self, Optional[Any] _=None)
 
T to_be (self, str expected)
 

Public Attributes

 disk
 
 roundtrip
 
 generator
 

Protected Member Functions

T _to_match_disk_impl (self, str sub, bool is_todo)
 
T _to_be_impl (self, Optional[str] snapshot)
 

Detailed Description

Definition at line 67 of file CacheSelfie.py.

Constructor & Destructor Documentation

◆ __init__()

selfie_lib.CacheSelfie.CacheSelfie.__init__ (   self,
DiskStorage  disk,
Roundtrip[T, str]  roundtrip,
Callable[..., T generator 
)

Definition at line 68 of file CacheSelfie.py.

73 ):
74 self.disk = disk
75 self.roundtrip = roundtrip
76 self.generator = generator
77

Member Function Documentation

◆ _to_be_impl()

T selfie_lib.CacheSelfie.CacheSelfie._to_be_impl (   self,
Optional[str]  snapshot 
)
protected

Definition at line 114 of file CacheSelfie.py.

114 def _to_be_impl(self, snapshot: Optional[str]) -> T:
115 call = recordCall(False)
116 system = _selfieSystem()
117 writable = system.mode.can_write(snapshot is None, call, system)
118 if writable:
119 actual = self.generator()
120 literal_string_formatter = LiteralString()
121 system.write_inline(
122 LiteralValue(
123 snapshot, self.roundtrip.serialize(actual), literal_string_formatter
124 ),
125 call,
126 )
127 return actual
128 else:
129 if snapshot is None:
130 raise Exception("Can't call `to_be_todo` in readonly mode!")
131 else:
132 return self.roundtrip.parse(snapshot)
133
134

◆ _to_match_disk_impl()

T selfie_lib.CacheSelfie.CacheSelfie._to_match_disk_impl (   self,
str  sub,
bool  is_todo 
)
protected

Definition at line 84 of file CacheSelfie.py.

84 def _to_match_disk_impl(self, sub: str, is_todo: bool) -> T:
85 call = recordCall(False)
86 system = _selfieSystem()
87 if system.mode.can_write(is_todo, call, system):
88 actual = self.generator()
89 self.disk.write_disk(
90 Snapshot.of(self.roundtrip.serialize(actual)), sub, call
91 )
92 if is_todo:
93 system.write_inline(TodoStub.to_match_disk.create_literal(), call)
94 return actual
95 else:
96 if is_todo:
97 raise Exception("Can't call `to_match_disk_todo` in readonly mode!")
98 else:
99 snapshot = self.disk.read_disk(sub, call)
100 if snapshot is None:
101 raise Exception(system.mode.msg_snapshot_not_found())
102 if snapshot.subject.is_binary or len(snapshot.facets) > 0:
103 raise Exception(
104 f"Expected a string subject with no facets, got {snapshot}"
105 )
106 return self.roundtrip.parse(snapshot.subject.value_string())
107

◆ to_be()

T selfie_lib.CacheSelfie.CacheSelfie.to_be (   self,
str  expected 
)

Definition at line 111 of file CacheSelfie.py.

111 def to_be(self, expected: str) -> T:
112 return self._to_be_impl(expected)
113

◆ to_be_TODO()

T selfie_lib.CacheSelfie.CacheSelfie.to_be_TODO (   self,
Optional[Any]   _ = None 
)

Definition at line 108 of file CacheSelfie.py.

108 def to_be_TODO(self, _: Optional[Any] = None) -> T:
109 return self._to_be_impl(None)
110

◆ to_match_disk()

T selfie_lib.CacheSelfie.CacheSelfie.to_match_disk (   self,
str   sub = "" 
)

Definition at line 78 of file CacheSelfie.py.

78 def to_match_disk(self, sub: str = "") -> T:
79 return self._to_match_disk_impl(sub, False)
80

◆ to_match_disk_TODO()

T selfie_lib.CacheSelfie.CacheSelfie.to_match_disk_TODO (   self,
str   sub = "" 
)

Definition at line 81 of file CacheSelfie.py.

81 def to_match_disk_TODO(self, sub: str = "") -> T:
82 return self._to_match_disk_impl(sub, True)
83

Member Data Documentation

◆ disk

selfie_lib.CacheSelfie.CacheSelfie.disk

Definition at line 74 of file CacheSelfie.py.

◆ generator

selfie_lib.CacheSelfie.CacheSelfie.generator

Definition at line 76 of file CacheSelfie.py.

◆ roundtrip

selfie_lib.CacheSelfie.CacheSelfie.roundtrip

Definition at line 75 of file CacheSelfie.py.


The documentation for this class was generated from the following file: