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)
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)
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)
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)
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)
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)
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)
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)