-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest_pv.py
116 lines (92 loc) · 3.74 KB
/
test_pv.py
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# coding: utf-8
import datetime
import unittest
import fastobo
class TestLiteralPropertyValue(unittest.TestCase):
type = fastobo.pv.LiteralPropertyValue
def test_init(self):
rel = fastobo.id.UnprefixedIdent("creation_date")
value = "2019-04-08T23:21:05Z"
dt = fastobo.id.PrefixedIdent("xsd", "date")
try:
pv = self.type(rel, value, dt)
except Exception:
self.fail("could not create `LiteralPropertyValue` instance")
def test_init_type_error(self):
rel = fastobo.id.UnprefixedIdent("creation_date")
value = "2019-04-08T23:21:05Z"
dt = fastobo.id.PrefixedIdent("xsd", "date")
self.assertRaises(TypeError, self.type, 1, value, dt)
self.assertRaises(TypeError, self.type, rel, 1, dt)
self.assertRaises(TypeError, self.type, rel, value, 1)
def test_property_relation(self):
rel = fastobo.id.UnprefixedIdent("creation_date")
value = "2019-04-08T23:21:05Z"
dt = fastobo.id.PrefixedIdent("xsd", "date")
pv = self.type(rel, value, dt)
self.assertEqual(pv.relation, rel)
rel2 = fastobo.id.PrefixedIdent("IAO", "0000219")
pv.relation = rel2
self.assertEqual(pv.relation, rel2)
with self.assertRaises(TypeError):
pv.relation = "IAO:0000219"
def test_str(self):
rel = fastobo.id.UnprefixedIdent("creation_date")
value = "2019-04-08T23:21:05Z"
dt = fastobo.id.PrefixedIdent("xsd", "date")
pv = self.type(rel, value, dt)
self.assertEqual(
str(pv),
'creation_date "2019-04-08T23:21:05Z" xsd:date'
)
def test_repr(self):
rel = fastobo.id.UnprefixedIdent("creation_date")
value = "2019-04-08T23:21:05Z"
dt = fastobo.id.PrefixedIdent("xsd", "date")
pv = self.type(rel, value, dt)
self.assertEqual(
repr(pv),
"LiteralPropertyValue("
"UnprefixedIdent('creation_date'), "
"'2019-04-08T23:21:05Z', "
"PrefixedIdent('xsd', 'date'))"
)
class TestResourcePropertyValue(unittest.TestCase):
type = fastobo.pv.ResourcePropertyValue
def test_init(self):
rel = fastobo.id.UnprefixedIdent("derived_from")
value = fastobo.id.PrefixedIdent("MS", "1000031")
try:
pv = self.type(rel, value)
except Exception:
self.fail("could not create `ResourcePropertyValue` instance")
def test_init_type_error(self):
rel = fastobo.id.UnprefixedIdent("derived_from")
value = fastobo.id.PrefixedIdent("MS", "1000031")
self.assertRaises(TypeError, self.type, 1, value)
self.assertRaises(TypeError, self.type, rel, 1)
def test_property_relation(self):
rel = fastobo.id.UnprefixedIdent("derived_from")
value = fastobo.id.PrefixedIdent("MS", "1000031")
pv = self.type(rel, value)
self.assertEqual(pv.relation, rel)
rel2 = fastobo.id.UnprefixedIdent("something")
pv.relation = rel2
self.assertEqual(pv.relation, rel2)
with self.assertRaises(TypeError):
pv.relation = "IAO:0000219"
def test_str(self):
rel = fastobo.id.UnprefixedIdent("derived_from")
value = fastobo.id.PrefixedIdent("MS", "1000031")
pv = self.type(rel, value)
self.assertEqual(str(pv), "derived_from MS:1000031")
def test_repr(self):
rel = fastobo.id.UnprefixedIdent("derived_from")
value = fastobo.id.PrefixedIdent("MS", "1000031")
pv = self.type(rel, value)
self.assertEqual(
repr(pv),
"ResourcePropertyValue("
"UnprefixedIdent('derived_from'), "
"PrefixedIdent('MS', '1000031'))"
)