I'm trying to run tests on a game for a class. Basically trying to determine if the AI always wins or with what degree of confidence it does. I tried using pexpect
child = pexpect.spawn('./a.out')
child.expect('Are you player 1 or 2?:')
child.sendline(player)
game_play(child)
I defined a separate function for the gameplay but this simple step on getting it launched is timing out. This would definitely not be ideal for say 100 tests. Please assist.
The error code:
raise TIMEOUT(msg)
pexpect.exceptions.TIMEOUT: Timeout exceeded.
<pexpect.pty_spawn.spawn object at 0x1067638d0>
child.expect()
expects RE (regular expression) string so you should write
child.expect('Are you player 1 or 2\\?:')
or you can use expect_exact()
:
child.expect_exact('Are you player 1 or 2?:')