def test_timer_decorator(self): log_file = logging.get_log_file('TestTimer') + '_decorator' logging.set_logfile(log_file) sleep(0.5) logging.shutdown() content = get_file_content(log_file+'_data.log') d = json.loads(content) self.assertAlmostEqual(0.5, d['mykey'], 1)
def test_timer_context_manager(self): log_file = logging.get_log_file('TestTimer') + '_context_manager' logging.set_logfile(log_file) logging.shutdown() with time_measure('mykey2'): time.sleep(0.5) content = get_file_content(log_file+'_data.log') d = json.loads(content) self.assertAlmostEqual(0.5, d['mykey2'], 1)
def __init__(self, args, runner_file): self.args = args # set logfile self.log_dir = get_log_dir(runner_file) summary = self.args_to_str() self.logfile = os.path.join(self.log_dir, summary) logging.set_logfile(self.logfile) # print content of file self.log_file_contents(runner_file)
def test_data(self): log_file = logging.get_log_file('test_logger') + '_data' logging.set_logfile(log_file) logging.data('key', 2) logging.info('ABCD') logging.shutdown() # check content = get_file_content(log_file + '_data.log') d = json.loads(content) self.assertEquals(d['key'], 2) self.assertTrue('ABCD' not in content)
def test_logger(self): # ignore warnings warnings.simplefilter("ignore") # log something log_file = logging.get_log_file('test_logger') + '_info' logging.set_logfile(log_file) logging.info("ABCD") logging.shutdown() # check logfile success = 'ABCD' in get_file_content(log_file + '_info.log') self.assertTrue(success)
def test_search(self): # prepare logger logfile = logging.get_log_file('search_test') logging.set_logfile(logfile) logging.info('Starting test of TensorFlowSearcher') parser = get_args_parser(n_steps=4, confidence=0.9) args = parser.parse_args([]) search(args) # finish logging logging.info('Finished test of TensorFlowSearcher') logging.shutdown()
def __init__(self, *args, **kwargs): super(TestParser, self).__init__(*args, **kwargs) # prepare logger logfile = logging.get_log_file('parser_test') logging.set_logfile(logfile) parser = get_args_parser(n_steps=4, confidence=0.9) args = parser.parse_args([]) search(args) # finish logging logging.shutdown() # get generated log self.p = get_parsed(logfile + '_data.log')
def setUpClass(cls): # prepare logger logfile = logging.get_log_file('psi_scorer_test/' + cls.__name__) logging.set_logfile(logfile)