Skip to content

Commit 164753c

Browse files
committed
cp to tests
1 parent 20c5039 commit 164753c

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

tests/test_uuid.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
from nose.tools import assert_true, assert_equal, raises
2+
import uuid
3+
from .schema_uuid import Basic, Item, Topic
4+
from datajoint import DataJointError
5+
from itertools import count
6+
7+
8+
def test_uuid():
9+
"""test inserting and fetching of UUID attributes and restricting by UUID attributes"""
10+
u, n = uuid.uuid4(), -1
11+
Basic().insert1(dict(item=u, number=n))
12+
Basic().insert(zip(map(uuid.uuid1, range(20)), count()))
13+
number = (Basic() & {"item": u}).fetch1("number")
14+
assert_equal(number, n)
15+
item = (Basic & {"number": n}).fetch1("item")
16+
assert_equal(u, item)
17+
18+
19+
def test_string_uuid():
20+
"""test that only UUID objects are accepted when inserting UUID fields"""
21+
u, n = "00000000-0000-0000-0000-000000000000", 24601
22+
Basic().insert1(dict(item=u, number=n))
23+
k, m = (Basic & {"item": u}).fetch1("KEY", "number")
24+
assert_equal(m, n)
25+
assert_true(isinstance(k["item"], uuid.UUID))
26+
27+
28+
@raises(DataJointError)
29+
def test_invalid_uuid_insert1():
30+
"""test that only UUID objects are accepted when inserting UUID fields"""
31+
u, n = 0, 24601
32+
Basic().insert1(dict(item=u, number=n))
33+
34+
35+
@raises(DataJointError)
36+
def test_invalid_uuid_insert2():
37+
"""test that only UUID objects are accepted when inserting UUID fields"""
38+
u, n = "abc", 24601
39+
Basic().insert1(dict(item=u, number=n))
40+
41+
42+
@raises(DataJointError)
43+
def test_invalid_uuid_restrict1():
44+
"""test that only UUID objects are accepted when inserting UUID fields"""
45+
u = 0
46+
k, m = (Basic & {"item": u}).fetch1("KEY", "number")
47+
48+
49+
@raises(DataJointError)
50+
def test_invalid_uuid_restrict1():
51+
"""test that only UUID objects are accepted when inserting UUID fields"""
52+
u = "abc"
53+
k, m = (Basic & {"item": u}).fetch1("KEY", "number")
54+
55+
56+
def test_uuid_dependencies():
57+
"""test the use of UUID in foreign keys"""
58+
for word in (
59+
"Neuroscience",
60+
"Knowledge",
61+
"Curiosity",
62+
"Inspiration",
63+
"Science",
64+
"Philosophy",
65+
"Conscience",
66+
):
67+
Topic().add(word)
68+
Item.populate()
69+
assert_equal(Item().progress(), (0, len(Topic())))

0 commit comments

Comments
 (0)