def test_long_pipe(): result = [] with (cat | grep("foo") | cat | cat | grep("foo") | cat) as (stdin, stdout, stderr): stdin.write("bar\n") stdin.write("foo\n") stdin.close() result.append(next(stdout).strip()) assert result == ["foo"]
def test_redirects(): filename = "src/tests/playground/output.txt" echo("hello world") > filename with open(filename) as f: assert f.read().strip() == "hello world" echo("hello world") >> filename with open(filename) as f: assert f.read().strip() == "hello world\nhello world" assert str(cat < filename).strip() == "hello world\nhello world" rm(filename)() buf = io.StringIO("foo") echo("hello world") > buf buf.seek(0) assert buf.read() == "hello world\n" buf = io.BytesIO(b"foo") echo("hello world", _text=False) > buf buf.seek(0) assert buf.read() == b"hello world\n" buf = io.StringIO("foo ") echo("hello world") >> buf buf.seek(0) assert buf.read() == "foo hello world\n" buf = io.BytesIO(b"foo ") echo("hello world", _text=False) >> buf buf.seek(0) assert buf.read() == b"foo hello world\n" assert str(grep("aaa") < io.StringIO("aaa\nbbb")) == "aaa\n"
def test_pipe_to_generator(): assert list(echo("aaa\nbbb") | upperize()) == ["AAA\n", "BBB\n"] assert str(echo("aaa\nbbb") | upperize() | grep("AAA")) == "AAA\n"
def test_long_pipe(): assert (str(my_input() | cat | grep('line') | my_output | grep("TWO")).strip() == "LINE TWO\nLINE TWO")
def test_pipe_command_to_command(): assert str(echo("aaa\nbbb") | grep("bbb")) == "bbb\n" result = echo("aaa\nbbb")() assert str(result | grep("bbb")) == "bbb\n"
def test_pipe_string_to_command(): str("aaa\nbbb" | grep('b')) == "bbb\n"