def test_line_time(): assert ts_to_dt(line_time( pacemaker_log, 2)).strftime("%Y/%m/%d %H:%M:%S") == "%d/04/03 11:01:18" % year assert ts_to_dt(line_time( pacemaker_log, 195)).strftime("%Y/%m/%d %H:%M:%S") == "%d/04/03 11:01:40" % year
def test_line_time(): eq_( ts_to_dt(line_time(pacemaker_log, 2)).strftime("%Y/%m/%d %H:%M:%S"), "2019/04/03 11:01:18") eq_( ts_to_dt(line_time(pacemaker_log, 195)).strftime("%Y/%m/%d %H:%M:%S"), "2019/04/03 11:01:40")
def test_get_ts(): eq_( ts_to_dt(get_ts(line5424_1)).strftime("%Y/%m/%d %H:%M"), "2017/01/26 03:04") eq_( ts_to_dt(get_ts(linesyslog_1)).strftime("%m/%d %H:%M:%S"), "05/17 15:52:40")
def test_line_time_unicode(): assert ts_to_dt(line_time( pacemaker_unicode_log, 3)).strftime("%Y/%m/%d %H:%M:%S") == "%d/04/03 11:01:18" % year with open(evil_unicode_log, 'wb') as f: f.write(invalid_utf8) assert ts_to_dt(line_time( evil_unicode_log, 1)).strftime("%Y/%m/%d %H:%M:%S") == "%d/04/03 11:01:18" % year os.remove(evil_unicode_log)
def test_ts_to_dt(): ts1 = crmsh.utils.parse_to_timestamp("2pm") ts2 = crmsh.utils.parse_to_timestamp("2007/9/5 12:30") ts3 = crmsh.utils.parse_to_timestamp("1:00") ts4 = crmsh.utils.parse_to_timestamp("09-Sep-15 2:00") eq_(ts_to_dt(ts1).strftime("%-I%P"), "2pm") eq_(ts_to_dt(ts2).strftime("%Y/%-m/%-d %H:%M"), "2007/9/5 12:30") eq_(ts_to_dt(ts3).strftime("%-H:%M"), "1:00") eq_(ts_to_dt(ts4).strftime("%d-%b-%y %-H:%M"), "09-Sep-15 2:00")
def test_line_time_unicode(): eq_( ts_to_dt(line_time(pacemaker_unicode_log, 3)).strftime("%Y/%m/%d %H:%M:%S"), "2019/04/03 11:01:18") with open(evil_unicode_log, 'wb') as f: f.write(invalid_utf8) eq_( ts_to_dt(line_time(evil_unicode_log, 1)).strftime("%Y/%m/%d %H:%M:%S"), "2019/04/03 11:01:18") os.remove(evil_unicode_log)
def test_ts_to_dt(): ts1 = crmsh.utils.parse_to_timestamp("2pm") ts2 = crmsh.utils.parse_to_timestamp("2007/9/5 12:30") ts3 = crmsh.utils.parse_to_timestamp("1:00") ts4 = crmsh.utils.parse_to_timestamp("09-Sep-15 2:00") ts5 = crmsh.utils.parse_to_timestamp("2017-06-01T14:27:08.412531+08:00") assert ts_to_dt(ts1).strftime("%-I%P") == "2pm" assert ts_to_dt(ts2).strftime("%Y/%-m/%-d %H:%M") == "2007/9/5 12:30" assert ts_to_dt(ts3).strftime("%-H:%M") == "1:00" assert ts_to_dt(ts4).strftime("%d-%b-%y %-H:%M") == "09-Sep-15 2:00" assert ts_to_dt(ts5).strftime("%Y/%m/%d %H:%M:%S") == "2017/06/01 06:27:08"
def test_ts_to_dt(): ts1 = crmsh.utils.parse_to_timestamp("2pm") ts2 = crmsh.utils.parse_to_timestamp("2007/9/5 12:30") ts3 = crmsh.utils.parse_to_timestamp("1:00") ts4 = crmsh.utils.parse_to_timestamp("09-Sep-15 2:00") ts5 = crmsh.utils.parse_to_timestamp("2017-06-01T14:27:08.412531+08:00") eq_(ts_to_dt(ts1).strftime("%-I%P"), "2pm") eq_(ts_to_dt(ts2).strftime("%Y/%-m/%-d %H:%M"), "2007/9/5 12:30") eq_(ts_to_dt(ts3).strftime("%-H:%M"), "1:00") eq_(ts_to_dt(ts4).strftime("%d-%b-%y %-H:%M"), "09-Sep-15 2:00") eq_(ts_to_dt(ts5).strftime("%Y/%m/%d %H:%M:%S"), "2017/06/01 06:27:08")
def test_get_ts(): assert ts_to_dt( get_ts(line5424_1)).strftime("%Y/%m/%d %H:%M") == "2017/01/26 03:04" assert ts_to_dt( get_ts(linesyslog_1)).strftime("%m/%d %H:%M:%S") == "05/17 15:52:40"
def test_find_first_ts(): with open(pacemaker_log, 'r') as f: res = find_first_ts(f.read().split('\n')) assert ts_to_dt(res).strftime( "%Y/%m/%d %H:%M:%S") == "%d/04/03 11:01:18" % year
def test_line_time_unicode(): eq_(ts_to_dt(line_time(pacemaker_unicode_log, 3)).strftime("%Y/%m/%d %H:%M:%S"), "2019/04/03 11:01:18") with open(evil_unicode_log, 'wb') as f: f.write(invalid_utf8) eq_(ts_to_dt(line_time(evil_unicode_log, 1)).strftime("%Y/%m/%d %H:%M:%S"), "2019/04/03 11:01:18") os.remove(evil_unicode_log)
def test_line_time(): eq_(ts_to_dt(line_time(pacemaker_log, 2)).strftime("%Y/%m/%d %H:%M:%S"), "2019/04/03 11:01:18") eq_(ts_to_dt(line_time(pacemaker_log, 195)).strftime("%Y/%m/%d %H:%M:%S"), "2019/04/03 11:01:40")
def test_get_ts(): eq_(ts_to_dt(get_ts(line5424_1)).strftime("%Y/%m/%d %H:%M"), "2017/01/26 03:04") eq_(ts_to_dt(get_ts(linesyslog_1)).strftime("%m/%d %H:%M:%S"), "05/17 15:52:40")
def test_find_first_ts(): with open(pacemaker_log, 'r') as f: res = find_first_ts(f.read().split('\n')) eq_(ts_to_dt(res).strftime("%Y/%m/%d %H:%M:%S"), "2019/04/03 11:01:18")
def test_find_first_ts(): with open(pacemaker_log, 'r') as f: res = find_first_ts(f.read().split('\n')) eq_(ts_to_dt(res).strftime("%Y/%m/%d %H:%M:%S"), "2019/04/03 11:01:18")