disable Popen shell option in test_bin.py

Fix failing tests from #1289 caused by bad quoting for Windows shell
Improve test_bin_hy_builtins and warn that it fails from IPython.
This commit is contained in:
gilch 2017-08-30 15:37:12 -06:00
parent c69f8ebb79
commit 50c21ca38c

View File

@ -5,12 +5,16 @@
# license. See the LICENSE. # license. See the LICENSE.
import os import os
import subprocess from pipes import quote
import re import re
from hy._compat import PY3, PY35 import shlex
from hy.importer import get_bytecode_path import subprocess
import pytest import pytest
from hy._compat import PY3, PY35, builtins
from hy.importer import get_bytecode_path
hy_dir = os.environ.get('HY_DIR', '') hy_dir = os.environ.get('HY_DIR', '')
@ -24,12 +28,14 @@ def run_cmd(cmd, stdin_data=None, expect=0, dontwritebytecode=False):
if dontwritebytecode: if dontwritebytecode:
env = dict(os.environ) env = dict(os.environ)
env["PYTHONDONTWRITEBYTECODE"] = "1" env["PYTHONDONTWRITEBYTECODE"] = "1"
p = subprocess.Popen(os.path.join(hy_dir, cmd), cmd = shlex.split(cmd)
cmd[0] = os.path.join(hy_dir, cmd[0])
p = subprocess.Popen(cmd,
stdin=subprocess.PIPE, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, stderr=subprocess.PIPE,
universal_newlines=True, universal_newlines=True,
shell=True, shell=False,
env=env) env=env)
if stdin_data is not None: if stdin_data is not None:
p.stdin.write(stdin_data) p.stdin.write(stdin_data)
@ -223,18 +229,22 @@ def test_hy2py():
if f == "py35_only_tests.hy" and not PY35: if f == "py35_only_tests.hy" and not PY35:
continue continue
i += 1 i += 1
output, err = run_cmd("hy2py -s -a " + output, err = run_cmd("hy2py -s -a " + quote(os.path.join(dirpath, f)))
os.path.join(dirpath, f))
assert len(output) > 1, f assert len(output) > 1, f
assert len(err) == 0, f assert len(err) == 0, f
assert i assert i
def test_bin_hy_builtins(): def test_bin_hy_builtins():
# hy.cmdline replaces builtins.exit and builtins.quit
# for use by hy's repl.
import hy.cmdline # NOQA import hy.cmdline # NOQA
# this test will fail if run from IPython because IPython deletes
assert str(exit) == "Use (exit) or Ctrl-D (i.e. EOF) to exit" # builtins.exit and builtins.quit
assert str(quit) == "Use (quit) or Ctrl-D (i.e. EOF) to exit" assert str(builtins.exit) == "Use (exit) or Ctrl-D (i.e. EOF) to exit"
assert type(builtins.exit) is hy.cmdline.HyQuitter
assert str(builtins.quit) == "Use (quit) or Ctrl-D (i.e. EOF) to exit"
assert type(builtins.quit) is hy.cmdline.HyQuitter
def test_bin_hy_main(): def test_bin_hy_main():