Parametrize test_bin_hy_byte_compile

This commit is contained in:
Kodi Arfer 2017-06-20 15:30:13 -07:00
parent 672c8a1637
commit 399e7628b4

View File

@ -9,6 +9,7 @@ import subprocess
import re import re
from hy._compat import PY3 from hy._compat import PY3
from hy.importer import get_bytecode_path from hy.importer import get_bytecode_path
import pytest
hy_dir = os.environ.get('HY_DIR', '') hy_dir = os.environ.get('HY_DIR', '')
@ -240,39 +241,38 @@ def test_bin_hy_no_main():
assert "This Should Still Work" in output assert "This Should Still Work" in output
def test_bin_hy_byte_compile(): @pytest.mark.parametrize('can_byte_compile', [True, False])
@pytest.mark.parametrize('cmd_fmt', [
'hy {fpath}', 'hy -m {modname}', "hy -c '(import {modname})'"])
def test_bin_hy_byte_compile(can_byte_compile, cmd_fmt):
modname = "tests.resources.bin.bytecompile" modname = "tests.resources.bin.bytecompile"
fpath = modname.replace(".", "/") + ".hy" fpath = modname.replace(".", "/") + ".hy"
cmd = cmd_fmt.format(**locals())
for can_byte_compile in [True, False]: rm(get_bytecode_path(fpath))
for cmd in ["hy " + fpath,
"hy -m " + modname,
"hy -c '(import {})'".format(modname)]:
rm(get_bytecode_path(fpath)) if not can_byte_compile:
# Keep Hy from being able to byte-compile the module by
# creating a directory at the target location.
os.mkdir(get_bytecode_path(fpath))
if not can_byte_compile: # Whether or not we can byte-compile the module, we should be able
# Keep Hy from being able to byte-compile the module by # to run it.
# creating a directory at the target location. output, _ = run_cmd(cmd)
os.mkdir(get_bytecode_path(fpath)) assert "Hello from macro" in output
assert "The macro returned: boink" in output
# Whether or not we can byte-compile the module, we should be able if can_byte_compile:
# to run it. # That should've byte-compiled the module.
output, _ = run_cmd(cmd) assert os.path.exists(get_bytecode_path(fpath))
assert "Hello from macro" in output
assert "The macro returned: boink" in output
if can_byte_compile: # When we run the same command again, and we've byte-compiled the
# That should've byte-compiled the module. # module, the byte-compiled version should be run instead of the
assert os.path.exists(get_bytecode_path(fpath)) # source, in which case the macro shouldn't be run.
output, _ = run_cmd(cmd)
# When we run the same command again, and we've byte-compiled the assert ("Hello from macro" in output) ^ can_byte_compile
# module, the byte-compiled version should be run instead of the assert "The macro returned: boink" in output
# source, in which case the macro shouldn't be run.
output, _ = run_cmd(cmd)
assert ("Hello from macro" in output) ^ can_byte_compile
assert "The macro returned: boink" in output
def test_bin_hy_module_main(): def test_bin_hy_module_main():