-
Notifications
You must be signed in to change notification settings - Fork 96
Expand file tree
/
Copy pathtest_uuid.py
More file actions
72 lines (55 loc) · 2.14 KB
/
Copy pathtest_uuid.py
File metadata and controls
72 lines (55 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import uuid
from itertools import count
import pytest
from datajoint import DataJointError
from tests.schema_uuid import Basic, Item, Topic
def test_uuid(schema_uuid):
"""test inserting and fetching of UUID attributes and restricting by UUID attributes"""
u, n = uuid.uuid4(), -1
Basic().insert1(dict(item=u, number=n))
Basic().insert(zip(map(uuid.uuid1, range(20)), count()))
number = (Basic() & {"item": u}).fetch1("number")
assert number == n
item = (Basic & {"number": n}).fetch1("item")
assert u == item
def test_string_uuid(schema_uuid):
"""test that only UUID objects are accepted when inserting UUID fields"""
u, n = "00000000-0000-0000-0000-000000000000", 24601
Basic().insert1(dict(item=u, number=n))
k, m = (Basic & {"item": u}).fetch1("KEY", "number")
assert m == n
assert isinstance(k["item"], uuid.UUID)
def test_invalid_uuid_insert1(schema_uuid):
"""test that only UUID objects are accepted when inserting UUID fields"""
u, n = 0, 24601
with pytest.raises(DataJointError):
Basic().insert1(dict(item=u, number=n))
def test_invalid_uuid_insert2(schema_uuid):
"""test that only UUID objects are accepted when inserting UUID fields"""
u, n = "abc", 24601
with pytest.raises(DataJointError):
Basic().insert1(dict(item=u, number=n))
def test_invalid_uuid_restrict1(schema_uuid):
"""test that only UUID objects are accepted when inserting UUID fields"""
u = 0
with pytest.raises(DataJointError):
k, m = (Basic & {"item": u}).fetch1("KEY", "number")
def test_invalid_uuid_restrict2(schema_uuid):
"""test that only UUID objects are accepted when inserting UUID fields"""
u = "abc"
with pytest.raises(DataJointError):
k, m = (Basic & {"item": u}).fetch1("KEY", "number")
def test_uuid_dependencies(schema_uuid):
"""test the use of UUID in foreign keys"""
for word in (
"Neuroscience",
"Knowledge",
"Curiosity",
"Inspiration",
"Science",
"Philosophy",
"Conscience",
):
Topic().add(word)
Item.populate()
assert Item().progress() == (0, len(Topic()))