def test_glob_warning(self): from pbs import ls from glob import glob import warnings with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") ls(glob("ofjaoweijfaowe")) self.assertTrue(len(w) == 1) self.assertTrue(issubclass(w[-1].category, UserWarning)) self.assertTrue("glob" in str(w[-1].message))
def test_err_redirection(self): import tempfile from pbs import time, ls file_obj = tempfile.TemporaryFile() with time(_with=True): ls(_err=file_obj) file_obj.seek(0) actual_out = file_obj.read() self.assertTrue(len(actual_out) != 0) file_obj.close()
def test_bake_args_come_first(self): from pbs import ls ls = ls.bake(full_time=True) ran = ls("-la").command_ran ft = ran.index("full-time") self.assertTrue("-la" in ran[ft:])
def test_composition(self): from pbs import ls, wc c1 = int(wc(ls("-A1"), l=True)) c2 = len(os.listdir(".")) if c1 != c2: with open("/tmp/fail", "a") as h: h.write("F**K\n") self.assertEqual(c1, c2)
def test_command_wrapper(self): from pbs import Command, which ls = Command(which("ls")) wc = Command(which("wc")) c1 = int(wc(ls(A=True), l=True)) c2 = len(os.listdir(".")) self.assertEqual(c1, c2)
def test_command_wrapper(self): from pbs import Command, which ls = Command(which("ls")) wc = Command(which("wc")) c1 = int(wc(ls("-A1"), l=True)) c2 = len(os.listdir(".")) self.assertEqual(c1, c2)
def test_out_redirection(self): import tempfile from pbs import ls file_obj = tempfile.TemporaryFile() out = ls(_out=file_obj) file_obj.seek(0) actual_out = file_obj.read() file_obj.close() self.assertTrue(len(actual_out) != 0)
def test_err_redirection(self): import tempfile from pbs import time, ls file_obj = tempfile.TemporaryFile() with time(_with=True): out = ls(_err=file_obj) file_obj.seek(0) actual_out = file_obj.read() file_obj.close() self.assertTrue(len(actual_out) != 0)
def test_ok_code(self): from pbs import ls, ErrorReturnCode_2 self.assertRaises(ErrorReturnCode_2, ls, "/aofwje/garogjao4a/eoan3on") ls("/aofwje/garogjao4a/eoan3on", _ok_code=2) ls("/aofwje/garogjao4a/eoan3on", _ok_code=[2])
def test_with_context(self): from pbs import time, ls with time: out = ls().stderr self.assertTrue("pagefaults" in out)
def test_err_to_out(self): from pbs import time, ls with time(_with=True): out = ls(_err_to_out=True) self.assertTrue("pagefaults" in out)
def test_with_context_args(self): from pbs import time, ls with time(verbose=True, _with=True): out = ls().stderr self.assertTrue("Voluntary context switches" in out)
def test_composition(self): from pbs import ls, wc c1 = int(wc(ls(A=True), l=True)) c2 = len(os.listdir(".")) self.assertEqual(c1, c2)
#!/usr/bin/env python from pbs import ls, wc def p(val, *fns): for fn in fns: val = fn(val) return val print p(ls(), wc())