def testPythonAndTalesContext(self):
     # Evaluation (use context in python and TALES)
     evaluationWithContextUsedTwice = EVAL_KEY + \
         '"100,*,${here/rackSlot},/," + str(here.rackSlot) + ",*"'
     alias = RRDDataPointAlias('alias8')
     alias.formula = evaluationWithContextUsedTwice
     self.assert_(alias.evaluate(self.device) == '100,*,5,/,5,*')
 def testMultipleSubstitution(self):
     # Multiple substitution
     multiSubstitution = \
         '100,*,3,${here/rackSlot},LT,10,20,IF,${here/rackSlot},*'
     alias = RRDDataPointAlias('alias5')
     alias.formula = multiSubstitution
     self.assert_(alias.evaluate(self.device) == '100,*,3,5,LT,10,20,IF,5,*')
 def testWithContext(self):
     # Evaluation (use context)
     evaluationWithContext = EVAL_KEY + \
         '"100,*," + str(len("12345") * here.rackSlot) + ",/"'
     alias = RRDDataPointAlias('alias7')
     alias.formula = evaluationWithContext
     self.assert_(alias.evaluate(self.device) == '100,*,25,/')
 def testPythonAndTalesContext(self):
     # Evaluation (use context in python and TALES)
     evaluationWithContextUsedTwice = EVAL_KEY + \
         '"100,*,${here/rackSlot},/," + str(here.rackSlot) + ",*"'
     alias = RRDDataPointAlias('alias8')
     alias.formula = evaluationWithContextUsedTwice
     self.assert_(alias.evaluate(self.device) == '100,*,5,/,5,*')
 def testWithContext(self):
     # Evaluation (use context)
     evaluationWithContext = EVAL_KEY + \
         '"100,*," + str(len("12345") * here.rackSlot) + ",/"'
     alias = RRDDataPointAlias('alias7')
     alias.formula = evaluationWithContext
     self.assert_(alias.evaluate(self.device) == '100,*,25,/')
 def testMultipleSubstitution(self):
     # Multiple substitution
     multiSubstitution = \
         '100,*,3,${here/rackSlot},LT,10,20,IF,${here/rackSlot},*'
     alias = RRDDataPointAlias('alias5')
     alias.formula = multiSubstitution
     self.assert_(
         alias.evaluate(self.device) == '100,*,3,5,LT,10,20,IF,5,*')
    def testCreate(self):
        name = 'testalias'
        formula = 'testformula'
        alias = RRDDataPointAlias(name)
        alias.formula = formula
        self.assert_(alias.id == name)
        self.assert_(alias.formula == formula)

        name2 = 'testalias2'
        alias = RRDDataPointAlias(name2)
        self.assert_(alias.id == name2)
        self.assert_(alias.formula is None)
    def testCreate(self):
        name = 'testalias'
        formula = 'testformula'
        alias = RRDDataPointAlias(name)
        alias.formula = formula
        self.assert_(alias.id == name)
        self.assert_(alias.formula == formula)

        name2 = 'testalias2'
        alias = RRDDataPointAlias(name2)
        self.assert_(alias.id == name2)
        self.assert_(alias.formula is None)
 def testInvalidLength(self, mock_logging):
     aliasId = ('alias' * 6) + 'a'
     alias = RRDDataPointAlias(aliasId)
     self.assertEqual(mock_logging.warn.call_count, 1)
     args = mock_logging.warn.call_args[0]
     self.assertTrue("exceeds 30 character limit" in args[0])
     self.assert_(alias.id == aliasId)
    def testTrimmedAliasId(self):
        alias = RRDDataPointAlias(' alias1')
        self.assert_(alias.id == 'alias1')
        alias = RRDDataPointAlias('alias1 ')
        self.assert_(alias.id == 'alias1')
        alias = RRDDataPointAlias(' alias1 ')
        self.assert_(alias.id == 'alias1')

        t = createTemplate(self.dmd)
        ds0 = t.datasources()[0]
        dp0 = ds0.datapoints()[0]
        alias1 = manage_addDataPointAlias(dp0, ' alias1', '')
        self.assert_(alias1.id == 'alias1')
        alias2 = manage_addDataPointAlias(dp0, 'alias2 ', '')
        self.assert_(alias2.id == 'alias2')
        alias3 = manage_addDataPointAlias(dp0, ' alias3 ', '')
        self.assert_(alias3.id == 'alias3')
 def testAliasWithUnderbar(self):
     alias = RRDDataPointAlias('alias_1')
     self.assert_(alias.id == 'alias_1')
 def testNoFormula(self):
     alias = RRDDataPointAlias('alias1')
     self.assert_(alias.evaluate(self.device) is None)
 def testEmptyFormula(self):
     # Empty formula
     alias = RRDDataPointAlias('alias2')
     alias.formula = ''
     self.assert_(alias.evaluate(self.device) is None)
 def testNoContext(self):
     # Evaluation (no context)
     evaluationNoContext = EVAL_KEY + '"100,*," + str(len("12345")) + ",/"'
     alias = RRDDataPointAlias('alias6')
     alias.formula = evaluationNoContext
     self.assert_(alias.evaluate(self.device) == '100,*,5,/')
 def testSimpleRPNFormula(self):
     # Simple RPN formula
     simpleRpn = '100,/'
     alias = RRDDataPointAlias('alias3')
     alias.formula = simpleRpn
     self.assert_(alias.evaluate(self.device) == simpleRpn)
 def testSingleSubstitution(self):
     # Single substitution
     singleSubstitution = '100,*,${here/rackSlot},/'
     alias = RRDDataPointAlias('alias4')
     alias.formula = singleSubstitution
     self.assert_(alias.evaluate(self.device) == '100,*,5,/')
 def testSimpleRPNFormula(self):
     # Simple RPN formula
     simpleRpn = '100,/'
     alias = RRDDataPointAlias('alias3')
     alias.formula = simpleRpn
     self.assert_(alias.evaluate(self.device) == simpleRpn)
 def testEmptyFormula(self):
     # Empty formula
     alias = RRDDataPointAlias('alias2')
     alias.formula = ''
     self.assert_(alias.evaluate(self.device) is None)
 def testEvaluate(self):
     device = createDevice( self.dmd, 'testdevice')
     device.rackSlot = 5
     
     # No formula
     alias = RRDDataPointAlias( 'alias1' )
     self.assert_( alias.evaluate( device ) is None )
     
     # Empty formula
     alias = RRDDataPointAlias( 'alias2' )
     alias.formula = ''
     self.assert_( alias.evaluate( device ) is None )
     
     # Simple RPN formula
     simpleRpn = '100,/'
     alias = RRDDataPointAlias( 'alias3' )
     alias.formula = simpleRpn
     self.assert_( alias.evaluate( device ) == simpleRpn )
     
     # Single substitution
     singleSubstitution = '100,*,${here/rackSlot},/'
     alias = RRDDataPointAlias( 'alias4' )
     alias.formula = singleSubstitution
     self.assert_( alias.evaluate( device ) == '100,*,5,/' )
     
     # Multiple substitution
     multiSubstitution = '100,*,3,${here/rackSlot},LT,10,20,IF,${here/rackSlot},*'
     alias = RRDDataPointAlias( 'alias5' )
     alias.formula = multiSubstitution
     self.assert_( alias.evaluate( device ) == '100,*,3,5,LT,10,20,IF,5,*' )
     
     # Evaluation (no context)
     evaluationNoContext = EVAL_KEY + '"100,*," + str( len("12345") ) + ",/"'
     alias = RRDDataPointAlias( 'alias6' )
     alias.formula = evaluationNoContext
     self.assert_( alias.evaluate( device ) == '100,*,5,/' )
     
     # Evaluation (use context)
     evaluationWithContext = EVAL_KEY + \
         '"100,*," + str( len("12345") * here.rackSlot ) + ",/"'
     alias = RRDDataPointAlias( 'alias7' )
     alias.formula = evaluationWithContext
     self.assert_( alias.evaluate( device ) == '100,*,25,/' )
     
     # Evaluation (use context in python and TALES)
     evaluationWithContextUsedTwice = EVAL_KEY + \
       '"100,*,${here/rackSlot},/," + str( here.rackSlot ) + ",*"'
     alias = RRDDataPointAlias( 'alias8' )
     alias.formula = evaluationWithContextUsedTwice
     self.assert_( alias.evaluate( device ) == '100,*,5,/,5,*' )
 def testSingleSubstitution(self):
     # Single substitution
     singleSubstitution = '100,*,${here/rackSlot},/'
     alias = RRDDataPointAlias('alias4')
     alias.formula = singleSubstitution
     self.assert_(alias.evaluate(self.device) == '100,*,5,/')
 def testNoContext(self):
     # Evaluation (no context)
     evaluationNoContext = EVAL_KEY + '"100,*," + str(len("12345")) + ",/"'
     alias = RRDDataPointAlias('alias6')
     alias.formula = evaluationNoContext
     self.assert_(alias.evaluate(self.device) == '100,*,5,/')
 def testInvalidWhitespace(self, mock_logging):
     alias = RRDDataPointAlias('an alias')
     self.assertEqual(mock_logging.warn.call_count, 1)
     args = mock_logging.warn.call_args[0]
     self.assertTrue("contains whitespace" in args[0])
     self.assert_(alias.id == 'an alias')
 def testNoFormula(self):
     alias = RRDDataPointAlias('alias1')
     self.assert_(alias.evaluate(self.device) is None)
 def testInvalid(self, mock_logging):
     aliasId = ('alias ' * 5) + 'a'
     alias = RRDDataPointAlias(aliasId)
     self.assertEqual(mock_logging.warn.call_count, 2)
     self.assert_(alias.id == aliasId)
