2020-01-03 19:47:51 +01:00
|
|
|
# Copyright 2020 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
|
2019-07-08 02:28:12 +02:00
|
|
|
import importlib.util
|
|
|
|
import py_compile
|
2013-04-13 18:57:54 +02:00
|
|
|
import tempfile
|
2018-08-20 06:29:29 +02:00
|
|
|
|
2019-07-08 02:28:12 +02:00
|
|
|
import hy.importer
|
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)
|
|
|
|
assert os.path.exists(cfile)
|
2013-04-13 18:57:54 +02:00
|
|
|
|
2019-07-08 02:28:12 +02:00
|
|
|
try:
|
|
|
|
mod = hy.importer._import_from_path('pyc', cfile)
|
|
|
|
finally:
|
|
|
|
os.remove(cfile)
|
2013-04-13 18:57:54 +02:00
|
|
|
|
2018-08-20 06:29:29 +02:00
|
|
|
assert mod.pyctest('Foo') == 'XFooY'
|