def setUp(self): self.int = 5 self.str = "string" self.float= 5.1 self.intValue= Value(obj=self, attr="int", type=int, maxCount=3) self.strValue= Value(obj=self, attr="str", type=str) self.floatValue= Value(obj=self, attr="float", type=float)
class MapTestCase(unittest.TestCase): def setUp(self): self.bool= True self.list= [] self.boolCtx= Value( self, "bool", Map({'Yes' : True, 'No' : False}), maxCount=2 ) self.listCtx= MultiValue( self, "list", Map({'On' : True, 'Off' : False}), maxCount=3) def test_construction(self): self.assertEqual(self.boolCtx.count, 0) self.assertEqual(self.listCtx.count, 0) self.assertRaises(ValueError, Map, {5: True}) def test_parse(self): self.boolCtx.enter() self.boolCtx.addContent("No") self.boolCtx.leave() self.boolCtx.enter() self.boolCtx.addContent("no") self.assertRaises(KeyError, self.boolCtx.leave) self.listCtx.enter() self.listCtx.addContent("On") self.listCtx.leave() self.listCtx.enter() self.listCtx.addContent("Off") self.listCtx.leave() self.assertEqual(self.bool, False) self.assertEqual(self.list, [True, False]) self.assertEqual(self.boolCtx.count, 2) self.assertEqual(self.listCtx.count, 2) def test_contextInterface(self): self.assertRaises(NotImplementedError, self.boolCtx.getContext, "ctx")
def setUp(self): self.bool= True self.list= [] self.boolCtx= Value( self, "bool", Map({'Yes' : True, 'No' : False}), maxCount=2 ) self.listCtx= MultiValue( self, "list", Map({'On' : True, 'Off' : False}), maxCount=3)
class ValueTestCase(unittest.TestCase): def setUp(self): self.int = 5 self.str = "string" self.float= 5.1 self.intValue= Value(obj=self, attr="int", type=int, maxCount=3) self.strValue= Value(obj=self, attr="str", type=str) self.floatValue= Value(obj=self, attr="float", type=float) def test_construction(self): self.assertEqual(self.intValue.count, 0) self.assertEqual(self.strValue.count, 0) self.assertEqual(self.floatValue.count, 0) def test_parse(self): inputString="123" self.intValue.enter() self.intValue.addContent(inputString) self.intValue.leave() self.assertEqual(self.int, int(inputString)) self.assertEqual(self.intValue.count, 1) inputString="12" self.intValue.enter() self.intValue.addContent(inputString) self.intValue.leave() self.assertEqual(self.int, int(inputString)) self.assertEqual(self.intValue.count, 2) self.intValue.enter() self.intValue.addContent("12.5") self.assertRaises(ValueError, self.intValue.leave) self.assertRaises(IOError, self.intValue.enter) self.assertEqual(self.int, 12) self.assertEqual(self.intValue.count, 3) inputString="a string" self.strValue.enter() self.strValue.addContent(inputString[:3]) self.strValue.addContent(inputString[3:]) self.strValue.leave() self.assertEqual(self.str, inputString) self.assertEqual(self.strValue.count, 1) inputString="12.123" self.floatValue.enter() self.floatValue.addContent(inputString[:4]) self.floatValue.addContent(inputString[4:]) self.floatValue.leave() self.assertEqual(self.float, float(inputString)) self.assertEqual(self.floatValue.count, 1) def test_contextInterface(self): self.assertRaises(NotImplementedError, self.intValue.getContext, "ctx") self.assertEqual(self.floatValue.help, "") x= 0 for value in self.floatValue: x+= 1 self.assertEqual(x, 0)