Skip to content

Commit 5b8c221

Browse files
committed
add loading .zip test
1 parent 4d9494e commit 5b8c221

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

tests/test_hdxms_datasets.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from pathlib import Path
99
import pytest
1010
import narwhals as nw
11+
import zipfile
1112

1213

1314
# %%
@@ -33,6 +34,21 @@ def database():
3334
yield db
3435

3536

37+
@pytest.fixture()
38+
def zipped_dataset(tmp_path: Path):
39+
"""Create a zipped version of the dataset directory"""
40+
dataset_dir = TEST_PTH / "datasets" / DATA_ID
41+
zip_path = tmp_path / f"{DATA_ID}.zip"
42+
43+
with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) as zipf:
44+
for file_path in dataset_dir.rglob('*'):
45+
if file_path.is_file():
46+
arcname = file_path.relative_to(dataset_dir.parent)
47+
zipf.write(file_path, arcname)
48+
49+
yield zip_path
50+
51+
3652
def test_dataset_basic(dataset: HDXDataSet):
3753
"""Test basic dataset loading and structure"""
3854
assert isinstance(dataset, HDXDataSet)
@@ -137,4 +153,21 @@ def test_protein_identifiers(dataset: HDXDataSet):
137153
assert len(dataset.protein_identifiers.uniprot_entry_name) > 0
138154

139155

156+
def test_load_dataset_from_zip(zipped_dataset: Path):
157+
"""Test loading a dataset from a zip file"""
158+
ds = load_dataset(zipped_dataset)
159+
160+
assert isinstance(ds, HDXDataSet)
161+
assert len(ds.states) == 6
162+
163+
# Verify the loaded data structure is correct
164+
first_state = ds.states[0]
165+
assert len(first_state.peptides) == 2
166+
167+
# Verify metadata is loaded correctly
168+
assert ds.metadata is not None
169+
assert len(ds.metadata.authors) > 0
170+
assert ds.metadata.authors[0].name == "Srinath Krishnamurthy"
171+
172+
140173
# %%

0 commit comments

Comments
 (0)