hy/tests/importer/test_pyc.py

26 lines
568 B
Python
Raw Permalink 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 imp
import tempfile
import py_compile
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)
2013-04-13 18:57:54 +02:00
assert os.path.exists(cfile)
2013-04-13 18:57:54 +02:00
mod = imp.load_compiled('pyc', cfile)
os.remove(cfile)
2013-04-13 18:57:54 +02:00
assert mod.pyctest('Foo') == 'XFooY'