def test_redirect_binary(self): with sh.pipes(sh.cat(__file__)) as cmd: cmd > 'tmp' ls = str(sh.ls('-l tmp')) with sh.pipes(sh.cat(__file__)) as cmd: cmd >> 'tmp' self.assertFalse(ls == str(sh.ls('-l tmp'))) sh.rm('tmp')
def test_redirect_python(self): @sh.wraps def grep(stdin): for line in stdin: if b'__' in line: yield line pipe = sh.cat(__file__) | grep with sh.pipes(pipe) as cmd: cmd > 'tmp' ls = str(sh.ls('-l tmp')) with sh.pipes(pipe) as cmd: cmd >> 'tmp' self.assertFalse(ls == str(sh.ls('-l tmp')), ls)