def testjunk(self): self.assertRaises(TypeError, item_create_instance, Item(name='wefwef')) item_create_instance(Item(blah='wefwef'), 'fwef') self.assertRaises(TypeError, item_create_instance) self.assertRaises(TypeError, item_create_instance, 'wefef') self.assertRaises(TypeError, item_create_instance, 1) self.assertRaises(TypeError, item_create_instance, Item, 1) self.assertRaises(TypeError, item_create_instance, [Item], 1) self.assertRaises(TypeError, item_create_instance, [Item], 'dd', name='ededed') self.assertRaises(TypeError, item_create_instance, [Item, {'name' : 'fff'}], 'dd', name='ededed')
def testsave3(self): s = item_create_instance(Setting(default='444', data_type=str), 'id') self.assert_(s.save() == []) s.set_value('fff') self.assert_(s.save() == [XMLItem('id', 'fff')]) s.set_value('') self.assert_(s.save() == [XMLItem('id', '')]) s.copy() s = item_create_instance(Setting(default='444', data_type=str, null_ok=True), 'id') s.set_value(None) self.assert_(s.save() == [XMLItem('id', None)])
def testsave3(self): s = item_create_instance(Setting(default='444', data_type=str), 'id') self.assert_(s.save() == []) s.set_value('fff') self.assert_(s.save() == [XMLItem('id', 'fff')]) s.set_value('') self.assert_(s.save() == [XMLItem('id', '')]) s.copy() s = item_create_instance( Setting(default='444', data_type=str, null_ok=True), 'id') s.set_value(None) self.assert_(s.save() == [XMLItem('id', None)])
def testnormal(self): s = item_create_instance(Setting(name='name', data_type=int), '1', value=2) self.assert_(s.get_default() is None) self.assert_(not s.is_default()) s = item_create_instance(Setting(name='name', default=8, data_type=int), '2') self.assert_(s.get_default() == 8) self.assert_(s.is_default()) s = item_create_instance(Setting(name='name', default=8, data_type=int), '3', value=2) self.assert_(s.get_default() == 8) self.assert_(s.get_value() == 2) self.assert_(not s.is_default()) s.copy()
def testops(self): s1 = item_create_instance(Setting(data_type=int), 'id') s2 = item_create_instance(Setting(data_type=int), 'id') self.assert_(s1 == s2) s1.set_value(5) self.assert_(s1 != s2) s2.set_value(5) self.assert_(s1 == s2) s2 = s1.copy() self.assert_(s1 == s2) self.assert_(s1.equal(5)) self.assert_(not s1.equal(s2)) self.assert_(not s1.equal(3)) s1.copy() s2.copy()
def testvalue2(self): s = item_create_instance(Setting(), 'id') self.assert_(s.get_default() is None) self.assert_(s.get_value() is None) s.reset() self.assert_(s.get_value() is None) s.copy()
def testsave2(self): s = item_create_instance(Setting(data_type=str), 'id') self.assert_(s.save() == []) s.set_value('') self.assert_(s.save() == [XMLItem('id', '')]) s.reset() self.assert_(s.save() == []) s.copy()
def testload2(self): s = item_create_instance(Setting(data_type=int), 'id') node = XMLItem('id', 'fff') self.assertRaises(ValueError, s.load, node) node = XMLItem('id', '5') s.load(node) self.assert_(s.get_value() == 5) s.copy()
def testnormal(self): s = item_create_instance(Setting(name='name', data_type=int), '1', value=2) self.assert_(s.get_default() is None) self.assert_(not s.is_default()) s = item_create_instance( Setting(name='name', default=8, data_type=int), '2') self.assert_(s.get_default() == 8) self.assert_(s.is_default()) s = item_create_instance(Setting(name='name', default=8, data_type=int), '3', value=2) self.assert_(s.get_default() == 8) self.assert_(s.get_value() == 2) self.assert_(not s.is_default()) s.copy()
def testload(self): s = item_create_instance(Setting(data_type=str), 'id') node = XMLItem('id', 'fff') s.load(node) self.assert_(s.get_value() == 'fff') node = XMLItem('id', None) s.load(node) self.assert_(s.get_value() is None) s.copy()
def testjunk(self): self.assertRaises(TypeError, item_create_instance, Item(name='wefwef')) item_create_instance(Item(blah='wefwef'), 'fwef') self.assertRaises(TypeError, item_create_instance) self.assertRaises(TypeError, item_create_instance, 'wefef') self.assertRaises(TypeError, item_create_instance, 1) self.assertRaises(TypeError, item_create_instance, Item, 1) self.assertRaises(TypeError, item_create_instance, [Item], 1) self.assertRaises(TypeError, item_create_instance, [Item], 'dd', name='ededed') self.assertRaises(TypeError, item_create_instance, [Item, { 'name': 'fff' }], 'dd', name='ededed')
def testdatatype(self): s = item_create_instance(Setting(data_type=str), 'id') self.assert_(s.get_default() is None) self.assert_(s.get_value() is None) self.assertRaises(TypeError, s.set_value, 8) s.reset() self.assert_(s.get_value() is None) s.set_string('5') self.assert_(s.get_value() == '5') s.copy()
def testdict2(self): S = Setting(data_type=int, default=5) s = item_create_instance(Dict(S), 'id') self.assert_(s == s.copy()) s['blah'] = S.create_instance('dd') self.assert_(s['blah'] == 5) self.assertRaises(Exception, self.assign, s, 'fff', 5) self.assertRaises(Exception, self.assign, s, 'fff', '44') self.assertRaises(Exception, self.assign, s, 'fff', None) self.assert_(s == s.copy())
def testdict(self): s = item_create_instance(Dict(str), 'id') self.assert_(s == s.copy()) s['blah'] = 'fwef' self.assert_(s['blah'] == 'fwef') s['foo'] = 'ddd' self.assert_(s['foo'] == 'ddd') s['foo'] = 'blah' self.assert_(s['foo'] == 'blah') self.assert_(s == s.copy()) self.assertRaises(Exception, self.assign, s, 'fff', 3)
def testnormal(self): item_create_instance(Item(name='wefwef'), 'id') item_create_instance(Item(name='wefwef', description='ewfwef'), 'id') item_create_instance(Item, 'id') self.assertRaises(TypeError, item_create_instance, [Item, { 'name': 'ffff' }], 'id')
def testdatatype2(self): s = item_create_instance(Setting(data_type=int), 'id') self.assert_(s.get_default() is None) self.assert_(s.get_value() is None) s.set_value(8) self.assert_(s.get_value() == 8) self.assertRaises(TypeError, s.set_value, '8') s.reset() self.assert_(s.get_value() is None) s.set_string('5') self.assert_(s.get_value() == 5) self.assertRaises(Exception, s.set_string, 'ewfwef') self.assertRaises(TypeError, s.set_value, 'ewfwef') s.copy()
def testnormal(self): item_create_instance(Item(name='wefwef'), 'id') item_create_instance(Item(name='wefwef', description='ewfwef'), 'id') item_create_instance(Item, 'id') self.assertRaises(TypeError, item_create_instance, [Item, {'name' : 'ffff'}], 'id')