Skip to content

Commit 8d4603b

Browse files
committed
Fix some issues in tests
1 parent 4f509cf commit 8d4603b

2 files changed

Lines changed: 17 additions & 11 deletions

File tree

src/blosc2/ctable.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,6 +1063,11 @@ def __init__(
10631063

10641064
# Choose storage backend
10651065
if urlpath is not None:
1066+
if mode == "w" and os.path.exists(urlpath):
1067+
if os.path.isdir(urlpath):
1068+
shutil.rmtree(urlpath)
1069+
else:
1070+
os.remove(urlpath)
10661071
storage: TableStorage = FileTableStorage(urlpath, mode)
10671072
else:
10681073
storage = InMemoryTableStorage()

tests/ctable/test_table_persistency.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,19 @@ def test_create_layout_files_exist():
5959
t = CTable(Row, urlpath=path, mode="w", expected_size=16)
6060
t.append((1, 50.0, True))
6161

62-
assert os.path.exists(os.path.join(path, "_meta.b2frame"))
62+
assert os.path.exists(os.path.join(path, "_meta.b2f"))
6363
assert os.path.exists(os.path.join(path, "_valid_rows.b2nd"))
6464
assert os.path.exists(os.path.join(path, "_cols", "id.b2nd"))
6565
assert os.path.exists(os.path.join(path, "_cols", "score.b2nd"))
6666
assert os.path.exists(os.path.join(path, "_cols", "active.b2nd"))
6767

6868

6969
def test_schema_saved_in_meta_vlmeta():
70-
"""Schema JSON and kind marker are present in _meta.b2frame."""
70+
"""Schema JSON and kind marker are present in _meta.b2f."""
7171
path = table_path("people")
7272
CTable(Row, urlpath=path, mode="w", expected_size=16)
7373

74-
meta = blosc2.open(os.path.join(path, "_meta.b2frame"))
74+
meta = blosc2.open(os.path.join(path, "_meta.b2f"), mode="r")
7575
assert meta.vlmeta["kind"] == "ctable"
7676
assert meta.vlmeta["version"] == 1
7777
schema = json.loads(meta.vlmeta["schema"])
@@ -204,7 +204,7 @@ def test_valid_rows_persisted():
204204
t.delete(1) # mark row 1 (id=2) as invalid
205205

206206
# _valid_rows on disk: slots 0 and 2 are True, slot 1 is False
207-
vr = blosc2.open(os.path.join(path, "_valid_rows.b2nd"))
207+
vr = blosc2.open(os.path.join(path, "_valid_rows.b2nd"), mode="r")
208208
raw = vr[:3]
209209
assert raw[0]
210210
assert not raw[1]
@@ -299,15 +299,16 @@ def test_open_nonexistent_raises():
299299

300300

301301
def test_open_wrong_kind_raises(tmp_path):
302-
"""A path with a _meta.b2frame that is not a ctable raises ValueError."""
303-
import blosc2
304-
305-
meta_path = str(tmp_path / "_meta.b2frame")
306-
sc = blosc2.SChunk(urlpath=meta_path, mode="w")
302+
"""A path with a _meta.b2f that is not a ctable raises ValueError."""
303+
path = str(tmp_path / "fake_table")
304+
store = blosc2.TreeStore(path, mode="w", threshold=0)
305+
sc = blosc2.SChunk()
307306
sc.vlmeta["kind"] = "something_else"
307+
store["/_meta"] = sc
308+
store.close()
308309

309310
with pytest.raises(ValueError, match="CTable"):
310-
CTable.open(str(tmp_path))
311+
CTable.open(path)
311312

312313

313314
# ---------------------------------------------------------------------------
@@ -386,7 +387,7 @@ def test_save_creates_disk_layout():
386387
path = table_path("saved")
387388
t.save(path)
388389

389-
assert os.path.exists(os.path.join(path, "_meta.b2frame"))
390+
assert os.path.exists(os.path.join(path, "_meta.b2f"))
390391
assert os.path.exists(os.path.join(path, "_valid_rows.b2nd"))
391392
assert os.path.exists(os.path.join(path, "_cols", "id.b2nd"))
392393
assert os.path.exists(os.path.join(path, "_cols", "score.b2nd"))

0 commit comments

Comments
 (0)