hy/tests/importer/test_pyc.py

28 lines
647 B
Python
Raw Normal View History

2019-02-07 14:57:35 +01:00
# Copyright 2019 the authors.
# This file is part of Hy, which is free software licensed under the Expat
# license. See the LICENSE.
2013-04-13 18:57:54 +02:00
import os
import importlib.util
import py_compile
2013-04-13 18:57:54 +02:00
import tempfile
import hy.importer
2013-04-13 18:57:54 +02:00
def test_pyc():
"""Test pyc compilation."""
with tempfile.NamedTemporaryFile(suffix='.hy') as f:
f.write(b'(defn pyctest [s] (+ "X" s "Y"))')
f.flush()
cfile = py_compile.compile(f.name)
assert os.path.exists(cfile)
2013-04-13 18:57:54 +02:00
try:
mod = hy.importer._import_from_path('pyc', cfile)
finally:
os.remove(cfile)
2013-04-13 18:57:54 +02:00
assert mod.pyctest('Foo') == 'XFooY'