diff options
author | jquast <contact@jeffquast.com> | 2014-03-06 22:46:43 -0800 |
---|---|---|
committer | jquast <contact@jeffquast.com> | 2014-03-06 22:46:43 -0800 |
commit | 5a393f4af034e180beb275d90b1d8f7475b68a63 (patch) | |
tree | d7f38c69b67063d04a17b61f50b0072efc6d6b9a /tests/test_pxssh.py | |
parent | 886430f6d13e8b5555bf08a1220093b3ca5fc657 (diff) | |
download | pexpect-5a393f4af034e180beb275d90b1d8f7475b68a63.tar.gz |
closes issue #42, self.buffer decoded implicitly
create a unit tests which otherwise failed for python3 only: mock the
return value of set_unique_prompt for a value of False, which causes
ExceptionPxssh to raise.
previously, displaying self.buffer within the exception causes
bytes() to be implicitly decoded to str (unicode type in py3). python2
didn't care. it is implicitly decoded as 'ascii' encoding, without
warning.
Then, use the %r to represent it as b'xyz' in python3. Also, display
what we expected to be more helpful for the user. What is actually
happening here is the 'set PS1=' command is used so that pexpect can
more regularly understand when the prompt is awaiting command input, and
it is set to something more predictable. You'd be suprised what kind of
hackery can happen to prompt values even if PS1 is explicitly set,
especially in today's oh-my-zhs and git-prompt.sh extensions.
Diffstat (limited to 'tests/test_pxssh.py')
-rw-r--r-- | tests/test_pxssh.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/tests/test_pxssh.py b/tests/test_pxssh.py index b4994e5..0ee5bf5 100644 --- a/tests/test_pxssh.py +++ b/tests/test_pxssh.py @@ -26,7 +26,7 @@ class PxsshTestCase(SSHTestBase): ssh.expect('pong', timeout=10) assert ssh.prompt(timeout=10) ssh.logout() - + def test_wrong_pw(self): ssh = pxssh.pxssh() try: @@ -36,5 +36,12 @@ class PxsshTestCase(SSHTestBase): else: assert False, 'Password should have been refused' + def test_failed_set_unique_prompt(self): + ssh = pxssh.pxssh() + ssh.set_unique_prompt = lambda: False + with self.assertRaises(pxssh.ExceptionPxssh): + ssh.login('server', 'me', password='s3cret', + auto_prompt_reset=True) + if __name__ == '__main__': - unittest.main()
\ No newline at end of file + unittest.main() |