DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
conffwk
scripts
test_configuration.py
Go to the documentation of this file.
1
#!/usr/bin/env python3
2
# DUNE DAQ modification notice:
3
# This file has been modified from the original ATLAS config source for the DUNE DAQ project.
4
# Fork baseline commit: 67a24e731 (2022-10-27).
5
# Renamed since fork: yes (from python/tests/test_configuration.py to scripts/test_configuration.py).
6
7
# Andre dos Anjos <andre.dos.anjos@cern.ch>
8
9
"""Unit test for the Python bindings to the Configuration class."""
10
11
import
os
12
import
unittest
13
import
conffwk
14
15
scriptsdir=os.path.dirname(os.path.realpath(__file__))
16
17
class
Configuration
(unittest.TestCase):
18
"""Tests if we can manipulate ConfigurationWrap objects as expected."""
19
20
def
test01_CanCreateDB
(self):
21
db =
conffwk.Configuration
(
"oksconflibs"
)
22
db.create_db(
"test.data.xml"
, [f
'{scriptsdir}/test.schema.xml'
])
23
db.commit()
24
25
def
test01a_DoesNotCrashIfDBNotThere
(self):
26
self.assertRaises(RuntimeError,
conffwk.Configuration
,
"test2.data.xml"
)
27
28
def
test02_CanReopenDB
(self):
29
db =
conffwk.Configuration
(
"oksconflibs:test.data.xml"
)
30
includes = db.get_includes(
"test.data.xml"
)
31
self.assertEqual(len(includes), 1)
32
self.assertEqual(includes[0], f
"{scriptsdir}/test.schema.xml"
)
33
34
def
test03_CanAddIncludes
(self):
35
db =
conffwk.Configuration
(
"oksconflibs:test.data.xml"
)
36
db.add_include(f
'{scriptsdir}/core.schema.xml'
)
37
includes = db.get_includes(
"test.data.xml"
)
38
print(includes)
39
self.assertEqual(len(includes), 2)
40
db.commit()
41
includes = db.get_includes(
"test.data.xml"
)
42
self.assertEqual(len(includes), 2)
43
44
def
test04_CanRemoveIncludes
(self):
45
db =
conffwk.Configuration
(
"oksconflibs:test.data.xml"
)
46
includes = db.get_includes()
47
self.assertEqual(len(includes), 2)
48
db.remove_include(includes[1])
49
db.commit()
50
includes = db.get_includes()
51
self.assertEqual(len(includes), 1)
52
53
def
test05_CanCreateObject
(self):
54
db =
conffwk.Configuration
(
"oksconflibs:test.data.xml"
)
55
for
i
in
range(10):
56
db.create_obj(
"Dummy"
,
"TestDummy-%d"
% i)
57
db.commit()
58
59
def
test05a_CanCreateObjectFromOtherObject
(self):
60
db =
conffwk.Configuration
(
"oksconflibs:test.data.xml"
)
61
master = db.create_obj(
"Dummy"
,
"MasterDummy"
)
62
for
i
in
range(100, 110):
63
db.create_obj(
"Dummy"
,
"TestDummy-%d"
% i)
64
db.commit()
65
66
def
test06_CanTestForObjects
(self):
67
db =
conffwk.Configuration
(
"oksconflibs:test.data.xml"
)
68
for
i
in
range(10):
69
self.assertTrue(db.test_object(
"Dummy"
,
"TestDummy-%d"
% i, 0, []))
70
for
i
in
range(1000, 1010):
71
self.assertTrue(
not
db.test_object(
"Dummy"
,
"TestDummy-%d"
% i, 0, []))
72
73
def
test07_DetectsExistingObjects
(self):
74
db =
conffwk.Configuration
(
"oksconflibs:test.data.xml"
)
75
self.assertRaises(RuntimeError, db.create_obj,
"Dummy"
,
"TestDummy-3"
)
76
77
def
test08_CanGetObject
(self):
78
db =
conffwk.Configuration
(
"oksconflibs:test.data.xml"
)
79
obj = db.get_obj(
"Dummy"
,
"TestDummy-4"
)
80
81
def
test08a_CanGetObjects
(self):
82
db =
conffwk.Configuration
(
"oksconflibs:test.data.xml"
)
83
objs = db.get_objs(
"Dummy"
)
84
self.assertEqual(len(objs), 21)
85
86
def
test09_DoesNotCrashIfNonExisting
(self):
87
db =
conffwk.Configuration
(
"oksconflibs:test.data.xml"
)
88
self.assertRaises(RuntimeError, db.get_obj,
"Dummy"
,
"TestDummy-44"
)
89
90
def
test10_CanRemoveObject
(self):
91
db =
conffwk.Configuration
(
"oksconflibs:test.data.xml"
)
92
obj = db.get_obj(
"Dummy"
,
"TestDummy-1"
)
93
db.destroy_obj(obj)
94
db.commit()
95
self.assertRaises(RuntimeError, db.get_obj,
"Dummy"
,
"TestDummy-1"
)
96
97
def
test11_CanCycleThroughStates
(self):
98
db =
conffwk.Configuration
(
"oksconflibs:test.data.xml"
)
99
self.assertTrue(db.loaded())
100
db.unload()
101
self.assertTrue(
not
db.loaded())
102
db.load(
"test.data.xml"
)
103
self.assertTrue(db.loaded())
104
db.unload()
105
self.assertTrue(
not
db.loaded())
106
107
def
test12_CanStuffThousands
(self):
108
amount = 10000
109
db =
conffwk.Configuration
(
"oksconflibs"
)
110
db.create_db(
"test.data.xml"
, [f
'{scriptsdir}/test.schema.xml'
])
111
for
i
in
range(amount):
112
db.create_obj(
"Dummy"
,
"TestDummy-%d"
% i)
113
db.commit()
114
115
def
test13_CanCommitDeepRelations
(self):
116
import
sys
117
sys.setrecursionlimit(10000)
118
119
depth = 10000
120
db =
conffwk.Configuration
(
"oksconflibs"
)
121
db.create_db(
"test.data.xml"
, [f
'{scriptsdir}/test.schema.xml'
])
122
previous =
None
123
for
i
in
range(depth):
124
obj = db.create_obj(
"Second"
,
"Object-%d"
% i)
125
if
previous:
126
obj[
'Another'
] = previous
127
previous = obj
128
db.commit()
129
130
131
# If CanRetrieveDeepRelations fails, don't expect subsequent tests to be able to open oksconflibs:test.data.xml
132
133
def
test14_CanRetrieveDeepRelations
(self):
134
# we test if one can leave the rlevel in gets() to "0" and that works
135
import
sys
136
sys.setrecursionlimit(10000)
137
138
depth = 10000
139
db =
conffwk.Configuration
(
'oksconflibs:test.data.xml'
)
140
# gets the topmost obj.
141
obj = db.get_obj(
'Second'
,
'Object-%d'
% (depth-1))
142
counter = 1
143
144
while
obj[
'Another'
]:
145
counter += 1
146
obj = obj[
'Another'
]
# go deep in the relationship
147
self.assertEqual(counter, depth)
148
149
def
test15_CommitWithComment
(self):
150
db =
conffwk.Configuration
(
"oksconflibs"
)
151
dbfile =
'testcomment.data.xml'
152
db.create_db(dbfile, [f
'{scriptsdir}/test.schema.xml'
])
153
comment =
"My test comment"
154
db.commit(comment)
155
del db
156
with
open(dbfile)
as
textfile:
157
line = [l
for
l
in
textfile
if
' <comment '
in
l][0]
158
159
element = line.splitlines()[0]
160
self.assertTrue(comment
in
element)
161
162
163
if
__name__ ==
"__main__"
:
164
import
sys
165
sys.argv.append(
'-v'
)
166
unittest.main()
conffwk.Configuration.Configuration
Definition
Configuration.py:29
test_configuration.Configuration
Definition
test_configuration.py:17
test_configuration.Configuration.test02_CanReopenDB
test02_CanReopenDB(self)
Definition
test_configuration.py:28
test_configuration.Configuration.test12_CanStuffThousands
test12_CanStuffThousands(self)
Definition
test_configuration.py:107
test_configuration.Configuration.test11_CanCycleThroughStates
test11_CanCycleThroughStates(self)
Definition
test_configuration.py:97
test_configuration.Configuration.test08a_CanGetObjects
test08a_CanGetObjects(self)
Definition
test_configuration.py:81
test_configuration.Configuration.test10_CanRemoveObject
test10_CanRemoveObject(self)
Definition
test_configuration.py:90
test_configuration.Configuration.test07_DetectsExistingObjects
test07_DetectsExistingObjects(self)
Definition
test_configuration.py:73
test_configuration.Configuration.test14_CanRetrieveDeepRelations
test14_CanRetrieveDeepRelations(self)
Definition
test_configuration.py:133
test_configuration.Configuration.test06_CanTestForObjects
test06_CanTestForObjects(self)
Definition
test_configuration.py:66
test_configuration.Configuration.test03_CanAddIncludes
test03_CanAddIncludes(self)
Definition
test_configuration.py:34
test_configuration.Configuration.test01_CanCreateDB
test01_CanCreateDB(self)
Definition
test_configuration.py:20
test_configuration.Configuration.test05_CanCreateObject
test05_CanCreateObject(self)
Definition
test_configuration.py:53
test_configuration.Configuration.test15_CommitWithComment
test15_CommitWithComment(self)
Definition
test_configuration.py:149
test_configuration.Configuration.test13_CanCommitDeepRelations
test13_CanCommitDeepRelations(self)
Definition
test_configuration.py:115
test_configuration.Configuration.test01a_DoesNotCrashIfDBNotThere
test01a_DoesNotCrashIfDBNotThere(self)
Definition
test_configuration.py:25
test_configuration.Configuration.test08_CanGetObject
test08_CanGetObject(self)
Definition
test_configuration.py:77
test_configuration.Configuration.test05a_CanCreateObjectFromOtherObject
test05a_CanCreateObjectFromOtherObject(self)
Definition
test_configuration.py:59
test_configuration.Configuration.test09_DoesNotCrashIfNonExisting
test09_DoesNotCrashIfNonExisting(self)
Definition
test_configuration.py:86
test_configuration.Configuration.test04_CanRemoveIncludes
test04_CanRemoveIncludes(self)
Definition
test_configuration.py:44
Generated on
for DUNE-DAQ by
1.17.0