DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
conffwk
scripts
test_configobject.py
Go to the documentation of this file.
1
#!/usr/bin/env python
2
# vim: set fileencoding=utf-8 :
3
# DUNE DAQ modification notice:
4
# This file has been modified from the original ATLAS config source for the DUNE DAQ project.
5
# Fork baseline commit: 67a24e731 (2022-10-27).
6
# Renamed since fork: yes (from python/tests/test_configobject.py to scripts/test_configobject.py).
7
8
# Created by Andre Anjos <andre.dos.anjos@cern.ch>
9
# Wed 24 Oct 2007 01:53:05 PM CEST
10
11
"""Unit test for the Python bindings to the ConfigObject class."""
12
13
import
os
14
import
unittest
15
import
conffwk
16
17
scriptsdir=os.path.dirname(os.path.realpath(__file__))
18
19
def
limit_test
(obj, attrname, min, max):
20
db =
conffwk.Configuration
(
"oksconflibs"
)
21
db.create_db(
'test.data.xml'
, [f
'{scriptsdir}/test.schema.xml'
])
22
23
low = db.create_obj(
"Dummy"
,
"TestDummy-Low"
)
24
low[attrname] = min
25
obj.assertEqual(low[attrname], min)
26
27
high = db.create_obj(
"Dummy"
,
"TestDummy-High"
)
28
high[attrname] = max
29
obj.assertEqual(high[attrname], max)
30
31
db.commit()
32
33
34
def
limit_test_raise
(obj, attrname, min, max):
35
db =
conffwk.Configuration
(
"oksconflibs"
)
36
filename =
'overflow_test.data.xml'
37
db.create_db(filename, [f
'{scriptsdir}/test.schema.xml'
])
38
39
low = db.create_obj(
"Dummy"
,
"TestDummy-Underflow"
)
40
41
#obj.assertRaises(OverflowError, low.__setitem__, attrname, min-1)
42
obj.assertRaises(TypeError, low.__setitem__, attrname, min-1)
43
44
high = db.create_obj(
"Dummy"
,
"TestDummy-Overflow"
)
45
#obj.assertRaises(OverflowError, high.__setitem__, attrname, max+1)
46
obj.assertRaises(TypeError, high.__setitem__, attrname, max+1)
47
48
db.commit()
49
50
51
class
ConfigObject
(unittest.TestCase):
52
53
def
test00_CanReadWriteBool
(self):
54
limit_test
(self,
'bool'
,
False
,
True
)
55
56
def
test01_CanReadWriteInt8
(self):
57
limit_test
(self,
'sint8'
, -2**7, (2**7)-1)
58
limit_test_raise
(self,
'sint8'
, -2**7, (2**7)-1)
59
60
def
test02_CanReadWriteUInt8
(self):
61
limit_test
(self,
'uint8'
, 0, (2**8)-1)
62
limit_test_raise
(self,
'uint8'
, 0, (2**8)-1)
63
64
def
test03_CanReadWriteInt16
(self):
65
limit_test
(self,
'sint16'
, -2**15, (2**15)-1)
66
limit_test_raise
(self,
'sint16'
, -2**15, (2**15)-1)
67
68
def
test04_CanReadWriteUInt16
(self):
69
limit_test
(self,
'uint16'
, 0, (2**16)-1)
70
limit_test_raise
(self,
'uint16'
, 0, (2**16)-1)
71
72
def
test05_CanReadWriteInt32
(self):
73
limit_test
(self,
'sint32'
, -2**31, (2**31)-1)
74
limit_test_raise
(self,
'sint32'
, -2**31, (2**31)-1)
75
76
def
test06_CanReadWriteUInt32
(self):
77
limit_test
(self,
'uint32'
, 0, (2**32)-1)
78
# The next test actually will fail on 32-bit machines if we set the
79
# lower limit to 0. It works OK in other platforms. The bug is related
80
# to the function PyLong_AsUnsignedLongLong() and variants that convert
81
# '-1L' to the highest possible 32-bit unsigned integer not raising an
82
# negative OverflowError as in the other convertions above.
83
# limit_test_raise(self, 'uint32', 0, (2**32)-1)
84
85
def
test07_CanReadWriteInt64
(self):
86
limit_test
(self,
'sint64'
, -2**63, (2**63)-1)
87
limit_test_raise
(self,
'sint64'
, -2**63, (2**63)-1)
88
89
def
test08_CanReadWriteUInt64
(self):
90
limit_test
(self,
'uint64'
, 0, (2**64)-1)
91
# The next test actually will fail on 64-bit machines if we set the
92
# lower limit to 0. It works OK in other platforms. The bug is related
93
# to the function PyLong_AsUnsignedLongLong() and variants that convert
94
# '-1L' to the highest possible 64-bit unsigned integer not raising an
95
# negative OverflowError as in the other convertions above.
96
# limit_test_raise(self, 'uint64', 0, (2**64)-1)
97
98
def
test08a_CanReadWriteUInt64WithRange
(self):
99
db =
conffwk.Configuration
(
"oksconflibs"
)
100
db.create_db(
"test.data.xml"
, [f
'{scriptsdir}/test.schema.xml'
])
101
t = db.create_obj(
"Dummy"
,
"TestDummy-1"
)
102
attrname =
'uint64_vector_range'
103
min = 2**64 - 16
104
max = 2**64 - 1
105
val = [min, max]
106
t[attrname] = val
107
self.assertEqual(t[attrname], val)
108
self.assertRaises(ValueError, t.__setitem__, attrname, [0, 1, 2])
109
db.commit()
110
111
def
test09_CanReadWriteString
(self):
112
db =
conffwk.Configuration
(
"oksconflibs"
)
113
db.create_db(
"test.data.xml"
, [f
'{scriptsdir}/test.schema.xml'
])
114
t = db.create_obj(
"Dummy"
,
"TestDummy-1"
)
115
val =
'bla'
116
attrname =
'string'
117
t[attrname] = val
118
self.assertEqual(t[attrname], val)
119
db.commit()
120
121
def
test10_CanReadWriteEnum
(self):
122
db =
conffwk.Configuration
(
"oksconflibs"
)
123
db.create_db(
"test.data.xml"
, [f
'{scriptsdir}/test.schema.xml'
])
124
t = db.create_obj(
"Dummy"
,
"TestDummy-1"
)
125
val =
'FIRST'
126
attrname =
'enum'
127
t[attrname] = val
128
self.assertEqual(t[attrname], val)
129
val =
'DOES NOT EXIST'
130
self.assertRaises(ValueError, t.__setitem__, attrname, val)
131
132
def
test11_CanReadWriteStringList
(self):
133
db =
conffwk.Configuration
(
"oksconflibs"
)
134
db.create_db(
"test.data.xml"
, [f
'{scriptsdir}/test.schema.xml'
])
135
t = db.create_obj(
"Dummy"
,
"TestDummy-1"
)
136
val = [
"test10"
,
"test20"
]
137
attrname =
'string_vector'
138
t[attrname] = val
139
self.assertEqual(t[attrname], val)
140
141
def
test12_CanReadWriteDate
(self):
142
db =
conffwk.Configuration
(
"oksconflibs"
)
143
db.create_db(
"test.data.xml"
, [f
'{scriptsdir}/test.schema.xml'
])
144
t = db.create_obj(
"Dummy"
,
"TestDummy-1"
)
145
val =
"2000-Jan-01"
146
attrname =
'date'
147
t[attrname] = val
148
self.assertEqual(t[attrname], val)
149
150
def
test13_CanReadWriteTime
(self):
151
db =
conffwk.Configuration
(
"oksconflibs"
)
152
db.create_db(
"test.data.xml"
, [f
'{scriptsdir}/test.schema.xml'
])
153
t = db.create_obj(
"Dummy"
,
"TestDummy-1"
)
154
val =
"2000-Jan-01 00:00:00"
155
attrname =
'time'
156
t[attrname] = val
157
self.assertEqual(t[attrname], val)
158
159
def
test14_CanReadWriteClassReference
(self):
160
db =
conffwk.Configuration
(
"oksconflibs"
)
161
db.create_db(
"test.data.xml"
, [f
'{scriptsdir}/test.schema.xml'
])
162
t = db.create_obj(
"Dummy"
,
"TestDummy-1"
)
163
val =
'Second'
164
attrname =
'classref'
165
t[attrname] = val
166
self.assertEqual(t[attrname], val)
167
self.assertRaises(ValueError, t.__setitem__, attrname,
'DoesNotExist'
)
168
db.commit()
169
170
def
test15_CanReadWriteSingleValuedRelations
(self):
171
db =
conffwk.Configuration
(
"oksconflibs"
)
172
db.create_db(
"test.data.xml"
, [f
'{scriptsdir}/test.schema.xml'
])
173
relation = db.create_obj(
"Dummy"
,
"Single-Relation"
)
174
t = db.create_obj(
'Third'
,
'Originator'
)
175
attrname =
'Another'
176
self.assertEqual(t[attrname],
None
)
# problem
177
t[attrname] = relation
178
self.assertEqual(t[attrname], relation)
179
db.commit()
180
181
def
test16_CanReadWriteMultiValuedRelations
(self):
182
db =
conffwk.Configuration
(
"oksconflibs"
)
183
db.create_db(
"test.data.xml"
, [f
'{scriptsdir}/test.schema.xml'
])
184
relations = []
185
for
i
in
range(10):
186
relations.append(db.create_obj(
"Second"
,
"Relation-%d"
% i))
187
t = db.create_obj(
'Third'
,
'Originator'
)
188
attrname =
'Seconds'
189
t[attrname] = relations
190
self.assertEqual(t[attrname], relations)
191
db.commit()
192
193
def
test17_CanRename
(self):
194
db =
conffwk.Configuration
(
"oksconflibs"
)
195
db.create_db(
"test.data.xml"
, [f
'{scriptsdir}/test.schema.xml'
])
196
t = db.create_obj(
'Dummy'
,
'TestDummy-1'
)
197
t.rename(
'TestDummy-2'
)
198
self.assertEqual(t.UID(),
'TestDummy-2'
)
199
t2 = db.get_obj(
'Dummy'
,
'TestDummy-2'
)
200
self.assertEqual(t, t2)
201
db.commit()
202
203
204
if
__name__ ==
"__main__"
:
205
import
sys
206
sys.argv.append(
'-v'
)
207
unittest.main()
conffwk.Configuration.Configuration
Definition
Configuration.py:29
test_configobject.ConfigObject
Definition
test_configobject.py:51
test_configobject.ConfigObject.test08_CanReadWriteUInt64
test08_CanReadWriteUInt64(self)
Definition
test_configobject.py:89
test_configobject.ConfigObject.test02_CanReadWriteUInt8
test02_CanReadWriteUInt8(self)
Definition
test_configobject.py:60
test_configobject.ConfigObject.test05_CanReadWriteInt32
test05_CanReadWriteInt32(self)
Definition
test_configobject.py:72
test_configobject.ConfigObject.test09_CanReadWriteString
test09_CanReadWriteString(self)
Definition
test_configobject.py:111
test_configobject.ConfigObject.test06_CanReadWriteUInt32
test06_CanReadWriteUInt32(self)
Definition
test_configobject.py:76
test_configobject.ConfigObject.test03_CanReadWriteInt16
test03_CanReadWriteInt16(self)
Definition
test_configobject.py:64
test_configobject.ConfigObject.test15_CanReadWriteSingleValuedRelations
test15_CanReadWriteSingleValuedRelations(self)
Definition
test_configobject.py:170
test_configobject.ConfigObject.test12_CanReadWriteDate
test12_CanReadWriteDate(self)
Definition
test_configobject.py:141
test_configobject.ConfigObject.test16_CanReadWriteMultiValuedRelations
test16_CanReadWriteMultiValuedRelations(self)
Definition
test_configobject.py:181
test_configobject.ConfigObject.test13_CanReadWriteTime
test13_CanReadWriteTime(self)
Definition
test_configobject.py:150
test_configobject.ConfigObject.test00_CanReadWriteBool
test00_CanReadWriteBool(self)
Definition
test_configobject.py:53
test_configobject.ConfigObject.test01_CanReadWriteInt8
test01_CanReadWriteInt8(self)
Definition
test_configobject.py:56
test_configobject.ConfigObject.test08a_CanReadWriteUInt64WithRange
test08a_CanReadWriteUInt64WithRange(self)
Definition
test_configobject.py:98
test_configobject.ConfigObject.test04_CanReadWriteUInt16
test04_CanReadWriteUInt16(self)
Definition
test_configobject.py:68
test_configobject.ConfigObject.test17_CanRename
test17_CanRename(self)
Definition
test_configobject.py:193
test_configobject.ConfigObject.test07_CanReadWriteInt64
test07_CanReadWriteInt64(self)
Definition
test_configobject.py:85
test_configobject.ConfigObject.test10_CanReadWriteEnum
test10_CanReadWriteEnum(self)
Definition
test_configobject.py:121
test_configobject.ConfigObject.test11_CanReadWriteStringList
test11_CanReadWriteStringList(self)
Definition
test_configobject.py:132
test_configobject.ConfigObject.test14_CanReadWriteClassReference
test14_CanReadWriteClassReference(self)
Definition
test_configobject.py:159
test_configobject.limit_test
limit_test(obj, attrname, min, max)
Definition
test_configobject.py:19
test_configobject.limit_test_raise
limit_test_raise(obj, attrname, min, max)
Definition
test_configobject.py:34
Generated on
for DUNE-DAQ by
1.17.0