diff options
author | Filippo Carra <karrukola@users.noreply.github.com> | 2023-02-27 16:55:28 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-27 16:55:28 +0100 |
commit | 5268a0f8d9b2bd21b3a26adc89680091c8df416f (patch) | |
tree | fbf03a3559c261b8a492efd5d83f9eabf09d2596 | |
parent | 0e668303b0248a74716a2b518b63d23bbbdf29d7 (diff) | |
parent | 4c768bd317fcb5ab6231bf21fc277b8b6ac36fa3 (diff) | |
download | pexpect-5268a0f8d9b2bd21b3a26adc89680091c8df416f.tar.gz |
Merge branch 'pexpect:master' into modern_async
-rw-r--r-- | pexpect/pxssh.py | 5 | ||||
-rw-r--r-- | tests/PexpectTestCase.py | 2 | ||||
-rwxr-xr-x | tests/deprecated_test_filedescriptor.py | 2 | ||||
-rwxr-xr-x | tests/deprecated_test_run_out_of_pty.py | 2 | ||||
-rwxr-xr-x | tests/fakessh/ssh | 2 | ||||
-rwxr-xr-x | tests/test_ansi.py | 2 | ||||
-rwxr-xr-x | tests/test_command_list_split.py | 2 | ||||
-rwxr-xr-x | tests/test_constructor.py | 2 | ||||
-rwxr-xr-x | tests/test_ctrl_chars.py | 2 | ||||
-rwxr-xr-x | tests/test_destructor.py | 2 | ||||
-rwxr-xr-x | tests/test_dotall.py | 2 | ||||
-rwxr-xr-x | tests/test_expect.py | 10 | ||||
-rwxr-xr-x | tests/test_filedescriptor.py | 2 | ||||
-rwxr-xr-x | tests/test_interact.py | 10 | ||||
-rwxr-xr-x | tests/test_isalive.py | 2 | ||||
-rwxr-xr-x | tests/test_log.py | 2 | ||||
-rwxr-xr-x | tests/test_misc.py | 6 | ||||
-rwxr-xr-x | tests/test_missing_command.py | 2 | ||||
-rwxr-xr-x | tests/test_performance.py | 2 | ||||
-rw-r--r-- | tests/test_popen_spawn.py | 10 | ||||
-rwxr-xr-x | tests/test_run.py | 22 | ||||
-rwxr-xr-x | tests/test_screen.py | 2 | ||||
-rw-r--r-- | tests/test_socket.py | 2 | ||||
-rwxr-xr-x | tests/test_timeout_pattern.py | 2 | ||||
-rw-r--r-- | tests/test_unicode.py | 2 | ||||
-rwxr-xr-x | tests/test_winsize.py | 2 |
26 files changed, 50 insertions, 53 deletions
diff --git a/pexpect/pxssh.py b/pexpect/pxssh.py index 3d53bd9..bfefc7a 100644 --- a/pexpect/pxssh.py +++ b/pexpect/pxssh.py @@ -143,8 +143,7 @@ class pxssh (spawn): # used to set shell command-line prompt to UNIQUE_PROMPT. self.PROMPT_SET_SH = r"PS1='[PEXPECT]\$ '" self.PROMPT_SET_CSH = r"set prompt='[PEXPECT]\$ '" - self.SSH_OPTS = ("-o'RSAAuthentication=no'" - + " -o 'PubkeyAuthentication=no'") + self.SSH_OPTS = (" -o 'PubkeyAuthentication=no'") # Disabling host key checking, makes you vulnerable to MITM attacks. # + " -o 'StrictHostKeyChecking=no'" # + " -o 'UserKnownHostsFile /dev/null' ") @@ -152,7 +151,7 @@ class pxssh (spawn): # displaying a GUI password dialog. I have not figured out how to # disable only SSH_ASKPASS without also disabling X11 forwarding. # Unsetting SSH_ASKPASS on the remote side doesn't disable it! Annoying! - #self.SSH_OPTS = "-x -o'RSAAuthentication=no' -o 'PubkeyAuthentication=no'" + #self.SSH_OPTS = "-x -o 'PubkeyAuthentication=no'" self.force_password = False self.debug_command_string = debug_command_string diff --git a/tests/PexpectTestCase.py b/tests/PexpectTestCase.py index 307437e..5d7a168 100644 --- a/tests/PexpectTestCase.py +++ b/tests/PexpectTestCase.py @@ -97,7 +97,7 @@ class PexpectTestCase(unittest.TestCase): raise AssertionError("%s was not raised" % excClass) @contextlib.contextmanager - def assertRaisesRegexp(self, excClass, pattern): + def assertRaisesRegex(self, excClass, pattern): import re try: yield diff --git a/tests/deprecated_test_filedescriptor.py b/tests/deprecated_test_filedescriptor.py index 6b0ef3e..cd930cf 100755 --- a/tests/deprecated_test_filedescriptor.py +++ b/tests/deprecated_test_filedescriptor.py @@ -72,7 +72,7 @@ class ExpectTestCase(PexpectTestCase.PexpectTestCase): if __name__ == '__main__': unittest.main() -suite = unittest.makeSuite(ExpectTestCase, 'test') +suite = unittest.TestLoader().loadTestsFromTestCase(ExpectTestCase) #fout = open('delete_me_1','wb') #fout.write(the_old_way) diff --git a/tests/deprecated_test_run_out_of_pty.py b/tests/deprecated_test_run_out_of_pty.py index 3090147..b34094e 100755 --- a/tests/deprecated_test_run_out_of_pty.py +++ b/tests/deprecated_test_run_out_of_pty.py @@ -47,5 +47,5 @@ class ExpectTestCase(PexpectTestCase.PexpectTestCase): if __name__ == '__main__': unittest.main() -suite = unittest.makeSuite(ExpectTestCase,'test') +suite = unittest.TestLoader().loadTestsFromTestCase(ExpectTestCase) diff --git a/tests/fakessh/ssh b/tests/fakessh/ssh index 4a5be1b..74ffe20 100755 --- a/tests/fakessh/ssh +++ b/tests/fakessh/ssh @@ -62,7 +62,7 @@ prompt = "$" while True: cmd = input(prompt) if cmd.startswith('PS1='): - prompt = eval(cmd[4:]).replace('\$', '$') + prompt = eval(cmd[4:]).replace(r'\$', '$') elif cmd == 'ping': print('pong') elif cmd.startswith('ls'): diff --git a/tests/test_ansi.py b/tests/test_ansi.py index 3d73fe8..a49c663 100755 --- a/tests/test_ansi.py +++ b/tests/test_ansi.py @@ -236,5 +236,5 @@ class ansiTestCase (PexpectTestCase.PexpectTestCase): if __name__ == '__main__': unittest.main() -suite = unittest.makeSuite(ansiTestCase,'test') +suite = unittest.TestLoader().loadTestsFromTestCase(ansiTestCase) diff --git a/tests/test_command_list_split.py b/tests/test_command_list_split.py index 370f46e..eeaf6c0 100755 --- a/tests/test_command_list_split.py +++ b/tests/test_command_list_split.py @@ -37,4 +37,4 @@ class SplitCommandLineTestCase(PexpectTestCase.PexpectTestCase): if __name__ == '__main__': unittest.main() -suite = unittest.makeSuite(SplitCommandLineTestCase,'test') +suite = unittest.TestLoader().loadTestsFromTestCase(SplitCommandLineTestCase) diff --git a/tests/test_constructor.py b/tests/test_constructor.py index 98c473a..1b4d717 100755 --- a/tests/test_constructor.py +++ b/tests/test_constructor.py @@ -44,5 +44,5 @@ class TestCaseConstructor(PexpectTestCase.PexpectTestCase): if __name__ == '__main__': unittest.main() -suite = unittest.makeSuite(TestCaseConstructor,'test') +suite = unittest.TestLoader().loadTestsFromTestCase(TestCaseConstructor) diff --git a/tests/test_ctrl_chars.py b/tests/test_ctrl_chars.py index 032027c..0719fc7 100755 --- a/tests/test_ctrl_chars.py +++ b/tests/test_ctrl_chars.py @@ -124,5 +124,5 @@ class TestCtrlChars(PexpectTestCase.PexpectTestCase): if __name__ == '__main__': unittest.main() -suite = unittest.makeSuite(TestCtrlChars,'test') +suite = unittest.TestLoader().loadTestsFromTestCase(TestCtrlChars) diff --git a/tests/test_destructor.py b/tests/test_destructor.py index d27b6f6..01d89a0 100755 --- a/tests/test_destructor.py +++ b/tests/test_destructor.py @@ -80,5 +80,5 @@ class TestCaseDestructor(PexpectTestCase.PexpectTestCase): if __name__ == '__main__': unittest.main() -suite = unittest.makeSuite(TestCaseDestructor,'test') +suite = unittest.TestLoader().loadTestsFromTestCase(TestCaseDestructor) diff --git a/tests/test_dotall.py b/tests/test_dotall.py index 68aef3f..44c58c5 100755 --- a/tests/test_dotall.py +++ b/tests/test_dotall.py @@ -39,5 +39,5 @@ class TestCaseDotall(PexpectTestCase.PexpectTestCase): if __name__ == '__main__': unittest.main() -suite = unittest.makeSuite(TestCaseDotall,'test') +suite = unittest.TestLoader().loadTestsFromTestCase(TestCaseDotall) diff --git a/tests/test_expect.py b/tests/test_expect.py index 5e54d65..c6d72da 100755 --- a/tests/test_expect.py +++ b/tests/test_expect.py @@ -643,13 +643,13 @@ class ExpectTestCase (PexpectTestCase.PexpectTestCase): def test_bad_arg(self): p = pexpect.spawn('cat') - with self.assertRaisesRegexp(TypeError, '.*must be one of'): + with self.assertRaisesRegex(TypeError, '.*must be one of'): p.expect(1) - with self.assertRaisesRegexp(TypeError, '.*must be one of'): + with self.assertRaisesRegex(TypeError, '.*must be one of'): p.expect([1, b'2']) - with self.assertRaisesRegexp(TypeError, '.*must be one of'): + with self.assertRaisesRegex(TypeError, '.*must be one of'): p.expect_exact(1) - with self.assertRaisesRegexp(TypeError, '.*must be one of'): + with self.assertRaisesRegex(TypeError, '.*must be one of'): p.expect_exact([1, b'2']) def test_timeout_none(self): @@ -714,4 +714,4 @@ class ExpectTestCase (PexpectTestCase.PexpectTestCase): if __name__ == '__main__': unittest.main() -suite = unittest.makeSuite(ExpectTestCase, 'test') +suite = unittest.TestLoader().loadTestsFromTestCase(ExpectTestCase) diff --git a/tests/test_filedescriptor.py b/tests/test_filedescriptor.py index d9164e1..3f9d954 100755 --- a/tests/test_filedescriptor.py +++ b/tests/test_filedescriptor.py @@ -69,4 +69,4 @@ class ExpectTestCase(PexpectTestCase.PexpectTestCase): if __name__ == '__main__': unittest.main() -suite = unittest.makeSuite(ExpectTestCase, 'test') +suite = unittest.TestLoader().loadTestsFromTestCase(ExpectTestCase) diff --git a/tests/test_interact.py b/tests/test_interact.py index 4afbd18..7205d80 100755 --- a/tests/test_interact.py +++ b/tests/test_interact.py @@ -62,8 +62,8 @@ class InteractTestCase (PexpectTestCase.PexpectTestCase): p.sendcontrol(']') p.expect('29<STOP>') p.send('\x00') - if not os.environ.get('TRAVIS', None): - # on Travis-CI, we sometimes miss trailing stdout from the + if not os.environ.get('CI', None): + # on CI platforms, we sometimes miss trailing stdout from the # chain of child processes, not entirely sure why. So this # is skipped on such systems. p.expect('0<STOP>') @@ -84,8 +84,8 @@ class InteractTestCase (PexpectTestCase.PexpectTestCase): p.expect('206<STOP>') # [206, 146] p.expect('146<STOP>') p.send('\x00') - if not os.environ.get('TRAVIS', None): - # on Travis-CI, we sometimes miss trailing stdout from the + if not os.environ.get('CI', None): + # on CI platforms, we sometimes miss trailing stdout from the # chain of child processes, not entirely sure why. So this # is skipped on such systems. p.expect('0<STOP>') @@ -97,5 +97,5 @@ class InteractTestCase (PexpectTestCase.PexpectTestCase): if __name__ == '__main__': unittest.main() -suite = unittest.makeSuite(InteractTestCase, 'test') +suite = unittest.TestLoader().loadTestsFromTestCase(InteractTestCase) diff --git a/tests/test_isalive.py b/tests/test_isalive.py index 5e3021e..ba2b5d4 100755 --- a/tests/test_isalive.py +++ b/tests/test_isalive.py @@ -121,5 +121,5 @@ class IsAliveTestCase(PexpectTestCase.PexpectTestCase): if __name__ == '__main__': unittest.main() -suite = unittest.makeSuite(IsAliveTestCase, 'test') +suite = unittest.TestLoader().loadTestsFromTestCase(IsAliveTestCase) diff --git a/tests/test_log.py b/tests/test_log.py index 4ad2256..e2defff 100755 --- a/tests/test_log.py +++ b/tests/test_log.py @@ -104,5 +104,5 @@ class TestCaseLog(PexpectTestCase.PexpectTestCase): if __name__ == '__main__': unittest.main() -suite = unittest.makeSuite(TestCaseLog,'test') +suite = unittest.TestLoader().loadTestsFromTestCase(TestCaseLog) diff --git a/tests/test_misc.py b/tests/test_misc.py index 7784759..5c81f92 100755 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -214,7 +214,7 @@ class TestCaseMisc(PexpectTestCase.PexpectTestCase): # Force an invalid state to test isalive child.ptyproc.terminated = 0 try: - with self.assertRaisesRegexp(pexpect.ExceptionPexpect, + with self.assertRaisesRegex(pexpect.ExceptionPexpect, ".*" + expect_errmsg): child.isalive() finally: @@ -224,7 +224,7 @@ class TestCaseMisc(PexpectTestCase.PexpectTestCase): def test_bad_arguments_suggest_fdpsawn(self): " assert custom exception for spawn(int). " expect_errmsg = "maybe you want to use fdpexpect.fdspawn" - with self.assertRaisesRegexp(pexpect.ExceptionPexpect, + with self.assertRaisesRegex(pexpect.ExceptionPexpect, ".*" + expect_errmsg): pexpect.spawn(1) @@ -370,4 +370,4 @@ class TestCaseMisc(PexpectTestCase.PexpectTestCase): if __name__ == '__main__': unittest.main() -suite = unittest.makeSuite(TestCaseMisc,'test') +suite = unittest.TestLoader().loadTestsFromTestCase(TestCaseMisc) diff --git a/tests/test_missing_command.py b/tests/test_missing_command.py index 92e4733..3775632 100755 --- a/tests/test_missing_command.py +++ b/tests/test_missing_command.py @@ -34,5 +34,5 @@ class MissingCommandTestCase (PexpectTestCase.PexpectTestCase): if __name__ == '__main__': unittest.main() -suite = unittest.makeSuite(MissingCommandTestCase,'test') +suite = unittest.TestLoader().loadTestsFromTestCase(MissingCommandTestCase) diff --git a/tests/test_performance.py b/tests/test_performance.py index d7e2cd6..05027a0 100755 --- a/tests/test_performance.py +++ b/tests/test_performance.py @@ -110,4 +110,4 @@ class PerformanceTestCase (PexpectTestCase.PexpectTestCase): if __name__ == "__main__": unittest.main() -suite = unittest.makeSuite(PerformanceTestCase,'test') +suite = unittest.TestLoader().loadTestsFromTestCase(PerformanceTestCase) diff --git a/tests/test_popen_spawn.py b/tests/test_popen_spawn.py index fca7493..6168148 100644 --- a/tests/test_popen_spawn.py +++ b/tests/test_popen_spawn.py @@ -110,13 +110,13 @@ class ExpectTestCase (PexpectTestCase.PexpectTestCase): def test_bad_arg(self): p = PopenSpawn('cat') - with self.assertRaisesRegexp(TypeError, '.*must be one of'): + with self.assertRaisesRegex(TypeError, '.*must be one of'): p.expect(1) - with self.assertRaisesRegexp(TypeError, '.*must be one of'): + with self.assertRaisesRegex(TypeError, '.*must be one of'): p.expect([1, b'2']) - with self.assertRaisesRegexp(TypeError, '.*must be one of'): + with self.assertRaisesRegex(TypeError, '.*must be one of'): p.expect_exact(1) - with self.assertRaisesRegexp(TypeError, '.*must be one of'): + with self.assertRaisesRegex(TypeError, '.*must be one of'): p.expect_exact([1, b'2']) def test_timeout_none(self): @@ -136,4 +136,4 @@ class ExpectTestCase (PexpectTestCase.PexpectTestCase): if __name__ == '__main__': unittest.main() -suite = unittest.makeSuite(ExpectTestCase, 'test') +suite = unittest.TestLoader().loadTestsFromTestCase(ExpectTestCase) diff --git a/tests/test_run.py b/tests/test_run.py index f750fb2..baa6b49 100755 --- a/tests/test_run.py +++ b/tests/test_run.py @@ -22,7 +22,6 @@ PEXPECT LICENSE import pexpect import unittest import subprocess -import tempfile import sys import os from . import PexpectTestCase @@ -59,15 +58,10 @@ class RunFuncTestCase(PexpectTestCase.PexpectTestCase): prep_subprocess_out = staticmethod(lambda x: x) def setUp(self): - fd, self.rcfile = tempfile.mkstemp() - os.write(fd, b'PS1=GO: \n') - os.close(fd) + self.runenv = os.environ.copy() + self.runenv['PS1'] = 'GO:' super(RunFuncTestCase, self).setUp() - def tearDown(self): - os.unlink(self.rcfile) - super(RunFuncTestCase, self).tearDown() - def test_run_exit(self): (data, exitstatus) = self.runfunc(sys.executable + ' exit1.py', withexitstatus=1) assert exitstatus == 1, "Exit status of 'python exit1.py' should be 1." @@ -106,9 +100,10 @@ class RunFuncTestCase(PexpectTestCase.PexpectTestCase): ] (data, exitstatus) = pexpect.run( - 'bash --rcfile {0}'.format(self.rcfile), + 'bash --norc', withexitstatus=True, events=events, + env=self.runenv, timeout=10) assert exitstatus == 0 @@ -118,9 +113,10 @@ class RunFuncTestCase(PexpectTestCase.PexpectTestCase): ] (data, exitstatus) = pexpect.run( - 'bash --rcfile {0}'.format(self.rcfile), + 'bash --norc', withexitstatus=True, events=events, + env=self.runenv, timeout=10) assert exitstatus == 0 @@ -130,18 +126,20 @@ class RunFuncTestCase(PexpectTestCase.PexpectTestCase): ] (data, exitstatus) = pexpect.run( - 'bash --rcfile {0}'.format(self.rcfile), + 'bash --norc', withexitstatus=True, events=events, + env=self.runenv, timeout=10) assert exitstatus == 0 def test_run_event_typeerror(self): events = [('GO:', -1)] with self.assertRaises(TypeError): - pexpect.run('bash --rcfile {0}'.format(self.rcfile), + pexpect.run('bash --norc', withexitstatus=True, events=events, + env=self.runenv, timeout=10) def _method_events_callback(self, values): diff --git a/tests/test_screen.py b/tests/test_screen.py index 2429e57..9e275bc 100755 --- a/tests/test_screen.py +++ b/tests/test_screen.py @@ -282,6 +282,6 @@ class screenTestCase (PexpectTestCase.PexpectTestCase): if __name__ == '__main__': unittest.main() -suite = unittest.makeSuite(screenTestCase,'test') +suite = unittest.TestLoader().loadTestsFromTestCase(screenTestCase) diff --git a/tests/test_socket.py b/tests/test_socket.py index a8c8595..548d90a 100644 --- a/tests/test_socket.py +++ b/tests/test_socket.py @@ -277,4 +277,4 @@ class ExpectTestCase(PexpectTestCase.PexpectTestCase): if __name__ == '__main__': unittest.main() -suite = unittest.makeSuite(ExpectTestCase, 'test') +suite = unittest.TestLoader().loadTestsFromTestCase(ExpectTestCase) diff --git a/tests/test_timeout_pattern.py b/tests/test_timeout_pattern.py index 5f610ef..35d4816 100755 --- a/tests/test_timeout_pattern.py +++ b/tests/test_timeout_pattern.py @@ -89,4 +89,4 @@ class Exp_TimeoutTestCase(PexpectTestCase.PexpectTestCase): if __name__ == '__main__': unittest.main() -suite = unittest.makeSuite(Exp_TimeoutTestCase,'test') +suite = unittest.TestLoader().loadTestsFromTestCase(Exp_TimeoutTestCase) diff --git a/tests/test_unicode.py b/tests/test_unicode.py index 9b5b988..6103167 100644 --- a/tests/test_unicode.py +++ b/tests/test_unicode.py @@ -184,4 +184,4 @@ class UnicodeTests(PexpectTestCase.PexpectTestCase): if __name__ == '__main__': unittest.main() -suite = unittest.makeSuite(UnicodeTests, 'test') +suite = unittest.TestLoader().loadTestsFromTestCase(UnicodeTests) diff --git a/tests/test_winsize.py b/tests/test_winsize.py index be16773..6fc78ce 100755 --- a/tests/test_winsize.py +++ b/tests/test_winsize.py @@ -55,6 +55,6 @@ class TestCaseWinsize(PexpectTestCase.PexpectTestCase): if __name__ == '__main__': unittest.main() -suite = unittest.makeSuite(TestCaseWinsize,'test') +suite = unittest.TestLoader().loadTestsFromTestCase(TestCaseWinsize) |