1313
1414
1515def test_cache_files_empty (tmp_path : Path ):
16- cache = FileCache (tmp_path )
16+ cache = FileCache (
17+ tmp_path ,
18+ schema = None , # type: ignore - testing
19+ batch_size = None , # type: ignore - testing
20+ rows_per_file = None , # type: ignore - testing
21+ compression = None , # type: ignore - testing
22+ )
1723 assert cache ._path == tmp_path
1824 assert cache .get_files () == []
1925 assert cache .get_dataset_files () == []
@@ -22,7 +28,13 @@ def test_cache_files_empty(tmp_path: Path):
2228
2329def test_cache_files_does_not_exist (tmp_path : Path ):
2430 path = tmp_path / "does_not_exist"
25- cache = FileCache (path )
31+ cache = FileCache (
32+ path ,
33+ schema = None , # type: ignore - testing
34+ batch_size = None , # type: ignore - testing
35+ rows_per_file = None , # type: ignore - testing
36+ compression = None , # type: ignore - testing
37+ )
2638 assert cache ._path == path
2739 assert cache .get_files () == []
2840 assert cache .get_dataset_files () == []
@@ -93,6 +105,7 @@ def test_cache_reader(tmp_path: Path):
93105 ]
94106
95107 assert reader .count_rows () == 202
108+ assert reader .count_tables () == 2
96109 assert reader ._schema == schema
97110
98111
@@ -167,11 +180,13 @@ def test_cache_write_columns(tmp_path: Path):
167180 "some_str" : pa .array ([f"str{ i } " ]),
168181 }
169182 )
183+ writer .write_columns ({})
170184 writer .flush ()
171185 assert len (writer .get_files ()) == 11
172186
173187 reader = FileCacheReader .load (writer .path )
174188 assert reader .count_rows () == 1000
189+ assert reader .count_tables () == 10
175190 for idx , tbl in enumerate (reader .iterate_tables ()):
176191 assert tbl ["some_int" ].to_pylist () == [
177192 i
@@ -221,6 +236,7 @@ def test_cache_write_rows(tmp_path: Path):
221236
222237 reader = FileCacheReader .load (writer .path )
223238 assert reader .count_rows () == 1000
239+ assert reader .count_tables () == 10
224240 for idx , tbl in enumerate (reader .iterate_tables ()):
225241 assert tbl ["some_int" ].to_pylist () == [
226242 i
@@ -269,6 +285,7 @@ def test_cache_write_table(tmp_path: Path):
269285
270286 reader = FileCacheReader .load (writer .path )
271287 assert reader .count_rows () == 202
288+ assert reader .count_tables () == 2
272289 for tbl in reader .iterate_tables ():
273290 assert tbl ["some_int" ].to_pylist () == [i for i in range (101 )]
274291 assert tbl ["some_float" ].to_pylist () == [i for i in range (101 )]
@@ -281,6 +298,33 @@ def test_cache_delete(tmp_path: Path):
281298 batch_size = 10
282299 rows_per_file = 100
283300 path = tmp_path / "cache"
301+
302+ FileCacheWriter .create (
303+ path = path ,
304+ schema = pa .schema (
305+ [
306+ ("some_int" , pa .int64 ()),
307+ ("some_float" , pa .float64 ()),
308+ ("some_str" , pa .string ()),
309+ ]
310+ ),
311+ batch_size = batch_size ,
312+ rows_per_file = rows_per_file ,
313+ )
314+ with pytest .raises (FileExistsError ):
315+ FileCacheWriter .create (
316+ path = path ,
317+ schema = pa .schema (
318+ [
319+ ("some_int" , pa .int64 ()),
320+ ("some_float" , pa .float64 ()),
321+ ("some_str" , pa .string ()),
322+ ]
323+ ),
324+ batch_size = batch_size ,
325+ rows_per_file = rows_per_file ,
326+ )
327+
284328 with FileCacheWriter .create (
285329 path = path ,
286330 schema = pa .schema (
@@ -292,6 +336,7 @@ def test_cache_delete(tmp_path: Path):
292336 ),
293337 batch_size = batch_size ,
294338 rows_per_file = rows_per_file ,
339+ delete_if_exists = True ,
295340 ) as writer :
296341 tbl = pa .Table .from_pylist (
297342 [
@@ -311,6 +356,7 @@ def test_cache_delete(tmp_path: Path):
311356
312357 reader = FileCacheReader .load (path = writer .path )
313358 assert reader .count_rows () == 202
359+ assert reader .count_tables () == 2
314360 for tbl in reader .iterate_tables ():
315361 assert tbl ["some_int" ].to_pylist () == [i for i in range (101 )]
316362 assert tbl ["some_float" ].to_pylist () == [i for i in range (101 )]
0 commit comments