Selfie
Loading...
Searching...
No Matches
selfie_lib.SelfieImplementations.BinarySelfie Class Reference
Inheritance diagram for selfie_lib.SelfieImplementations.BinarySelfie:
selfie_lib.SelfieImplementations.ReprSelfie selfie_lib.SelfieImplementations.BinaryFacet selfie_lib.SelfieImplementations.DiskSelfie selfie_lib.SelfieImplementations.FluentFacet selfie_lib.SelfieImplementations.FluentFacet

Public Member Functions

 __init__ (self, Snapshot actual, DiskStorage disk, str only_facet)
 
"BinarySelfie" to_match_disk (self, str sub="")
 
"BinarySelfie" to_match_disk_TODO (self, str sub="")
 
bytes to_be_base64_TODO (self, Any _=None)
 
bytes to_be_base64 (self, str expected)
 
bytes to_be_file_TODO (self, str subpath)
 
bytes to_be_file (self, str subpath)
 
- Public Member Functions inherited from selfie_lib.SelfieImplementations.ReprSelfie
T to_be_TODO (self, Optional[T] _=None)
 
T to_be (self, T expected)
 
- Public Member Functions inherited from selfie_lib.SelfieImplementations.DiskSelfie
"StringFacet" facet (self, str facet)
 
"StringFacet" facets (self, *str facets)
 
"BinaryFacet" facet_binary (self, str facet)
 

Public Attributes

 only_facet
 
- Public Attributes inherited from selfie_lib.SelfieImplementations.ReprSelfie
 actual_before_repr
 
- Public Attributes inherited from selfie_lib.SelfieImplementations.DiskSelfie
 actual
 
 disk
 

Protected Member Functions

bytes _actual_bytes (self)
 
str _actual_string (self)
 
bytes _to_be_file_impl (self, str subpath, bool is_todo)
 

Detailed Description

Definition at line 176 of file SelfieImplementations.py.

Constructor & Destructor Documentation

◆ __init__()

selfie_lib.SelfieImplementations.BinarySelfie.__init__ (   self,
Snapshot  actual,
DiskStorage  disk,
str  only_facet 
)

Reimplemented from selfie_lib.SelfieImplementations.ReprSelfie.

Definition at line 177 of file SelfieImplementations.py.

177 def __init__(self, actual: Snapshot, disk: DiskStorage, only_facet: str):
178 super().__init__(actual.subject.value_binary(), actual, disk)
179 self.only_facet = only_facet
180
181 facet_value = actual.subject_or_facet_maybe(only_facet)
182 if facet_value is None:
183 raise ValueError(f"The facet {only_facet} was not found in the snapshot")
184 elif not facet_value.is_binary:
185 raise ValueError(
186 f"The facet {only_facet} is a string, not a binary snapshot"
187 )
188

Member Function Documentation

◆ _actual_bytes()

bytes selfie_lib.SelfieImplementations.BinarySelfie._actual_bytes (   self)
protected

Definition at line 189 of file SelfieImplementations.py.

189 def _actual_bytes(self) -> bytes:
190 return self.actual.subject_or_facet(self.only_facet).value_binary()
191

◆ _actual_string()

str selfie_lib.SelfieImplementations.BinarySelfie._actual_string (   self)
protected

Definition at line 213 of file SelfieImplementations.py.

213 def _actual_string(self) -> str:
214 return base64.b64encode(self._actual_bytes()).decode().replace("\r", "")
215

◆ _to_be_file_impl()

bytes selfie_lib.SelfieImplementations.BinarySelfie._to_be_file_impl (   self,
str  subpath,
bool  is_todo 
)
protected

Definition at line 216 of file SelfieImplementations.py.

