class TestLoggingFunctions(unittest.TestCase): def __init__(self, *args, **kwargs): super(TestLoggingFunctions, self).__init__(*args, **kwargs) self.log = Logger() def test_INFO(self): self.log.INFO('test') self.checkLog('INFO') def test_WARN(self): self.log.WARN('test') self.checkLog('WARN') def test_ALERT(self): self.log.ALERT('test') self.checkLog('ALERT') def test_ERROR(self): self.log.ERROR('test') self.checkLog('ERROR') def test_FATAL(self): self.log.FATAL('test') self.checkLog('FATAL') def checkLog(self, level): with open(self.log.filepath, 'r') as f: line = f.readlines()[-1] self.assertTrue(level in line)
def execute_use_case(self, user_case_function, *params, exit_on_fail=False): Logger.INFO(self.__bar_separator) self.use_case_total += 1 Logger.INFO('Start use case {} : {}'.format( self.use_case_total, user_case_function.__name__)) res = user_case_function(*params) if res != False: self.use_case_success += 1 else: if exit_on_fail: Logger.error( 'Blocking error. This step have to succed in order to continue the Scenario' ) exit(0) Logger.INFO(self.__bar_separator + '\n') return res
class Main(): def __init__(self): self.state = Armed() self.log = Logger(filepath='/proj/hubcap/hubcap/logs/main.log') def main(self): try: while True: print self.state.getState() self.state.wait() self.state.sync() if self.state.transition(): self.state = self.state.next() print self.state.getState() self.log.INFO('{0}'.format(self.state.getState())) except KeyboardInterrupt: shutil.copytree( '/proj/hubcap/hubcap/logs', '/proj/hubcap/hubcap/archives/{0}/'.format( time.strftime("%m-%d-%y-%H%M%S")))
def print_execute_ending(self): Logger.INFO(self.__bar_separator) Logger.success('End of scenario : {} use cases passed on {}'.format( self.use_case_success, self.use_case_total)) Logger.INFO(self.__bar_separator + '\n')
def print_execute_title(self): Logger.INFO(self.__bar_separator) Logger.INFO(self.__scenario_title) Logger.INFO(self.__bar_separator + '\n')