@@ -199,27 +199,20 @@ def to_be_base64(self, expected: str) -> bytes:
199199 def to_be_base64_TODO (self , _ : Any = None ) -> bytes :
200200 call = recordCall (False )
201201 if not _selfieSystem ().mode .can_write (True , call , _selfieSystem ()):
202- raise _selfieSystem ().fs .assert_failed (
203- f"Can't call `to_be_base64_TODO` in { _selfieSystem ().mode } mode!"
204- )
202+ raise AssertionError (f"Can't call `to_be_base64_TODO` in { Mode .readonly } mode!" )
205203 actual_bytes = self .actual .subject_or_facet (self .only_facet ).value_binary ()
206204 actual_b64 = base64 .b64encode (actual_bytes ).decode ().replace ("\r " , "" )
207205 _toBeDidntMatch (None , actual_b64 , LiteralString ())
208206 return actual_bytes
209207
210- def to_be_file (self , subpath : str ) -> bytes :
208+ def to_be_file_impl (self , subpath : str , is_todo : bool ) -> bytes :
211209 call = recordCall (False )
212- writable = _selfieSystem ().mode .can_write (False , call , _selfieSystem ())
213210 actual_bytes = self .actual .subject_or_facet (self .only_facet ).value_binary ()
214- root_folder = (
215- _selfieSystem ().layout .sourcefile_for_call (call .location ).parent_folder ()
216- )
217- path = root_folder .resolve_file (subpath )
218-
219- if writable :
220- _selfieSystem ().write_to_be_file (path , actual_bytes , call )
221- return actual_bytes
222- else :
211+ writable = _selfieSystem ().mode .can_write (is_todo , call , _selfieSystem ())
212+ if is_todo and not writable :
213+ raise AssertionError (f"Can't call `to_be_file_TODO` in { Mode .readonly } mode!" )
214+ if not writable :
215+ path = _selfieSystem ().layout .sourcefile_for_call (call .location ).parent_folder ().resolve_file (subpath )
223216 if not _selfieSystem ().fs .file_exists (path ):
224217 raise _selfieSystem ().fs .assert_failed (
225218 _selfieSystem ().mode .msg_snapshot_not_found_no_such_file (path )
@@ -229,25 +222,24 @@ def to_be_file(self, subpath: str) -> bytes:
229222 return actual_bytes
230223 else :
231224 raise _selfieSystem ().fs .assert_failed (
232- _selfieSystem ().mode .msg_snapshot_mismatch (), expected , actual_bytes
225+ _selfieSystem ().mode .msg_snapshot_mismatch (expected , actual_bytes ),
226+ expected ,
227+ actual_bytes
233228 )
229+ else :
230+ if is_todo :
231+ _selfieSystem ().write_inline (TodoStub .to_be_file .create_literal (), call )
232+ _selfieSystem ().write_to_be_file (_selfieSystem ().layout .sourcefile_for_call (call .location ).parent_folder ().resolve_file (subpath ), actual_bytes , call )
233+ return actual_bytes
234234
235235 def to_be_file_TODO (self , subpath : str ) -> bytes :
236236 call = recordCall (False )
237237 if not _selfieSystem ().mode .can_write (True , call , _selfieSystem ()):
238- raise _selfieSystem ().fs .assert_failed (
239- f"Can't call `to_be_file_TODO` in { _selfieSystem ().mode } mode!"
240- )
241- actual_bytes = self .actual .subject_or_facet (self .only_facet ).value_binary ()
242- root_folder = (
243- _selfieSystem ()
244- .layout .sourcefile_for_call (call .location )
245- .parent_folder ()
246- )
247- path = root_folder .resolve_file (subpath )
248- _selfieSystem ().write_to_be_file (path , actual_bytes , call )
249- _selfieSystem ().write_inline (TodoStub .to_be_file .create_literal (), call )
250- return actual_bytes
238+ raise AssertionError (f"Can't call `to_be_file_TODO` in { Mode .readonly } mode!" )
239+ return self .to_be_file_impl (subpath , True )
240+
241+ def to_be_file (self , subpath : str ) -> bytes :
242+ return self .to_be_file_impl (subpath , False )
251243
252244
253245def _checkSrc (value : T ) -> T :
0 commit comments