-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest_header.py
203 lines (150 loc) · 6.86 KB
/
test_header.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# coding: utf-8
import datetime
import unittest
import sys
import fastobo
# --- HeaderFrame ------------------------------------------------------------
class TestHeaderFrame(unittest.TestCase):
type = fastobo.header.HeaderFrame
def test_init(self):
try:
frame = fastobo.header.HeaderFrame([])
except Exception:
self.fail("could not create `HeaderFrame` instance")
try:
frame = fastobo.header.HeaderFrame()
except Exception:
self.fail("could not create `HeaderFrame` instance")
try:
frame = fastobo.header.HeaderFrame((
fastobo.header.FormatVersionClause("1.2"),
fastobo.header.SavedByClause("Martin Larralde"),
))
except Exception:
self.fail("could not create `HeaderFrame` instance from iterable")
def test_init_type_error(self):
self.assertRaises(TypeError, self.type, 1)
self.assertRaises(TypeError, self.type, [1])
self.assertRaises(TypeError, self.type, ["abc"])
self.assertRaises(TypeError, self.type, "abc")
# --- HeaderClause -----------------------------------------------------------
class _TestUnquotedStringClause(object):
type = NotImplemented
def test_init(self):
try:
vc = self.type("1.2")
except Exception:
self.fail("could not create `{}` instance", self.type.__name__)
def test_init_type_error(self):
self.assertRaises(TypeError, self.type, 1)
self.assertRaises(TypeError, self.type, [])
def test_repr(self):
x = self.type("abc")
r = self.type.__name__
if sys.implementation.name == "pypy":
r = r.split(".")[-1]
self.assertEqual(repr(x), "{}('abc')".format(r))
def test_eq(self):
x = self.type("1.2")
self.assertEqual(x, x)
y = self.type("1.2")
self.assertEqual(x, y)
z = self.type("1.4")
self.assertNotEqual(x, z)
self.assertNotEqual(y, z)
# --- FormatVersion ----------------------------------------------------------
class TestFormatVersionClause(_TestUnquotedStringClause, unittest.TestCase):
type = fastobo.header.FormatVersionClause
def test_str(self):
vc = fastobo.header.FormatVersionClause("1.2")
self.assertEqual(str(vc), "format-version: 1.2")
vc = fastobo.header.FormatVersionClause("x:y")
self.assertEqual(str(vc), "format-version: x:y")
def test_property_version(self):
vc1 = self.type("1.2")
self.assertEqual(vc1.version, "1.2")
vc1.version = "1.3"
self.assertEqual(vc1.version, "1.3")
self.assertEqual(repr(vc1), "FormatVersionClause('1.3')")
def test_raw_tag(self):
vc = self.type("1.2")
self.assertEqual(vc.raw_tag(), "format-version")
# --- DataVersion ------------------------------------------------------------
class TestDataVersionClause(_TestUnquotedStringClause, unittest.TestCase):
type = fastobo.header.DataVersionClause
def test_str(self):
x = self.type("4.0")
self.assertEqual(str(x), "data-version: 4.0")
def test_property_version(self):
vc1 = self.type("1.2")
self.assertEqual(vc1.version, "1.2")
vc1.version = "1.3"
self.assertEqual(vc1.version, "1.3")
self.assertEqual(repr(vc1), "DataVersionClause('1.3')")
def test_raw_tag(self):
vc = self.type("1.2")
self.assertEqual(vc.raw_tag(), "data-version")
# --- Date -------------------------------------------------------------------
class TestDateClause(unittest.TestCase):
type = fastobo.header.DateClause
def test_init(self):
try:
vc = self.type(datetime.datetime.now())
except Exception:
self.fail("could not create `{}` instance", self.type.__name__)
def test_init_type_error(self):
self.assertRaises(TypeError, self.type, 1)
self.assertRaises(TypeError, self.type, [])
@unittest.expectedFailure
def test_repr(self):
now = datetime.datetime.now()
x = self.type(now)
self.assertEqual(repr(x), "{}({!r})".format(self.type.__name__, now))
@unittest.expectedFailure
def test_eq(self):
now = datetime.datetime.now()
x = self.type(now)
self.assertEqual(x, self.type(now))
self.assertNotEqual(x, self.type(datetime.datetime.now()))
def test_str(self):
then = datetime.datetime(2019, 4, 8, 16, 51)
vc = self.type(then)
self.assertEqual(str(vc), "date: 08:04:2019 16:51")
@unittest.expectedFailure
def test_property_version(self):
now = datetime.datetime.now()
vc1 = self.type(now)
self.assertEqual(vc1.date, now)
then = datetime.datetime(2019, 4, 8, 16, 51)
vc1.date = then
self.assertEqual(vc1.date, then)
with self.assertRaises(TypeError):
vc1.date = 1
# --- SavedBy ----------------------------------------------------------------
class TestSavedByClause(_TestUnquotedStringClause, unittest.TestCase):
type = fastobo.header.SavedByClause
# --- AutoGeneratedBy --------------------------------------------------------
class TestAutoGeneratedByClause(_TestUnquotedStringClause, unittest.TestCase):
type = fastobo.header.AutoGeneratedByClause
# --- Import -----------------------------------------------------------------
# --- Subsetdef --------------------------------------------------------------
# --- SynonymTypedef ---------------------------------------------------------
# --- DefaultNamespace -------------------------------------------------------
# --- IdspaceClause ----------------------------------------------------------
# --- TreatXrefsAsEquivalentClause -------------------------------------------
# --- TreatXrefsAsGenusDifferentiaClause -------------------------------------
# --- TreatXrefsAsReverseGenusDifferentiaClause ------------------------------
# --- TreatXrefsAsRelationshipClause -----------------------------------------
# --- TreatXrefsAsIsA --------------------------------------------------------
# --- TreatXrefsAsHasSubclassClause ------------------------------------------
# --- PropertyValue ----------------------------------------------------------
# --- Remark -----------------------------------------------------------------
class TestRemarkClause(_TestUnquotedStringClause, unittest.TestCase):
type = fastobo.header.RemarkClause
# --- Ontology ---------------------------------------------------------------
class TestOntologyClause(_TestUnquotedStringClause, unittest.TestCase):
type = fastobo.header.OntologyClause
# --- OwlAxioms --------------------------------------------------------------
class TestOwlAxiomsClause(_TestUnquotedStringClause, unittest.TestCase):
type = fastobo.header.OwlAxiomsClause
# --- UnreservedClause -------------------------------------------------------