CBL-Mariner/SPECS/python-pexpect/sys_executable.patch

111 строки
4.5 KiB
Diff

From 6f78e3b7cec5adc7db56bae37f97adb05ca2ae5c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Chv=C3=A1tal?= <tchvatal@suse.com>
Date: Thu, 12 Mar 2020 12:35:21 +0100
Subject: [PATCH] Do not directly call python and use sys.executable
This makes sure the tests and wrapper works on systems where there
is no python2 nor /usr/bin/python available
---
pexpect/replwrap.py | 2 +-
tests/test_performance.py | 10 +++++-----
tests/test_replwrap.py | 3 ++-
tests/test_run.py | 2 +-
4 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/pexpect/replwrap.py b/pexpect/replwrap.py
index c930f1e4..6c34ce41 100644
--- a/pexpect/replwrap.py
+++ b/pexpect/replwrap.py
@@ -108,7 +108,7 @@ def run_command(self, command, timeout=-1, async_=False):
+ command)
return u''.join(res + [self.child.before])
-def python(command="python"):
+def python(command=sys.executable):
"""Start a Python shell and return a :class:`REPLWrapper` object."""
return REPLWrapper(command, u">>> ", u"import sys; sys.ps1={0!r}; sys.ps2={1!r}")
diff --git a/tests/test_performance.py b/tests/test_performance.py
index 63778af6..d7e2cd6a 100755
--- a/tests/test_performance.py
+++ b/tests/test_performance.py
@@ -45,7 +45,7 @@ def _iter_n(n):
return 'for n in range(1, %d+1): print(n)' % n
def plain_range(self, n):
- e = pexpect.spawn('python', timeout=100)
+ e = pexpect.spawn(sys.executable, timeout=100)
self.assertEqual(e.expect(b'>>>'), 0)
e.sendline(self._iter_n(n))
self.assertEqual(e.expect(br'\.{3}'), 0)
@@ -53,7 +53,7 @@ def plain_range(self, n):
self.assertEqual(e.expect([b'inquisition', '%d' % n]), 1)
def window_range(self, n):
- e = pexpect.spawn('python', timeout=100)
+ e = pexpect.spawn(sys.executable, timeout=100)
self.assertEqual(e.expect(b'>>>'), 0)
e.sendline(self._iter_n(n))
self.assertEqual(e.expect(r'\.{3}'), 0)
@@ -61,7 +61,7 @@ def window_range(self, n):
self.assertEqual(e.expect([b'inquisition', '%d' % n], searchwindowsize=20), 1)
def exact_range(self, n):
- e = pexpect.spawn('python', timeout=100)
+ e = pexpect.spawn(sys.executable, timeout=100)
self.assertEqual(e.expect_exact([b'>>>']), 0)
e.sendline(self._iter_n(n))
self.assertEqual(e.expect_exact([b'...']), 0)
@@ -69,7 +69,7 @@ def exact_range(self, n):
self.assertEqual(e.expect_exact([b'inquisition', '%d' % n],timeout=520), 1)
def ewin_range(self, n):
- e = pexpect.spawn('python', timeout=100)
+ e = pexpect.spawn(sys.executable, timeout=100)
self.assertEqual(e.expect_exact([b'>>>']), 0)
e.sendline(self._iter_n(n))
self.assertEqual(e.expect_exact([b'...']), 0)
@@ -77,7 +77,7 @@ def ewin_range(self, n):
self.assertEqual(e.expect_exact([b'inquisition', '%d' % n], searchwindowsize=20), 1)
def faster_range(self, n):
- e = pexpect.spawn('python', timeout=100)
+ e = pexpect.spawn(sys.executable, timeout=100)
self.assertEqual(e.expect(b'>>>'), 0)
e.sendline(('list(range(1, %d+1))' % n).encode('ascii'))
self.assertEqual(e.expect([b'inquisition', '%d' % n]), 1)
diff --git a/tests/test_replwrap.py b/tests/test_replwrap.py
index 06ca07b9..1e5ff873 100644
--- a/tests/test_replwrap.py
+++ b/tests/test_replwrap.py
@@ -2,6 +2,7 @@
import unittest
import re
import os
+import sys
import pexpect
from pexpect import replwrap
@@ -108,7 +109,7 @@ def test_no_change_prompt(self):
if platform.python_implementation() == 'PyPy':
raise unittest.SkipTest(skip_pypy)
- child = pexpect.spawn('python', echo=False, timeout=5, encoding='utf-8')
+ child = pexpect.spawn(sys.executable, echo=False, timeout=5, encoding='utf-8')
# prompt_change=None should mean no prompt change
py = replwrap.REPLWrapper(child, u">>> ", prompt_change=None,
continuation_prompt=u"... ")
diff --git a/tests/test_run.py b/tests/test_run.py
index 401ddc63..f750fb29 100755
--- a/tests/test_run.py
+++ b/tests/test_run.py
@@ -69,7 +69,7 @@ def tearDown(self):
super(RunFuncTestCase, self).tearDown()
def test_run_exit(self):
- (data, exitstatus) = self.runfunc('python exit1.py', withexitstatus=1)
+ (data, exitstatus) = self.runfunc(sys.executable + ' exit1.py', withexitstatus=1)
assert exitstatus == 1, "Exit status of 'python exit1.py' should be 1."
def test_run(self):