def test_exe(self):
sproc = get_test_subprocess()
exe = psutil.Process(sproc.pid).exe()
try:
self.assertEqual(exe, PYTHON)
except AssertionError:
if WINDOWS and len(exe) == len(PYTHON):
# on Windows we don't care about case sensitivity
normcase = os.path.normcase
self.assertEqual(normcase(exe), normcase(PYTHON))
else:
# certain platforms such as BSD are more accurate returning:
# "/usr/local/bin/python2.7"
# ...instead of:
# "/usr/local/bin/python"
# We do not want to consider this difference in accuracy
# an error.
ver = "%s.%s" % (sys.version_info[0], sys.version_info[1])
try:
self.assertEqual(exe.replace(ver, ''),
PYTHON.replace(ver, ''))
except AssertionError:
# Tipically OSX. Really not sure what to do here.
pass
subp = subprocess.Popen([exe, '-c', 'import os; print("hey")'],
stdout=subprocess.PIPE)
out, _ = subp.communicate()
self.assertEqual(out.strip(), b'hey')
评论列表
文章目录