def test_meta_information(): description = {"author": "testing", "description": "here goes the testing text"} description_changed = { "author": "changed author", "description": "now it's changed", } schema = {"text": Text((None,), max_shape=(1000,))} ds = Dataset( "./data/test_meta", shape=(10,), schema=schema, meta_information=description, mode="w", ) some_text = ["hello world", "hello penguin", "hi penguin"] for i, text in enumerate(some_text): ds["text", i] = text assert type(ds.meta["meta_info"]) == dict assert ds.meta["meta_info"]["author"] == "testing" assert ds.meta["meta_info"]["description"] == "here goes the testing text" ds.close()
def test_dataset_append_and_read(): dt = {"first": "float", "second": "float"} os.makedirs("./data/test/test_dataset_append_and_read", exist_ok=True) shutil.rmtree("./data/test/test_dataset_append_and_read") ds = Dataset( schema=dt, shape=(2,), url="./data/test/test_dataset_append_and_read", mode="a", ) ds["first"][0] = 2.3 ds.meta_information["description"] = "This is my description" assert ds.meta_information["description"] == "This is my description" assert ds["second"][0].numpy() != 2.3 ds.close() ds = Dataset( url="./data/test/test_dataset_append_and_read", mode="r", ) assert ds.meta_information["description"] == "This is my description" ds.meta_information["hello"] = 5 ds.delete() ds.close()
def test_dataset_bug_3(url="./data/test/dataset", token=None): my_schema = { "image": Tensor((100, 100), "uint8"), } ds = Dataset(url, token=token, shape=(10000,), mode="w", schema=my_schema) ds.close() ds = Dataset(url) ds["image", 0:1] = [np.zeros((100, 100))]
def test_dataset_wrong_append(url="./data/test/dataset", token=None): my_schema = { "image": Tensor((100, 100), "uint8"), } ds = Dataset(url, token=token, shape=(10000, ), mode="w", schema=my_schema) ds.close() with pytest.raises(TypeError): ds = Dataset(url, shape=100) with pytest.raises(SchemaMismatchException): ds = Dataset(url, schema={"hello": "uint8"})
def test_dataset(url="./data/test/dataset", token=None, public=True): ds = Dataset( url, token=token, shape=(10000,), mode="w", schema=my_schema, public=public ) sds = ds[5] sds["label/a", 50, 50] = 2 assert sds["label", 50, 50, "a"].numpy() == 2 ds["image", 5, 4, 100:200, 150:300, :] = np.ones((100, 150, 3), "uint8") assert ( ds["image", 5, 4, 100:200, 150:300, :].numpy() == np.ones((100, 150, 3), "uint8") ).all() ds["image", 8, 6, 500:550, 700:730] = np.ones((50, 30, 3)) subds = ds[3:15] subsubds = subds[4:9] assert ( subsubds["image", 1, 6, 500:550, 700:730].numpy() == np.ones((50, 30, 3)) ).all() subds = ds[5:7] ds["image", 6, 3:5, 100:135, 700:720] = 5 * np.ones((2, 35, 20, 3)) assert ( subds["image", 1, 3:5, 100:135, 700:720].numpy() == 5 * np.ones((2, 35, 20, 3)) ).all() ds["label", "c"] = 4 * np.ones((10000, 5, 3), "uint8") assert (ds["label/c"].numpy() == 4 * np.ones((10000, 5, 3), "uint8")).all() ds["label", "c", 2, 4] = 6 * np.ones((3)) sds = ds["label", "c"] ssds = sds[1:3, 4] sssds = ssds[1] assert (sssds.numpy() == 6 * np.ones((3))).all() ds.save() sds = ds["/label", 5:15, "c"] sds[2:4, 4, :] = 98 * np.ones((2, 3)) assert (ds[7:9, 4, "label", "/c"].numpy() == 98 * np.ones((2, 3))).all() labels = ds["label", 1:5] d = labels["d"] e = d["e"] e[:] = 77 * np.ones((4, 5, 3)) assert (e.numpy() == 77 * np.ones((4, 5, 3))).all() ds.close()
def test_dataset_wrong_append(url="./data/test/dataset", token=None): my_schema = { "image": Tensor((100, 100), "uint8"), } ds = Dataset(url, token=token, shape=(10000,), mode="w", schema=my_schema) ds.close() try: ds = Dataset(url, shape=100) except Exception as ex: assert isinstance(ex, TypeError) try: ds = Dataset(url, schema={"hello": "uint8"}) except Exception as ex: assert isinstance(ex, TypeError)
def test_dataset_append_and_read(): dt = {"first": "float", "second": "float"} ds = Dataset( schema=dt, shape=(2,), url="./data/test/test_dataset_append_and_read", mode="a", ) ds["first"][0] = 2.3 assert ds["second"][0].numpy() != 2.3 ds.close() ds = Dataset( url="./data/test/test_dataset_append_and_read", mode="r", ) ds.delete() ds.close()