6"""Unit test for the Python bindings to the ConfigObject class."""
12scriptsdir=os.path.dirname(os.path.realpath(__file__))
16 db.create_db(
'test.data.xml', [f
'{scriptsdir}/test.schema.xml'])
18 low = db.create_obj(
"Dummy",
"TestDummy-Low")
20 obj.assertEqual(low[attrname], min)
22 high = db.create_obj(
"Dummy",
"TestDummy-High")
24 obj.assertEqual(high[attrname], max)
31 filename =
'overflow_test.data.xml'
32 db.create_db(filename, [f
'{scriptsdir}/test.schema.xml'])
34 low = db.create_obj(
"Dummy",
"TestDummy-Underflow")
37 obj.assertRaises(TypeError, low.__setitem__, attrname, min-1)
39 high = db.create_obj(
"Dummy",
"TestDummy-Overflow")
41 obj.assertRaises(TypeError, high.__setitem__, attrname, max+1)
95 db.create_db(
"test.data.xml", [f
'{scriptsdir}/test.schema.xml'])
96 t = db.create_obj(
"Dummy",
"TestDummy-1")
97 attrname =
'uint64_vector_range'
102 self.assertEqual(t[attrname], val)
103 self.assertRaises(ValueError, t.__setitem__, attrname, [0, 1, 2])
108 db.create_db(
"test.data.xml", [f
'{scriptsdir}/test.schema.xml'])
109 t = db.create_obj(
"Dummy",
"TestDummy-1")
113 self.assertEqual(t[attrname], val)
118 db.create_db(
"test.data.xml", [f
'{scriptsdir}/test.schema.xml'])
119 t = db.create_obj(
"Dummy",
"TestDummy-1")
123 self.assertEqual(t[attrname], val)
124 val =
'DOES NOT EXIST'
125 self.assertRaises(ValueError, t.__setitem__, attrname, val)
129 db.create_db(
"test.data.xml", [f
'{scriptsdir}/test.schema.xml'])
130 t = db.create_obj(
"Dummy",
"TestDummy-1")
131 val = [
"test10",
"test20"]
132 attrname =
'string_vector'
134 self.assertEqual(t[attrname], val)
138 db.create_db(
"test.data.xml", [f
'{scriptsdir}/test.schema.xml'])
139 t = db.create_obj(
"Dummy",
"TestDummy-1")
143 self.assertEqual(t[attrname], val)
147 db.create_db(
"test.data.xml", [f
'{scriptsdir}/test.schema.xml'])
148 t = db.create_obj(
"Dummy",
"TestDummy-1")
149 val =
"2000-Jan-01 00:00:00"
152 self.assertEqual(t[attrname], val)
156 db.create_db(
"test.data.xml", [f
'{scriptsdir}/test.schema.xml'])
157 t = db.create_obj(
"Dummy",
"TestDummy-1")
159 attrname =
'classref'
161 self.assertEqual(t[attrname], val)
162 self.assertRaises(ValueError, t.__setitem__, attrname,
'DoesNotExist')
167 db.create_db(
"test.data.xml", [f
'{scriptsdir}/test.schema.xml'])
168 relation = db.create_obj(
"Dummy",
"Single-Relation")
169 t = db.create_obj(
'Third',
'Originator')
171 self.assertEqual(t[attrname],
None)
172 t[attrname] = relation
173 self.assertEqual(t[attrname], relation)
178 db.create_db(
"test.data.xml", [f
'{scriptsdir}/test.schema.xml'])
181 relations.append(db.create_obj(
"Second",
"Relation-%d" % i))
182 t = db.create_obj(
'Third',
'Originator')
184 t[attrname] = relations
185 self.assertEqual(t[attrname], relations)
190 db.create_db(
"test.data.xml", [f
'{scriptsdir}/test.schema.xml'])
191 t = db.create_obj(
'Dummy',
'TestDummy-1')
192 t.rename(
'TestDummy-2')
193 self.assertEqual(t.UID(),
'TestDummy-2')
194 t2 = db.get_obj(
'Dummy',
'TestDummy-2')
195 self.assertEqual(t, t2)
199if __name__ ==
"__main__":
201 sys.argv.append(
'-v')
test08_CanReadWriteUInt64(self)
test02_CanReadWriteUInt8(self)
test05_CanReadWriteInt32(self)
test09_CanReadWriteString(self)
test06_CanReadWriteUInt32(self)
test03_CanReadWriteInt16(self)
test15_CanReadWriteSingleValuedRelations(self)
test12_CanReadWriteDate(self)
test16_CanReadWriteMultiValuedRelations(self)
test13_CanReadWriteTime(self)
test00_CanReadWriteBool(self)
test01_CanReadWriteInt8(self)
test08a_CanReadWriteUInt64WithRange(self)
test04_CanReadWriteUInt16(self)
test07_CanReadWriteInt64(self)
test10_CanReadWriteEnum(self)
test11_CanReadWriteStringList(self)
test14_CanReadWriteClassReference(self)
limit_test(obj, attrname, min, max)
limit_test_raise(obj, attrname, min, max)