def test_run(): # (Commits in this repo's history.) assert list(cmd.run('git log --abbrev=9 --format={} {}', '%p', '9cdfc6d46') | cmd.splitlines()) \ == [b'a515d0250', b'c90596c89', b''] assert (pysh.slurp(cmd.echo(b'hello') | cmd.run('tr h H')) # sh { echo hello | tr h H | slurp } ) == b'Hello' assert pysh.slurp( cmd.run('git log --oneline --reverse --abbrev=9') | cmd.run('grep -m1 {}', 'yield') | cmd.run('perl -lane {}', 'print $F[0]')) == b'91a20bf6b'
def test_pipeline(): assert list( cmd.cat(b'/etc/shells') | cmd.splitlines() # sh { cat /etc/shells | split -l } ) == open('/etc/shells', 'rb').read().rstrip(b"\n").split(b"\n") assert (pysh.slurp(cmd.run('git rev-parse {}', 'dbccdbe6f~2')) # sh { git rev-parse ${commitish} | slurp } ) == b'91a20bf6b4a72f1f84b2f57cf38b3f771dd35fda' # Input and output optional; check nothing blows up. cmd.devnull()()
def test_decode(): world = '\N{WORLD MAP}'.encode() assert pysh.slurp(cmd.echo(b'hello', world) | cmd.decode() | cmd.encode()) == b'hello ' + world
def test_echo(): assert (pysh.slurp(cmd.echo(b'hello', b'world'))) == b'hello world'
def test_run_check(): with pytest.raises(subprocess.CalledProcessError): pysh.slurp(cmd.run('false')) assert pysh.slurp(cmd.run('false', _check=False)) == b''