Date: Mon, 27 Sep 2021 15:50:35 GMT From: =?utf-8?Q?Stefan E=C3=9Fer?= <se@FreeBSD.org> To: ports-committers@FreeBSD.org, dev-commits-ports-all@FreeBSD.org, dev-commits-ports-main@FreeBSD.org Subject: git: a642f92e86d3 - main - misc/py-pexpect: fix most of the test cases Message-ID: <202109271550.18RFoZuU023509@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch main has been updated by se: URL: https://cgit.FreeBSD.org/ports/commit/?id=a642f92e86d3b022e67d99f1c1dbd9fe6499c634 commit a642f92e86d3b022e67d99f1c1dbd9fe6499c634 Author: Stefan Eßer <se@FreeBSD.org> AuthorDate: 2021-09-27 13:49:11 +0000 Commit: Stefan Eßer <se@FreeBSD.org> CommitDate: 2021-09-27 15:49:50 +0000 misc/py-pexpect: fix most of the test cases A number of test cases included in the pexpect distribution failed on FreeBSD. The patches included in the commit fix most of these tests. One of the tests used /bin/bash and long options for the nl command. Other tests assumed pipe buffers larger than provided by FreeBSD. 3 tests are still failing: tests/test_replwrap.py::REPLWrapTestCase::test_existing_spawn FAILED The text received contains bracketed paste escape characters when a bash version 5.1 or newer is installed. There may be another problem with this test, though, since it seems to depend on some bash rc file of the account executing this test. tests/test_socket.py::ExpectTestCase::test_interrupt FAILED tests/test_socket.py::ExpectTestCase::test_multiple_interrupts FAILED These two test seem to fail due to an early exit of the sending process. It appears to be in Zombie state and cannot be signaled. The "non-blocking read" seems to be blocking in this situation. The real cause is unclear, it seems to be a mismatch between process lifetime semantics in Linux and FreeBSD. I have removed an infinite wait loop with these patches, which causes a test failure to be detected (instead of preventing the execution of any further test cases). I have created a pull request on Github to get these patches into the upstream, but it seems that the owner of the pexpect repository is not very active. Approved by: sunpoet (maintainer) --- misc/py-pexpect/Makefile | 1 + misc/py-pexpect/files/patch-pexpect_bashrc.sh | 8 ++++ .../files/patch-tests_PexpectTestCase.py | 11 +++++ misc/py-pexpect/files/patch-tests_test__expect.py | 47 ++++++++++++++++++++++ misc/py-pexpect/files/patch-tests_test__misc.py | 20 +++++++++ .../files/patch-tests_test__popen__spawn.py | 20 +++++++++ .../py-pexpect/files/patch-tests_test__replwrap.py | 11 +++++ misc/py-pexpect/files/patch-tests_test__socket.py | 26 ++++++++++++ 8 files changed, 144 insertions(+) diff --git a/misc/py-pexpect/Makefile b/misc/py-pexpect/Makefile index bfd97b12b97f..c234ebf85a97 100644 --- a/misc/py-pexpect/Makefile +++ b/misc/py-pexpect/Makefile @@ -2,6 +2,7 @@ PORTNAME= pexpect PORTVERSION= 4.8.0 +PORTREVISION= 1 CATEGORIES= misc python MASTER_SITES= CHEESESHOP PKGNAMEPREFIX= ${PYTHON_PKGNAMEPREFIX} diff --git a/misc/py-pexpect/files/patch-pexpect_bashrc.sh b/misc/py-pexpect/files/patch-pexpect_bashrc.sh new file mode 100644 index 000000000000..da3b2719271c --- /dev/null +++ b/misc/py-pexpect/files/patch-pexpect_bashrc.sh @@ -0,0 +1,8 @@ +--- pexpect/bashrc.sh.orig 2020-01-17 17:08:15 UTC ++++ pexpect/bashrc.sh +@@ -14,3 +14,5 @@ PS1="$" + + # Unset PROMPT_COMMAND, so that it can't change PS1 to something unexpected. + unset PROMPT_COMMAND ++ ++bind 'set enable-bracketed-paste off' diff --git a/misc/py-pexpect/files/patch-tests_PexpectTestCase.py b/misc/py-pexpect/files/patch-tests_PexpectTestCase.py new file mode 100644 index 000000000000..4f71643ec7f1 --- /dev/null +++ b/misc/py-pexpect/files/patch-tests_PexpectTestCase.py @@ -0,0 +1,11 @@ +--- tests/PexpectTestCase.py.orig 2020-01-17 17:08:15 UTC ++++ 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/misc/py-pexpect/files/patch-tests_test__expect.py b/misc/py-pexpect/files/patch-tests_test__expect.py new file mode 100644 index 000000000000..5d068493d7e9 --- /dev/null +++ b/misc/py-pexpect/files/patch-tests_test__expect.py @@ -0,0 +1,47 @@ +--- tests/test_expect.py.orig 2021-09-22 12:21:58 UTC ++++ tests/test_expect.py +@@ -411,7 +411,7 @@ class ExpectTestCase (PexpectTestCase.PexpectTestCase): + def test_before_across_chunks(self): + # https://github.com/pexpect/pexpect/issues/478 + child = pexpect.spawn( +- '''/bin/bash -c "openssl rand -base64 {} 2>/dev/null | head -500 | nl --number-format=rz --number-width=5 2>&1 ; echo 'PATTERN!!!'"'''.format(1024 * 1024 * 2), ++ '''/bin/sh -c "openssl rand -base64 {} 2>/dev/null | head -500 | nl -n rz -w 5 2>&1 ; echo 'PATTERN!!!'"'''.format(1024 * 1024 * 2), + searchwindowsize=128 + ) + child.expect(['PATTERN']) +@@ -456,7 +456,7 @@ class ExpectTestCase (PexpectTestCase.PexpectTestCase): + child = pexpect.spawn('cat', echo=False) + child.sendline('BEGIN') + for i in range(100): +- child.sendline('foo' * 100) ++ child.sendline('foo' * 10) + e = child.expect([b'xyzzy', pexpect.TIMEOUT], + searchwindowsize=10, timeout=0.001) + self.assertEqual(e, 1) +@@ -473,7 +473,7 @@ class ExpectTestCase (PexpectTestCase.PexpectTestCase): + child = pexpect.spawn('cat', echo=False) + child.sendline('BEGIN') + for i in range(100): +- child.sendline('foo' * 100) ++ child.sendline('foo' * 10) + e = child.expect([b'xyzzy', pexpect.TIMEOUT], + searchwindowsize=10, timeout=0.5) + self.assertEqual(e, 1) +@@ -569,13 +569,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): diff --git a/misc/py-pexpect/files/patch-tests_test__misc.py b/misc/py-pexpect/files/patch-tests_test__misc.py new file mode 100644 index 000000000000..668854c6b5de --- /dev/null +++ b/misc/py-pexpect/files/patch-tests_test__misc.py @@ -0,0 +1,20 @@ +--- tests/test_misc.py.orig 2020-01-17 17:08:15 UTC ++++ 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) + diff --git a/misc/py-pexpect/files/patch-tests_test__popen__spawn.py b/misc/py-pexpect/files/patch-tests_test__popen__spawn.py new file mode 100644 index 000000000000..e95c4f38abf9 --- /dev/null +++ b/misc/py-pexpect/files/patch-tests_test__popen__spawn.py @@ -0,0 +1,20 @@ +--- tests/test_popen_spawn.py.orig 2020-01-17 17:08:15 UTC ++++ 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): diff --git a/misc/py-pexpect/files/patch-tests_test__replwrap.py b/misc/py-pexpect/files/patch-tests_test__replwrap.py new file mode 100644 index 000000000000..7f98316ee132 --- /dev/null +++ b/misc/py-pexpect/files/patch-tests_test__replwrap.py @@ -0,0 +1,11 @@ +--- tests/test_replwrap.py.orig 2021-09-22 14:15:55 UTC ++++ tests/test_replwrap.py +@@ -24,7 +24,7 @@ class REPLWrapTestCase(unittest.TestCase): + + def test_bash(self): + bash = replwrap.bash() +- res = bash.run_command("alias") ++ res = bash.run_command("alias xyzzy=true; alias") + assert 'alias' in res, res + + try: diff --git a/misc/py-pexpect/files/patch-tests_test__socket.py b/misc/py-pexpect/files/patch-tests_test__socket.py new file mode 100644 index 000000000000..625390650e44 --- /dev/null +++ b/misc/py-pexpect/files/patch-tests_test__socket.py @@ -0,0 +1,26 @@ +--- tests/test_socket.py.orig 2020-01-17 17:08:15 UTC ++++ tests/test_socket.py +@@ -201,8 +201,8 @@ class ExpectTestCase(PexpectTestCase.PexpectTestCase): + while not all_read.is_set(): + time.sleep(1.0) + os.kill(test_proc.pid, signal.SIGWINCH) +- while not timed_out.is_set(): +- time.sleep(1.0) ++# while not timed_out.is_set(): ++# time.sleep(1.0) + test_proc.join(timeout=5.0) + self.assertEqual(test_proc.exitcode, errno.ETIMEDOUT) + +@@ -214,9 +214,9 @@ class ExpectTestCase(PexpectTestCase.PexpectTestCase): + test_proc.start() + while not all_read.is_set(): + time.sleep(1.0) +- while not timed_out.is_set(): +- os.kill(test_proc.pid, signal.SIGWINCH) +- time.sleep(1.0) ++# while not timed_out.is_set(): ++# os.kill(test_proc.pid, signal.SIGWINCH) ++# time.sleep(1.0) + test_proc.join(timeout=5.0) + self.assertEqual(test_proc.exitcode, errno.ETIMEDOUT) +
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202109271550.18RFoZuU023509>