@@ -174,23 +174,75 @@ def test_file_dbnstore_given_valid_path_initialized_expected_data(
174174 assert dbnstore .nbytes == 189
175175
176176
177+ @pytest .mark .parametrize (
178+ "schema,expected_size" ,
179+ [
180+ (Schema .MBO , 189 ),
181+ (Schema .DEFINITION , 290 ),
182+ ],
183+ )
177184def test_to_file_persists_to_disk (
178185 test_data : Callable [[Dataset , Schema ], bytes ],
179186 tmp_path : Path ,
187+ schema : Schema ,
188+ expected_size : int ,
180189) -> None :
190+ """
191+ Test the DBNStore.to_file writes files to disk.
192+ """
181193 # Arrange
182- stub_data = test_data (Dataset .GLBX_MDP3 , Schema . MBO )
194+ stub_data = test_data (Dataset .GLBX_MDP3 , schema )
183195 dbnstore = DBNStore .from_bytes (data = stub_data )
184196
185197 # Act
186198 dbn_path = tmp_path / "my_test.dbn"
187199 dbnstore .to_file (path = dbn_path )
188200
201+ # Assert
202+ assert dbn_path .exists ()
203+ assert dbn_path .stat ().st_size == expected_size
204+
205+
206+ def test_to_file_overwrite (
207+ test_data : Callable [[Dataset , Schema ], bytes ],
208+ tmp_path : Path ,
209+ ) -> None :
210+ """
211+ Test that the default write mode allows files to be overwritten.
212+ """
213+ # Arrange
214+ stub_data = test_data (Dataset .GLBX_MDP3 , Schema .MBO )
215+ dbnstore = DBNStore .from_bytes (data = stub_data )
216+ dbn_path = tmp_path / "my_test.dbn"
217+ dbnstore .to_file (path = dbn_path )
218+ assert dbn_path .stat ().st_size == 189
219+
220+ # Act
221+ dbnstore .to_file (path = dbn_path )
222+
189223 # Assert
190224 assert dbn_path .exists ()
191225 assert dbn_path .stat ().st_size == 189
192226
193227
228+ def test_to_file_exclusive (
229+ test_data : Callable [[Dataset , Schema ], bytes ],
230+ tmp_path : Path ,
231+ ) -> None :
232+ """
233+ Test that the exclusive write mode correctly rejects an existing file path.
234+ """
235+ # Arrange
236+ stub_data = test_data (Dataset .GLBX_MDP3 , Schema .MBO )
237+ dbnstore = DBNStore .from_bytes (data = stub_data )
238+ dbn_path = tmp_path / "my_test.dbn"
239+ dbnstore .to_file (path = dbn_path )
240+
241+ # Act, Assert
242+ with pytest .raises (FileExistsError ):
243+ dbnstore .to_file (path = dbn_path , mode = "x" )
244+
245+
194246def test_to_ndarray_with_stub_data_returns_expected_array (
195247 test_data : Callable [[Dataset , Schema ], bytes ],
196248) -> None :
0 commit comments