Skip to content

Commit 2d80899

Browse files
committed
Use tempfiles to create artificial hdf5 file of toy data for test
1 parent 85658e7 commit 2d80899

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

tests/test_dataloaders.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,18 @@
33

44
def test_uspsdataset0_6():
55
from pathlib import Path
6+
from tempfile import TemporaryFile
67

8+
import h5py
79
import numpy as np
810

9-
datapath = Path("data/USPS")
11+
with TemporaryFile() as tf:
12+
with h5py.File(tf, "w") as f:
13+
f["train/data"] = np.random.rand(10, 16 * 16)
14+
f["train/target"] = np.array([6, 5, 4, 3, 2, 1, 0, 0, 0, 0])
1015

11-
dataset = USPSDataset0_6(data_path=datapath, train=True)
12-
assert len(dataset) == 5460
13-
data, target = dataset[0]
14-
assert data.shape == (1, 16, 16)
15-
assert all(target == np.array([0, 0, 0, 0, 0, 0, 1]))
16+
dataset = USPSDataset0_6(data_path=tf, train=True)
17+
assert len(dataset) == 10
18+
data, target = dataset[0]
19+
assert data.shape == (1, 16, 16)
20+
assert all(target == np.array([0, 0, 0, 0, 0, 0, 1]))

0 commit comments

Comments
 (0)