2018-01-01 16:38:33 +01:00
|
|
|
# Copyright 2018 the authors.
|
2017-04-27 23:16:57 +02:00
|
|
|
# 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
|
2018-08-20 06:29:29 +02:00
|
|
|
|
|
|
|
import py_compile
|
2013-04-13 18:57:54 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_pyc():
|
|
|
|
"""Test pyc compilation."""
|
2018-08-20 06:29:29 +02:00
|
|
|
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
|
|
|
|
2018-08-20 06:29:29 +02:00
|
|
|
assert os.path.exists(cfile)
|
2013-04-13 18:57:54 +02:00
|
|
|
|
2018-08-20 06:29:29 +02:00
|
|
|
mod = imp.load_compiled('pyc', cfile)
|
|
|
|
os.remove(cfile)
|
2013-04-13 18:57:54 +02:00
|
|
|
|
2018-08-20 06:29:29 +02:00
|
|
|
assert mod.pyctest('Foo') == 'XFooY'
|