216 def _to_be_file_impl(self, subpath: str, is_todo: bool) -> bytes:
217 call = recordCall(False)
218 writable = _selfieSystem().mode.can_write(is_todo, call, _selfieSystem())
219 actual_bytes = self._actual_bytes()
220 path = _selfieSystem().layout.root_folder().resolve_file(subpath)
221
222 if writable:
223 if is_todo:
224 _selfieSystem().write_inline(TodoStub.to_be_file.create_literal(), call)
225 _selfieSystem().write_to_be_file(path, actual_bytes, call)
226 return actual_bytes
227 else:
228 if is_todo:
229 raise _selfieSystem().fs.assert_failed(
230 f"Can't call `to_be_file_TODO` in {Mode.readonly} mode!"
231 )
232 else:
233 if not _selfieSystem().fs.file_exists(path):
234 raise _selfieSystem().fs.assert_failed(
235 _selfieSystem().mode.msg_snapshot_not_found_no_such_file(path)
236 )
237 expected = _selfieSystem().fs.file_read_binary(path)
238 if expected == actual_bytes:
239 return actual_bytes
240 else:
241 raise _selfieSystem().fs.assert_failed(
242 message=_selfieSystem().mode.msg_snapshot_mismatch_binary(
243 expected, actual_bytes
244 ),
245 expected=expected,
246 actual=actual_bytes,
247 )
248

◆ to_be_base64()

bytes selfie_lib.SelfieImplementations.BinarySelfie.to_be_base64 (   self,
str  expected 
)

Reimplemented from selfie_lib.SelfieImplementations.BinaryFacet.

Definition at line 204 of file SelfieImplementations.py.

204 def to_be_base64(self, expected: str) -> bytes:
205 expected_bytes = base64.b64decode(expected)
206 actual_bytes = self._actual_bytes()
207 if actual_bytes == expected_bytes:
208 return _check_src(actual_bytes)
209 else:
210 _to_be_didnt_match(expected, self._actual_string(), LiteralString())
211 return actual_bytes
212

◆ to_be_base64_TODO()

bytes selfie_lib.SelfieImplementations.BinarySelfie.to_be_base64_TODO (   self,
Any   _ = None 
)

Reimplemented from selfie_lib.SelfieImplementations.BinaryFacet.

Definition at line 200 of file SelfieImplementations.py.

200 def to_be_base64_TODO(self, _: Any = None) -> bytes:
201 _to_be_didnt_match(None, self._actual_string(), LiteralString())
202 return self._actual_bytes()
203

◆ to_be_file()

bytes selfie_lib.SelfieImplementations.BinarySelfie.to_be_file (   self,
str  subpath 
)

Reimplemented from selfie_lib.SelfieImplementations.BinaryFacet.

Definition at line 252 of file SelfieImplementations.py.

252 def to_be_file(self, subpath: str) -> bytes:
253 return self._to_be_file_impl(subpath, False)
254
255

◆ to_be_file_TODO()

bytes selfie_lib.SelfieImplementations.BinarySelfie.to_be_file_TODO (   self,
str  subpath 
)

Reimplemented from selfie_lib.SelfieImplementations.BinaryFacet.

Definition at line 249 of file SelfieImplementations.py.

249 def to_be_file_TODO(self, subpath: str) -> bytes:
250 return self._to_be_file_impl(subpath, True)
251

◆ to_match_disk()

"BinarySelfie" selfie_lib.SelfieImplementations.BinarySelfie.to_match_disk (   self,
str   sub = "" 
)

Reimplemented from selfie_lib.SelfieImplementations.DiskSelfie.

Definition at line 192 of file SelfieImplementations.py.

192 def to_match_disk(self, sub: str = "") -> "BinarySelfie":
193 super().to_match_disk(sub)
194 return self
195

◆ to_match_disk_TODO()

"BinarySelfie" selfie_lib.SelfieImplementations.BinarySelfie.to_match_disk_TODO (   self,
str   sub = "" 
)

Reimplemented from selfie_lib.SelfieImplementations.DiskSelfie.

Definition at line 196 of file SelfieImplementations.py.

196 def to_match_disk_TODO(self, sub: str = "") -> "BinarySelfie":
197 super().to_match_disk_TODO(sub)
198 return self
199

Member Data Documentation

◆ only_facet

selfie_lib.SelfieImplementations.BinarySelfie.only_facet

Definition at line 179 of file SelfieImplementations.py.


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