Exemple #1
0
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")
Exemple #2
0
class MultiValueTestCase(unittest.TestCase):
    def setUp(self):
        self.list1 = []
        self.list2 = []

        self.list1Value = MultiValue(self, "list1", int)
        self.list2Value = MultiValue(self, "list2", float, maxCount=3)

    def test_construction(self):
        self.assertEqual(self.list1Value.count, 0)
        self.assertEqual(self.list2Value.count, 0)

    def test_parse(self):
        inputString = "123"
        self.list1Value.enter()
        self.list1Value.addContent(inputString)
        self.list1Value.leave()

        self.list2Value.enter()
        self.list2Value.addContent(inputString)
        self.list2Value.leave()

        self.assertEqual(self.list1, [int(inputString)])
        self.assertEqual(self.list2, [float(inputString)])
        self.assertEqual(self.list1Value.count, 1)
        self.assertEqual(self.list2Value.count, 1)

        self.list1Value.enter()
        self.list1Value.addContent("2")
        self.list1Value.leave()

        self.list1Value.enter()
        self.list1Value.addContent("3")
        self.list1Value.leave()

        self.list2Value.enter()
        self.list2Value.addContent("2.0")
        self.list2Value.leave()

        self.list2Value.enter()
        self.list2Value.addContent("4.2")
        self.list2Value.leave()

        self.assertEqual(self.list1, [int(inputString), 2, 3])
        self.assertEqual(self.list2, [int(inputString), 2.0, 4.2])

        self.assertRaises(IOError, self.list2Value.enter)

        self.list1Value.enter()
        self.list1Value.addContent("4")
        self.list1Value.addContent("4")
        self.list1Value.leave()

        self.assertEqual(self.list1, [int(inputString), 2, 3, 44])

    def test_contextInterface(self):
        self.assertRaises(NotImplementedError, self.list1Value.getContext, "ctx")