Skip to content

Commit

Permalink
use new PYTHON_EXE
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Oct 30, 2017
1 parent da32baf commit 1781c24
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
7 changes: 3 additions & 4 deletions psutil/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions psutil/tests/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
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):
Expand Down Expand Up @@ -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


Expand All @@ -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,
Expand All @@ -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()


Expand Down
4 changes: 2 additions & 2 deletions psutil/tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import pickle
import socket
import stat
import sys

from psutil import LINUX
from psutil import POSIX
Expand Down Expand Up @@ -49,6 +48,7 @@
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
Expand Down Expand Up @@ -652,7 +652,7 @@ def assert_stdout(exe, args=None, **kwds):
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)
Expand Down

0 comments on commit 1781c24

Please sign in to comment.