def test_find_files(): ok_(not find_files("test", "testtime", time_after)) ok_(not find_files("test", 0, time_after)) dirs = make_temp_dir() tmpfile1 = create_tempfile(time_between) tmpfile2 = create_tempfile(time_after) shutil.copy2(tmpfile1, dirs) shutil.copy2(tmpfile2, dirs) t = Tempfile() t.add(dirs) t.add(tmpfile1) t.add(tmpfile2) eq_( sorted(find_files(dirs, time_before, 0)), sorted([ os.path.join(dirs, os.path.basename(tmpfile1)), os.path.join(dirs, os.path.basename(tmpfile2)) ])) eq_(find_files(dirs, time_before, time_between), [os.path.join(dirs, os.path.basename(tmpfile1))]) t.drop()
def test_find_files(): assert not find_files("test", "testtime", time_after) assert not find_files("test", 0, time_after) dirs = make_temp_dir() tmpfile1 = create_tempfile(time_between) tmpfile2 = create_tempfile(time_after) shutil.copy2(tmpfile1, dirs) shutil.copy2(tmpfile2, dirs) t = Tempfile() t.add(dirs) t.add(tmpfile1) t.add(tmpfile2) assert sorted(find_files(dirs, time_before, 0)) == sorted([os.path.join(dirs, os.path.basename(tmpfile1)), os.path.join(dirs, os.path.basename(tmpfile2))]) assert find_files(dirs, time_before, time_between) == [os.path.join(dirs, os.path.basename(tmpfile1))] t.drop()
def test_find_files(): ok_(not find_files("test", "testtime", time_after)) ok_(not find_files("test", 0, time_after)) dirs = make_temp_dir() tmpfile1 = create_tempfile(time_between) tmpfile2 = create_tempfile(time_after) shutil.copy2(tmpfile1, dirs) shutil.copy2(tmpfile2, dirs) t = Tempfile() t.add(dirs) t.add(tmpfile1) t.add(tmpfile2) eq_(sorted(find_files(dirs, time_before, 0)), sorted([os.path.join(dirs, os.path.basename(tmpfile1)), os.path.join(dirs, os.path.basename(tmpfile2))])) eq_(find_files(dirs, time_before, time_between), [os.path.join(dirs, os.path.basename(tmpfile1))]) t.drop()
def test_tail(): temp_file = create_tempfile() with open(temp_file, 'w') as f: f.write(sample_string1) _, out = get_command_info("cat %s|tail -3" % temp_file) with open(temp_file, 'r') as f: data = f.read() res = tail(3, data) os.remove(temp_file) eq_(out.rstrip('\n'), '\n'.join(res))
def test_grep(): in_string = """aaaa bbbb """ temp_file = create_tempfile() with open(temp_file, 'w') as f: f.write(in_string) res = grep("aaaa", infile=temp_file, flag='v')[0] _, out = get_command_info("grep -v aaaa %s" % temp_file) os.remove(temp_file) assert res == out.strip("\n")
def test_head(): temp_file = create_tempfile() with open(temp_file, 'w') as f: f.write(sample_string1) _, out = get_command_info("cat %s|head -3" % temp_file) with open(temp_file, 'r') as f: data = f.read() res = head(3, data) os.remove(temp_file) eq_(out.rstrip('\n'), '\n'.join(res))
def test_tail(): temp_file = create_tempfile() with open(temp_file, 'w') as f: f.write(sample_string1) _, out = get_command_info("cat %s|tail -3" % temp_file) with open(temp_file, 'r') as f: data = f.read() res = tail(3, data) os.remove(temp_file) assert out.rstrip('\n') == '\n'.join(res)
def test_find_decompressor(): log_file = "testfile" eq_(find_decompressor(log_file), "cat") log_file = "log.bz2" eq_(find_decompressor(log_file), "bzip2 -dc") log_file = "log.gz" eq_(find_decompressor(log_file), "gzip -dc") log_file = "log.tar.xz" eq_(find_decompressor(log_file), "xz -dc") log_file = create_tempfile() with open(log_file, 'w') as f: f.write("test") eq_(find_decompressor(log_file), "cat") os.remove(log_file)
def test_grep(): res = grep("^Name", incmd="rpm -qi crmsh")[0] _, out = get_command_info("rpm -qi crmsh|grep \"^Name\"") eq_(res, out) ################################## in_string = """aaaa bbbb """ temp_file = create_tempfile() with open(temp_file, 'w') as f: f.write(in_string) res = grep("aaaa", infile=temp_file, flag='v')[0] _, out = get_command_info("grep -v aaaa %s" % temp_file) os.remove(temp_file) eq_(res, out)
def test_arch_logs(): # test blank file temp_file = create_tempfile() assert not arch_logs(temp_file, time_before, time_between) # from_time > last_time assert not arch_logs(pacemaker_log, time_after, time_between) # from_time >= first_time assert arch_logs(pacemaker_log, time_before, time_between)[0] == pacemaker_log # to_time == 0 assert arch_logs(pacemaker_log, time_before, 0)[0] == pacemaker_log # to_time >= first_time assert arch_logs(pacemaker_log, time_before, first_time)[0] == pacemaker_log os.remove(temp_file)
def test_arch_logs(): # test blank file temp_file = create_tempfile() ok_(not arch_logs(temp_file, time_before, time_between)) # from_time > last_time ok_(not arch_logs(pacemaker_log, time_after, time_between)) # from_time >= first_time eq_(arch_logs(pacemaker_log, time_before, time_between)[0], pacemaker_log) # to_time == 0 eq_(arch_logs(pacemaker_log, time_before, 0)[0], pacemaker_log) # to_time >= first_time eq_(arch_logs(pacemaker_log, time_before, first_time)[0], pacemaker_log) os.remove(temp_file)
def test_is_our_log(): # empty log temp_file = create_tempfile() eq_(is_our_log(temp_file, time_before, time_between), 0) # from_time > last_time eq_(is_our_log(pacemaker_log, time_after, time_between), 2) # from_time >= first_time eq_(is_our_log(pacemaker_log, time_between, time_after), 3) # to_time == 0 eq_(is_our_log(pacemaker_log, time_before, 0), 1) # to_time >= first_time eq_(is_our_log(pacemaker_log, time_before, first_time), 1) os.remove(temp_file)
def test_is_our_log(): # empty log temp_file = create_tempfile() assert is_our_log(temp_file, time_before, time_between) == 0 # from_time > last_time assert is_our_log(pacemaker_log, time_after, time_between) == 2 # from_time >= first_time assert is_our_log(pacemaker_log, time_between, time_after) == 3 # to_time == 0 assert is_our_log(pacemaker_log, time_before, 0) == 1 # to_time >= first_time assert is_our_log(pacemaker_log, time_before, first_time) == 1 os.remove(temp_file)
def test_find_decompressor(): log_file = "testfile" assert find_decompressor(log_file) == "cat" log_file = "log.bz2" assert find_decompressor(log_file) == "bzip2 -dc" log_file = "log.gz" assert find_decompressor(log_file) == "gzip -dc" log_file = "log.tar.xz" assert find_decompressor(log_file) == "xz -dc" log_file = create_tempfile() with open(log_file, 'w') as f: f.write("test") assert find_decompressor(log_file) == "cat" os.remove(log_file)
def test_grep(): res = grep("^Name", incmd="rpm -qi bash")[0] _, out = get_command_info("rpm -qi bash|grep \"^Name\"") eq_(res, out.strip("\n")) in_string = """aaaa bbbb """ temp_file = create_tempfile() with open(temp_file, 'w') as f: f.write(in_string) res = grep("aaaa", infile=temp_file, flag='v')[0] _, out = get_command_info("grep -v aaaa %s"%temp_file) os.remove(temp_file) eq_(res, out.strip("\n"))
def test_tail(): in_string = """some aaa some bbbb some cccc some dddd """ temp_file = create_tempfile() with open(temp_file, 'w') as f: f.write(in_string) _, out = get_command_info("cat %s|tail -3" % temp_file) with open(temp_file, 'r') as f: data = f.read() res = tail(3, data) os.remove(temp_file) eq_(out, '\n'.join(res))
def test_Tempfile(): t = Tempfile() tmpdir = make_temp_dir() t.add(tmpdir) tmpfile = create_tempfile() t.add(tmpfile) assert os.path.isdir(tmpdir) assert os.path.isfile(tmpfile) assert os.path.isfile(t.file) t.drop() assert not os.path.isdir(tmpdir) assert not os.path.isfile(tmpfile) assert not os.path.isfile(t.file)
def test_Tempfile(): t = Tempfile() tmpdir = make_temp_dir() t.add(tmpdir) tmpfile = create_tempfile() t.add(tmpfile) ok_(os.path.isdir(tmpdir)) ok_(os.path.isfile(tmpfile)) ok_(os.path.isfile(t.file)) t.drop() ok_(not os.path.isdir(tmpdir)) ok_(not os.path.isfile(tmpfile)) ok_(not os.path.isfile(t.file))
def test_find_getstampproc(): temp_file = create_tempfile() in_string1 = """abcd efg""" with open(temp_file, 'w') as f: f.write(in_string1) ok_(not find_getstampproc(temp_file)) in_string2 = """%s %s""" % (line5424_1, line5424_2) with open(temp_file, 'w') as f: f.write(in_string2) eq_(find_getstampproc(temp_file), "rfc5424") in_string3 = """%s %s""" % (linesyslog_1, linesyslog_2) with open(temp_file, 'w') as f: f.write(in_string3) eq_(find_getstampproc(temp_file), "syslog") os.remove(temp_file)
def test_find_getstampproc(): temp_file = create_tempfile() in_string1 = """abcd efg""" with open(temp_file, 'w') as f: f.write(in_string1) assert not find_getstampproc(temp_file) in_string2 = """%s %s""" % (line5424_1, line5424_2) with open(temp_file, 'w') as f: f.write(in_string2) assert find_getstampproc(temp_file) == "rfc5424" in_string3 = """%s %s""" % (linesyslog_1, linesyslog_2) with open(temp_file, 'w') as f: f.write(in_string3) assert find_getstampproc(temp_file) == "syslog" os.remove(temp_file)