summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2017-10-30 01:13:22 +0100
committerGiampaolo Rodola <g.rodola@gmail.com>2017-10-30 01:13:22 +0100
commit1781c243e590d4dfdb3abff9a658fdc8bbec80b4 (patch)
tree3f632c59a486b88d127ecfb33d3077eaaa42616e
parentda32baf6ce6f648b709bc5cbd537e904022fc790 (diff)
downloadpsutil-1781c243e590d4dfdb3abff9a658fdc8bbec80b4.tar.gz
use new PYTHON_EXE
-rw-r--r--psutil/tests/__init__.py7
-rwxr-xr-xpsutil/tests/__main__.py12
-rwxr-xr-xpsutil/tests/test_misc.py4
3 files changed, 11 insertions, 12 deletions
diff --git a/psutil/tests/__init__.py b/psutil/tests/__init__.py
index 72f3076e..cb46a463 100644
--- a/psutil/tests/__init__.py
+++ b/psutil/tests/__init__.py
@@ -321,15 +321,14 @@ def create_proc_children_pair():
_TESTFN2 = os.path.basename(_TESTFN) + '2' # need to be relative
s = textwrap.dedent("""\
import subprocess, os, sys, time
- PYTHON_EXE = os.path.realpath(sys.executable)
s = "import os, time;"
s += "f = open('%s', 'w');"
s += "f.write(str(os.getpid()));"
s += "f.close();"
s += "time.sleep(60);"
- subprocess.Popen([PYTHON_EXE, '-c', s])
+ subprocess.Popen(['%s', '-c', s])
time.sleep(60)
- """ % _TESTFN2)
+ """ % (_TESTFN2, PYTHON_EXE))
# On Windows if we create a subprocess with CREATE_NO_WINDOW flag
# set (which is the default) a "conhost.exe" extra process will be
# spawned as a child. We don't want that.
@@ -721,7 +720,7 @@ def create_exe(outpath, c_code=None):
safe_rmpath(f.name)
else:
# copy python executable
- shutil.copyfile(sys.executable, outpath)
+ shutil.copyfile(PYTHON_EXE, outpath)
if POSIX:
st = os.stat(outpath)
os.chmod(outpath, st.st_mode | stat.S_IEXEC)
diff --git a/psutil/tests/__main__.py b/psutil/tests/__main__.py
index 475e6b81..2cdf5c42 100755
--- a/psutil/tests/__main__.py
+++ b/psutil/tests/__main__.py
@@ -21,11 +21,11 @@ try:
except ImportError:
from urllib2 import urlopen
+from psutil.tests import PYTHON_EXE
from psutil.tests import run_suite
HERE = os.path.abspath(os.path.dirname(__file__))
-PYTHON = os.path.basename(sys.executable)
GET_PIP_URL = "https://bootstrap.pypa.io/get-pip.py"
TEST_DEPS = []
if sys.version_info[:2] == (2, 6):
@@ -54,7 +54,7 @@ def install_pip():
f.flush()
print("installing pip")
- code = os.system('%s %s --user' % (sys.executable, f.name))
+ code = os.system('%s %s --user' % (PYTHON_EXE, f.name))
return code
@@ -68,12 +68,12 @@ def install_test_deps(deps=None):
opts = "--user" if not is_venv else ""
install_pip()
code = os.system('%s -m pip install %s --upgrade %s' % (
- sys.executable, opts, " ".join(deps)))
+ PYTHON_EXE, opts, " ".join(deps)))
return code
def main():
- usage = "%s -m psutil.tests [opts]" % PYTHON
+ usage = "%s -m psutil.tests [opts]" % PYTHON_EXE
parser = optparse.OptionParser(usage=usage, description="run unit tests")
parser.add_option("-i", "--install-deps",
action="store_true", default=False,
@@ -88,8 +88,8 @@ def main():
try:
__import__(dep.split("==")[0])
except ImportError:
- sys.exit("%r lib is not installed; run:\n"
- "%s -m psutil.tests --install-deps" % (dep, PYTHON))
+ sys.exit("%r lib is not installed; run %s -m psutil.tests "
+ "--install-deps" % (dep, PYTHON_EXE))
run_suite()
diff --git a/psutil/tests/test_misc.py b/psutil/tests/test_misc.py
index 85bab84c..43b589eb 100755
--- a/psutil/tests/test_misc.py
+++ b/psutil/tests/test_misc.py
@@ -18,7 +18,6 @@ import os
import pickle
import socket
import stat
-import sys
from psutil import LINUX
from psutil import POSIX
@@ -49,6 +48,7 @@ from psutil.tests import HAS_SENSORS_TEMPERATURES
from psutil.tests import import_module_by_path
from psutil.tests import is_namedtuple
from psutil.tests import mock
+from psutil.tests import PYTHON_EXE
from psutil.tests import reap_children
from psutil.tests import reload_module
from psutil.tests import retry
@@ -652,7 +652,7 @@ class TestScripts(unittest.TestCase):
if args:
exe = exe + ' ' + args
try:
- out = sh(sys.executable + ' ' + exe, **kwds).strip()
+ out = sh(PYTHON_EXE + ' ' + exe, **kwds).strip()
except RuntimeError as err:
if 'AccessDenied' in str(err):
return str(err)