Exemple #1
0
def test_pipe_command_to_function():
    assert (echo("aaa\nbbb") |
            (lambda output: [item.upper()
                             for item in output.split()]) == ["AAA", "BBB"])

    assert (echo("aaa\nbbb") |
            (lambda stdout: [line.strip().upper()
                             for line in stdout]) == ["AAA", "BBB"])
Exemple #2
0
def test_iter():
    assert list(echo("a\nb\nc")) == ["a\n", "b\n", "c\n"]
    assert list(echo('a', 'b', 'c').iter_words()) == ["a", "b", "c"]

    tic = None
    delay = .01
    for i, line in enumerate(
            echo_messages(count=3, delay=delay, message='hello world {}')):
        toc = time.time()
        if tic is not None:
            # Verify that the message is indeed delayed
            assert toc - tic > .8 * delay
        assert line.strip() == f"hello world {i}"
        tic = time.time()
Exemple #3
0
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"
Exemple #4
0
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"
Exemple #5
0
def test_return_properties():
    assert true.returncode == 0
    assert false.returncode != 0
    assert echo('hello world').stdout == "hello world\n"
    assert (echo_messages(stream="stderr", count=1,
                          message="hello world").stderr == "hello world\n")
Exemple #6
0
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"
Exemple #7
0
def test_str():
    assert str(echo("hello world")) == "hello world\n"
    assert str(echo("καλημέρα", _text=False)) == "καλημέρα\n"
    assert (str("καλημέρα".encode('iso-8859-7')
                | cat(_text=False, _encoding='iso-8859-7')) == "καλημέρα")