Skip to content
Snippets Groups Projects

draft: Basic dataset

Open Florian Ziemen requested to merge basic_dataset into main
Files
8
+ 59
0
import dataset
import unittest
from serde.yaml import from_yaml, to_yaml
class test_dataset(unittest.TestCase):
dsl1 = dataset.dataset_location(method="direct", host="local", path="/scratch/")
dsl2 = dataset.dataset_location(method="direct", host="local", path="/work/")
ds = dataset.dataset(name="test_ds", serve=True, locations=(dsl1, dsl2))
def test_dataset(self):
dsl1 = test_dataset.dsl1
ds = dataset.dataset(name="test_ds", serve=True, locations=(dsl1,))
self.assertTrue(ds.is_valid())
ds = test_dataset.ds
self.assertTrue(ds.is_valid())
def test_bad_dataset_location(self):
badhost = dataset.dataset_location(method="direct", host=None, path="/scratch/")
self.assertFalse(badhost.is_valid())
badpath = dataset.dataset_location(method="direct", host="local", path=None)
self.assertFalse(badpath.is_valid())
badmethod = dataset.dataset_location(method=None, host="local", path="/scratch")
self.assertFalse(badmethod.is_valid())
def test_bad_dataset(self):
dsl1 = dataset.dataset_location(method="direct", host="local", path="/scratch/")
bad_name = dataset.dataset(name=None, serve=True, locations=(dsl1,))
self.assertFalse(bad_name.is_valid())
bad_serve = dataset.dataset(name="test", serve=7, locations=(dsl1,))
self.assertFalse(bad_serve.is_valid())
with self.assertRaises(TypeError):
bad_location = dataset.dataset(name=None, serve=True, locations=dsl1)
badpath = dataset.dataset_location(method="direct", host="local", path=None)
bad_location = dataset.dataset(name=None, serve=True, locations=(badpath,))
self.assertFalse(bad_location.is_valid())
with self.assertRaises(TypeError):
bad_location = dataset.dataset(name=None, serve=True, locations=(None,))
def test_to_from_yaml(self):
ds = test_dataset.ds
with open("test.yaml", "w") as of:
of.write(to_yaml(ds))
with open("test.yaml", "r") as infile:
obj = from_yaml(dataset.dataset, infile.read())
self.assertEqual(obj, ds)
if __name__ == "__main__":
unittest.main()
Loading