Beispiel #25
0
    def testEvaluate(self):
        device = createDevice(self.dmd, 'testdevice')
        device.rackSlot = 5

        # No formula
        alias = RRDDataPointAlias('alias1')
        self.assert_(alias.evaluate(device) is None)

        # Empty formula
        alias = RRDDataPointAlias('alias2')
        alias.formula = ''
        self.assert_(alias.evaluate(device) is None)

        # Simple RPN formula
        simpleRpn = '100,/'
        alias = RRDDataPointAlias('alias3')
        alias.formula = simpleRpn
        self.assert_(alias.evaluate(device) == simpleRpn)

        # Single substitution
        singleSubstitution = '100,*,${here/rackSlot},/'
        alias = RRDDataPointAlias('alias4')
        alias.formula = singleSubstitution
        self.assert_(alias.evaluate(device) == '100,*,5,/')

        # Multiple substitution
        multiSubstitution = '100,*,3,${here/rackSlot},LT,10,20,IF,${here/rackSlot},*'
        alias = RRDDataPointAlias('alias5')
        alias.formula = multiSubstitution
        self.assert_(alias.evaluate(device) == '100,*,3,5,LT,10,20,IF,5,*')

        # Evaluation (no context)
        evaluationNoContext = EVAL_KEY + '"100,*," + str( len("12345") ) + ",/"'
        alias = RRDDataPointAlias('alias6')
        alias.formula = evaluationNoContext
        self.assert_(alias.evaluate(device) == '100,*,5,/')

        # Evaluation (use context)
        evaluationWithContext = EVAL_KEY + \
            '"100,*," + str( len("12345") * here.rackSlot ) + ",/"'
        alias = RRDDataPointAlias('alias7')
        alias.formula = evaluationWithContext
        self.assert_(alias.evaluate(device) == '100,*,25,/')

        # Evaluation (use context in python and TALES)
        evaluationWithContextUsedTwice = EVAL_KEY + \
          '"100,*,${here/rackSlot},/," + str( here.rackSlot ) + ",*"'
        alias = RRDDataPointAlias('alias8')
        alias.formula = evaluationWithContextUsedTwice
        self.assert_(alias.evaluate(device) == '100,*,5,/,5,*')