From 50c21ca38c8ec41a083216a9cd368f498d47e065 Mon Sep 17 00:00:00 2001 From: gilch Date: Wed, 30 Aug 2017 15:37:12 -0600 Subject: [PATCH 1/2] 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. --- tests/test_bin.py | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/tests/test_bin.py b/tests/test_bin.py index 670b77a..ad2ea13 100644 --- a/tests/test_bin.py +++ b/tests/test_bin.py @@ -5,12 +5,16 @@ # license. See the LICENSE. import os -import subprocess +from pipes import quote import re -from hy._compat import PY3, PY35 -from hy.importer import get_bytecode_path +import shlex +import subprocess + import pytest +from hy._compat import PY3, PY35, builtins +from hy.importer import get_bytecode_path + hy_dir = os.environ.get('HY_DIR', '') @@ -24,12 +28,14 @@ def run_cmd(cmd, stdin_data=None, expect=0, dontwritebytecode=False): if dontwritebytecode: env = dict(os.environ) 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, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, - shell=True, + shell=False, env=env) if stdin_data is not None: p.stdin.write(stdin_data) @@ -223,18 +229,22 @@ def test_hy2py(): if f == "py35_only_tests.hy" and not PY35: continue i += 1 - output, err = run_cmd("hy2py -s -a " + - os.path.join(dirpath, f)) + output, err = run_cmd("hy2py -s -a " + quote(os.path.join(dirpath, f))) assert len(output) > 1, f assert len(err) == 0, f assert i def test_bin_hy_builtins(): + # hy.cmdline replaces builtins.exit and builtins.quit + # for use by hy's repl. import hy.cmdline # NOQA - - assert str(exit) == "Use (exit) or Ctrl-D (i.e. EOF) to exit" - assert str(quit) == "Use (quit) or Ctrl-D (i.e. EOF) to exit" + # this test will fail if run from IPython because IPython deletes + # builtins.exit and builtins.quit + 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(): From 20516cce7946041174e770e6678ddc3efe6d0f79 Mon Sep 17 00:00:00 2001 From: gilch Date: Wed, 30 Aug 2017 23:36:06 -0600 Subject: [PATCH 2/2] make native tests run on Windows too --- conftest.py | 5 ++++- hy/importer.py | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/conftest.py b/conftest.py index 0735cf7..7302742 100644 --- a/conftest.py +++ b/conftest.py @@ -1,10 +1,13 @@ import _pytest import hy +import os from hy._compat import PY3, PY35 +NATIVE_TESTS = os.path.join("", "tests", "native_tests", "") + def pytest_collect_file(parent, path): if (path.ext == ".hy" - and "/tests/native_tests/" in path.dirname + "/" + and NATIVE_TESTS in path.dirname + os.sep and path.basename != "__init__.hy" and not ("py3_only" in path.basename and not PY3) and not ("py35_only" in path.basename and not PY35)): diff --git a/hy/importer.py b/hy/importer.py index ae32164..bd1bc1f 100644 --- a/hy/importer.py +++ b/hy/importer.py @@ -98,7 +98,7 @@ def import_file_to_module(module_name, fpath, loader=None): try: _ast = import_file_to_ast(fpath, module_name) module = imp.new_module(module_name) - module.__file__ = fpath + module.__file__ = os.path.normpath(fpath) code = ast_compile(_ast, fpath, "exec") if not os.environ.get('PYTHONDONTWRITEBYTECODE'): try: @@ -121,7 +121,7 @@ def import_file_to_module(module_name, fpath, loader=None): sys.modules[module_name] = module module.__name__ = module_name - module.__file__ = fpath + module.__file__ = os.path.normpath(fpath) if loader: module.__loader__ = loader if is_package(module_name):