Skip to content

Commit 071a3c0

Browse files
committed
cp to tests
1 parent 9392959 commit 071a3c0

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

tests/test_external_class.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
from nose.tools import assert_true, assert_list_equal
2+
from numpy.testing import assert_almost_equal
3+
import datajoint as dj
4+
from . import schema_external as modu
5+
6+
7+
def setUp(self):
8+
dj.config["stores"] = modu.stores_config
9+
10+
11+
def test_heading():
12+
heading = modu.Simple().heading
13+
assert_true("item" in heading)
14+
assert_true(heading["item"].is_external)
15+
16+
17+
def test_insert_and_fetch():
18+
original_list = [1, 3, 8]
19+
modu.Simple().insert1(dict(simple=1, item=original_list))
20+
# test fetch
21+
q = (modu.Simple() & {"simple": 1}).fetch("item")[0]
22+
assert_list_equal(list(q), original_list)
23+
# test fetch1 as a tuple
24+
q = (modu.Simple() & {"simple": 1}).fetch1("item")
25+
assert_list_equal(list(q), original_list)
26+
# test fetch1 as a dict
27+
q = (modu.Simple() & {"simple": 1}).fetch1()
28+
assert_list_equal(list(q["item"]), original_list)
29+
# test without cache
30+
previous_cache = dj.config["cache"]
31+
dj.config["cache"] = None
32+
q = (modu.Simple() & {"simple": 1}).fetch1()
33+
assert_list_equal(list(q["item"]), original_list)
34+
# test with cache
35+
dj.config["cache"] = previous_cache
36+
q = (modu.Simple() & {"simple": 1}).fetch1()
37+
assert_list_equal(list(q["item"]), original_list)
38+
39+
40+
def test_populate():
41+
image = modu.Image()
42+
image.populate()
43+
remaining, total = image.progress()
44+
assert_true(total == len(modu.Dimension() * modu.Seed()) and remaining == 0)
45+
for img, neg, dimensions in zip(
46+
*(image * modu.Dimension()).fetch("img", "neg", "dimensions")
47+
):
48+
assert_list_equal(list(img.shape), list(dimensions))
49+
assert_almost_equal(img, -neg)
50+
image.delete()
51+
dj.errors._switch_filepath_types(True)
52+
for external_table in image.external.values():
53+
external_table.delete(display_progress=False, delete_external_files=True)
54+
dj.errors._switch_filepath_types(False)

0 commit comments

Comments
 (0)