4"""Unit test for the Python bindings to the Configuration class."""
10scriptsdir=os.path.dirname(os.path.realpath(__file__))
13 """Tests if we can manipulate ConfigurationWrap objects as expected."""
17 db.create_db(
"test.data.xml", [f
'{scriptsdir}/test.schema.xml'])
25 includes = db.get_includes(
"test.data.xml")
26 self.assertEqual(len(includes), 1)
27 self.assertEqual(includes[0], f
"{scriptsdir}/test.schema.xml")
31 db.add_include(f
'{scriptsdir}/core.schema.xml')
32 includes = db.get_includes(
"test.data.xml")
34 self.assertEqual(len(includes), 2)
36 includes = db.get_includes(
"test.data.xml")
37 self.assertEqual(len(includes), 2)
41 includes = db.get_includes()
42 self.assertEqual(len(includes), 2)
43 db.remove_include(includes[1])
45 includes = db.get_includes()
46 self.assertEqual(len(includes), 1)
51 db.create_obj(
"Dummy",
"TestDummy-%d" % i)
56 master = db.create_obj(
"Dummy",
"MasterDummy")
57 for i
in range(100, 110):
58 db.create_obj(
"Dummy",
"TestDummy-%d" % i)
64 self.assertTrue(db.test_object(
"Dummy",
"TestDummy-%d" % i, 0, []))
65 for i
in range(1000, 1010):
66 self.assertTrue(
not db.test_object(
"Dummy",
"TestDummy-%d" % i, 0, []))
70 self.assertRaises(RuntimeError, db.create_obj,
"Dummy",
"TestDummy-3")
74 obj = db.get_obj(
"Dummy",
"TestDummy-4")
78 objs = db.get_objs(
"Dummy")
79 self.assertEqual(len(objs), 21)
83 self.assertRaises(RuntimeError, db.get_obj,
"Dummy",
"TestDummy-44")
87 obj = db.get_obj(
"Dummy",
"TestDummy-1")
90 self.assertRaises(RuntimeError, db.get_obj,
"Dummy",
"TestDummy-1")
94 self.assertTrue(db.loaded())
96 self.assertTrue(
not db.loaded())
97 db.load(
"test.data.xml")
98 self.assertTrue(db.loaded())
100 self.assertTrue(
not db.loaded())
105 db.create_db(
"test.data.xml", [f
'{scriptsdir}/test.schema.xml'])
106 for i
in range(amount):
107 db.create_obj(
"Dummy",
"TestDummy-%d" % i)
112 sys.setrecursionlimit(10000)
116 db.create_db(
"test.data.xml", [f
'{scriptsdir}/test.schema.xml'])
118 for i
in range(depth):
119 obj = db.create_obj(
"Second",
"Object-%d" % i)
121 obj[
'Another'] = previous
131 sys.setrecursionlimit(10000)
136 obj = db.get_obj(
'Second',
'Object-%d' % (depth-1))
139 while obj[
'Another']:
142 self.assertEqual(counter, depth)
146 dbfile =
'testcomment.data.xml'
147 db.create_db(dbfile, [f
'{scriptsdir}/test.schema.xml'])
148 comment =
"My test comment"
151 with open(dbfile)
as textfile:
152 line = [l
for l
in textfile
if ' <comment ' in l][0]
154 element = line.splitlines()[0]
155 self.assertTrue(comment
in element)
158if __name__ ==
"__main__":
160 sys.argv.append(
'-v')
test12_CanStuffThousands(self)
test11_CanCycleThroughStates(self)
test08a_CanGetObjects(self)
test10_CanRemoveObject(self)
test07_DetectsExistingObjects(self)
test14_CanRetrieveDeepRelations(self)
test06_CanTestForObjects(self)
test03_CanAddIncludes(self)
test05_CanCreateObject(self)
test15_CommitWithComment(self)
test13_CanCommitDeepRelations(self)
test01a_DoesNotCrashIfDBNotThere(self)
test08_CanGetObject(self)
test05a_CanCreateObjectFromOtherObject(self)
test09_DoesNotCrashIfNonExisting(self)
test04_CanRemoveIncludes(self)