Skip to content

Commit

Permalink
yews.files under cover.
Browse files Browse the repository at this point in the history
  • Loading branch information
lijunzh committed Apr 17, 2019
1 parent 744daae commit e9ebf46
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
Binary file added tests/assets/array/data.npy
Binary file not shown.
27 changes: 26 additions & 1 deletion tests/test_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,13 @@ def build_dataset(self):
return DummpyDatasetlike(), DummpyDatasetlike()

def test_root_is_path(self):
# check existing path
dset = self.DummyPathDataset(root='.')
# check path resolved
assert dset.root == Path(dset.root).resolve()
# check non-existing path
with pytest.raises(ValueError):
dset = self.DummyPathDataset(root='abc')


class TestDirDataset:
Expand All @@ -127,7 +132,7 @@ def build_dataset(self):
def test_dir_check(self):
dset = self.DummyDirDataset(root='.')
with pytest.raises(ValueError):
dset = self.DummyDirDataset(root='abc')
dset = self.DummyDirDataset(root='setup.py')


class TestDatasetArrayFolder:
Expand All @@ -143,3 +148,23 @@ def test_loading_folder(self):
dset = datasets.DatasetFolder(root=root_dir/ 'folder', loader=np.load)
assert all([dset[0][0].shape == (3, 100), type(dset[0][1]) is str])


class TestFileDataset:

class DummpyFileDataset(datasets.FileDataset):

def build_dataset(self):
return DummpyDatasetlike(), DummpyDatasetlike()

def test_file_check(self):
dset = self.DummpyFileDataset(root='setup.py')
with pytest.raises(ValueError):
dset = self.DummpyFileDataset(root='.')


class TestDatasetArray:

def test_loading_array(self):
dset = datasets.DatasetArray(root=root_dir / 'array/data.npy')
assert all([dset[0][0].shape == (3, 100), dset[0][1].shape == ()])

3 changes: 3 additions & 0 deletions yews/datasets/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,6 @@ class PathDataset(BaseDataset):
def __init__(self, **kwargs):
super(PathDataset, self).__init__(**kwargs)
self.root = Path(self.root).resolve()
if not self.root.exists():
raise ValueError(f"{self.root} does not exists.")

0 comments on commit e9ebf46

Please sign in to comment.