def test_init(self): """ OptionModel: __init__ """ p = OptionModel('KEY', 'GeneralSection', 0, int) st = {} p.bindToConfig(lambda: st) self.assertIsNotNone(p) self.assertIsInstance(p, OptionModel)
def test_get_default_with_conv(self, deflt, conv, expval, exptp): """ OptionModel: test get of default value vith type conversion """ p = OptionModel('KEY', 'GeneralSection', deflt, conv) st = {} p.bindToConfig(lambda: st) act = p.get() self.assertIsInstance(act, exptp) self.assertEqual(act, expval)
def test_get_default(self, deflt, tp): """ OptionModel: test get of default value """ p = OptionModel('KEY', 'GeneralSection', deflt, tp) st = {} p.bindToConfig(lambda: st) act = p.get() self.assertIsInstance(act, tp) self.assertEqual(act, deflt)
def test_get_wrong_type_falls_back_to_default(self, deflt, conv, confval): """ OptionModel: get with wrong type in config SHOULD fallback to default """ sec = 'AnySection' key = 'ANYKEY' inikey = key.lower() p = OptionModel(key, sec, deflt, conv) st = { sec: { inikey: confval } } p.bindToConfig(lambda: st) act = p.get() self.assertEqual(act, deflt)