From b3a11ac3dba190dce355620935ef45260d6e721e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20E=C3=9Fer?= Date: Wed, 22 Sep 2021 14:57:11 +0200 Subject: Use only POSIX commands and options The hard-coded use of /bin/bash and of long options for nl does only work on Linux based systems with GNU textutils. If POSIX commands and options are used, this test becomes portable to other systems than Linux. --- tests/test_expect.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/test_expect.py') diff --git a/tests/test_expect.py b/tests/test_expect.py index c37e159..243bc34 100755 --- a/tests/test_expect.py +++ b/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']) -- cgit v1.2.1 From a48c3021c4c4cffc537122ac14d2c340ae75ad62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20E=C3=9Fer?= Date: Wed, 22 Sep 2021 15:00:08 +0200 Subject: Do not send more characters than can be buffered by cat The cat command on FreeBSD blocks if the default input buffer fills and not output can be sent. The test used to generate more than 10 KB of data before accepting the output generated by the cat program, causing cat to block (stop reading input) until the output buffer has been drained. There is no reason to send long lines in this test, therefore it is easily possible to perform the tests with lines that do not cause more than 4 KB (the default input buffer size on FreeBSD) to be sent before output from the cat program is checked. In order to not depend on such buffer sizes pexpect needs to check for output from the spawned command and buffer it, before it gets to execute the expect() function. Apparently this is not happening and thus the system dependent buffer size limit makes this test fail if its capacity is exceeded. --- tests/test_expect.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/test_expect.py') diff --git a/tests/test_expect.py b/tests/test_expect.py index 243bc34..c9087f4 100755 --- a/tests/test_expect.py +++ b/tests/test_expect.py @@ -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) -- cgit v1.2.1 From b717990ac74691f2081f4ab0c63d8829db9e8fa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20E=C3=9Fer?= Date: Wed, 22 Sep 2021 17:11:46 +0200 Subject: Replace deprecated assertRaisesRegexp with assertRaisesRegex The assertRaisesRegexp function appeared in Python-3.1 and was renamed to assertRaisesRegex in Python-3.2. --- tests/test_expect.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests/test_expect.py') diff --git a/tests/test_expect.py b/tests/test_expect.py index c9087f4..5553d28 100755 --- a/tests/test_expect.py +++ b/tests/test_expect.py @@ -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): -- cgit v1.2.1