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
|
2017-04-10 02:27:51 +02:00
|
|
|
from hy.importer import write_hy_as_pyc, get_bytecode_path
|
2013-04-13 18:57:54 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_pyc():
|
|
|
|
"""Test pyc compilation."""
|
|
|
|
f = tempfile.NamedTemporaryFile(suffix='.hy', delete=False)
|
2017-04-10 02:27:51 +02:00
|
|
|
f.write(b'(defn pyctest [s] (+ "X" s "Y"))')
|
2013-04-13 18:57:54 +02:00
|
|
|
f.close()
|
|
|
|
|
|
|
|
write_hy_as_pyc(f.name)
|
2017-04-10 02:27:51 +02:00
|
|
|
os.remove(f.name)
|
2013-04-13 18:57:54 +02:00
|
|
|
|
2017-04-10 02:27:51 +02:00
|
|
|
cfile = get_bytecode_path(f.name)
|
2013-04-13 18:57:54 +02:00
|
|
|
mod = imp.load_compiled('pyc', cfile)
|
2017-04-10 02:27:51 +02:00
|
|
|
os.remove(cfile)
|
2013-04-13 18:57:54 +02:00
|
|
|
|
2017-04-10 02:27:51 +02:00
|
|
|
assert mod.pyctest('Foo') == 'XFooY'
|