Add expect feature

This commit is contained in:
jpic
2021-11-12 03:56:48 +01:00
parent 217777f60e
commit 93f40dc7dd
2 changed files with 50 additions and 35 deletions
+20 -1
View File
@@ -8,7 +8,6 @@ from shlax import Proc
@pytest.mark.parametrize(
'args',
(
['sh', '-c', 'echo hi'],
['echo hi'],
['sh -c "echo hi"'],
)
@@ -195,3 +194,23 @@ async def test_highlight_if_not_colored():
}
).wait()
proc.write.assert_called_with(b'h\x1b[31mi\n')
@pytest.mark.asyncio
async def test_expect():
proc = Proc(
'echo "x?"; read x; echo x=$x; echo "z?"; read z; echo z=$z',
expects=[
dict(
regexp=b'x?',
sendline=b'y\n',
),
dict(
regexp=b'z?',
sendline=b'w\n',
)
],
quiet=True,
)
await proc.wait()
assert proc.out == 'x?\nx=y\nz?\nz=w'