示例#1
0
 def test_simple(self):
     # test
     decorated = Log('{id}')(foo)
     decorated._log(None, None, 1)
         
     # verify
     self.assertEquals(1, len(self.logs))
     self.assertEquals(logging.INFO, self.logs[0].level)
     self.assertEquals('1', self.logs[0].msg)
     self.assertIsNone(self.logs[0].exc_info)
示例#2
0
 def test_exc_info(self):
     decorated = Log('{id}', exc_info=True)(foo)
     try:
         raise Exception()
     except:
         decorated._log(None, None, 1)
             
     # verify
     self.assertEquals(1, len(self.logs))
     self.assertEquals(logging.INFO, self.logs[0].level)
     self.assertEquals('1', self.logs[0].msg)
     self.assertTrue(self.logs[0].exc_info)
示例#3
0
 def test_bad_msg(self):
     decorated = Log('aaa {bbb} ccc')(foo)
     condition, msg = decorated._evaluate_expressions(None, None, 1, name='my name')
     self.assertTrue(condition)
     self.assertEquals('aaa {error:bbb} ccc', msg)
示例#4
0
 def test_bad_condition(self):
     decorated = Log('aaa', '!@#$%')(foo)
     condition, msg = decorated._evaluate_expressions(None, None, 1, name='my name')
     self.assertTrue(condition)
     self.assertEquals('Invalid condition: !@#$%.', msg)
示例#5
0
 def test_extra_kw_in_msg(self):
     decorated = Log('aaa {ret} bbb')(foo)
     _, msg = decorated._evaluate_expressions('111', None, 1, name='my name')
     self.assertEquals('aaa 111 bbb', msg)
示例#6
0
 def test_extra_kw_in_condition(self):
     decorated = Log('aaa', 'ret')(foo)
     condition, _ = decorated._evaluate_expressions([1], {'name': 'my name'}, {'ret': True})
     self.assertTrue(condition)
示例#7
0
 def test_condition_false(self):
     decorated = Log('aaa', '1 == 2')(foo)
     condition, msg = decorated._evaluate_expressions(None, None, 1, name='my name')
     self.assertFalse(condition)
     self.assertIsNone(msg)
示例#8
0
 def test_condition_true(self):
     decorated = Log('aaa', '1 == 1')(foo)
     condition, msg = decorated._evaluate_expressions(None, None, 1, name='my name')
     self.assertTrue(condition)
     self.assertEquals('aaa', msg)