commit
51fb807cc9
@ -1,10 +1,13 @@
|
|||||||
import _pytest
|
import _pytest
|
||||||
import hy
|
import hy
|
||||||
|
import os
|
||||||
from hy._compat import PY3, PY35
|
from hy._compat import PY3, PY35
|
||||||
|
|
||||||
|
NATIVE_TESTS = os.path.join("", "tests", "native_tests", "")
|
||||||
|
|
||||||
def pytest_collect_file(parent, path):
|
def pytest_collect_file(parent, path):
|
||||||
if (path.ext == ".hy"
|
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 path.basename != "__init__.hy"
|
||||||
and not ("py3_only" in path.basename and not PY3)
|
and not ("py3_only" in path.basename and not PY3)
|
||||||
and not ("py35_only" in path.basename and not PY35)):
|
and not ("py35_only" in path.basename and not PY35)):
|
||||||
|
@ -98,7 +98,7 @@ def import_file_to_module(module_name, fpath, loader=None):
|
|||||||
try:
|
try:
|
||||||
_ast = import_file_to_ast(fpath, module_name)
|
_ast = import_file_to_ast(fpath, module_name)
|
||||||
module = imp.new_module(module_name)
|
module = imp.new_module(module_name)
|
||||||
module.__file__ = fpath
|
module.__file__ = os.path.normpath(fpath)
|
||||||
code = ast_compile(_ast, fpath, "exec")
|
code = ast_compile(_ast, fpath, "exec")
|
||||||
if not os.environ.get('PYTHONDONTWRITEBYTECODE'):
|
if not os.environ.get('PYTHONDONTWRITEBYTECODE'):
|
||||||
try:
|
try:
|
||||||
@ -121,7 +121,7 @@ def import_file_to_module(module_name, fpath, loader=None):
|
|||||||
sys.modules[module_name] = module
|
sys.modules[module_name] = module
|
||||||
module.__name__ = module_name
|
module.__name__ = module_name
|
||||||
|
|
||||||
module.__file__ = fpath
|
module.__file__ = os.path.normpath(fpath)
|
||||||
if loader:
|
if loader:
|
||||||
module.__loader__ = loader
|
module.__loader__ = loader
|
||||||
if is_package(module_name):
|
if is_package(module_name):
|
||||||
|
@ -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():
|
||||||
|
Loading…
Reference in New Issue
Block a user