DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
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
11import os
12import unittest
13import conffwk
14
15scriptsdir=os.path.dirname(os.path.realpath(__file__))
16
17class Configuration(unittest.TestCase):
18 """Tests if we can manipulate ConfigurationWrap objects as expected."""
19
21 db = conffwk.Configuration("oksconflibs")
22 db.create_db("test.data.xml", [f'{scriptsdir}/test.schema.xml'])
23 db.commit()
24
26 self.assertRaises(RuntimeError, conffwk.Configuration, "test2.data.xml")
27
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
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
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
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
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
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
74 db = conffwk.Configuration("oksconflibs:test.data.xml")
75 self.assertRaises(RuntimeError, db.create_obj, "Dummy", "TestDummy-3")
76
78 db = conffwk.Configuration("oksconflibs:test.data.xml")
79 obj = db.get_obj("Dummy", "TestDummy-4")
80
82 db = conffwk.Configuration("oksconflibs:test.data.xml")
83 objs = db.get_objs("Dummy")
84 self.assertEqual(len(objs), 21)
85
87 db = conffwk.Configuration("oksconflibs:test.data.xml")
88 self.assertRaises(RuntimeError, db.get_obj, "Dummy", "TestDummy-44")
89
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
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
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
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
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
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
163if __name__ == "__main__":
164 import sys
165 sys.argv.append('-v')
166 unittest.main()