2016-07-09 17:47:31 -07:00
|
|
|
from hy.importer import import_file_to_module, import_buffer_to_ast
|
2014-02-11 16:57:31 +01:00
|
|
|
from hy.errors import HyTypeError
|
2013-04-01 22:13:45 -04:00
|
|
|
import ast
|
2013-03-03 19:40:46 -05:00
|
|
|
|
|
|
|
|
|
|
|
def test_basics():
|
2013-03-05 22:15:45 -05:00
|
|
|
"Make sure the basics of the importer work"
|
2013-04-06 21:22:35 +02:00
|
|
|
import_file_to_module("basic",
|
|
|
|
"tests/resources/importer/basic.hy")
|
2013-04-01 22:13:45 -04:00
|
|
|
|
|
|
|
|
|
|
|
def test_stringer():
|
|
|
|
"Make sure the basics of the importer work"
|
2013-05-16 15:34:14 +02:00
|
|
|
_ast = import_buffer_to_ast("(defn square [x] (* x x))", '')
|
2013-04-01 22:13:45 -04:00
|
|
|
assert type(_ast.body[0]) == ast.FunctionDef
|
2013-07-06 20:35:26 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_imports():
|
|
|
|
def _import_test():
|
|
|
|
try:
|
2016-07-09 17:47:31 -07:00
|
|
|
import tests.resources.importer.a # NOQA
|
2013-07-06 20:35:26 +02:00
|
|
|
except:
|
|
|
|
return "Error"
|
|
|
|
|
|
|
|
assert _import_test() == "Error"
|
2013-07-06 20:39:02 +02:00
|
|
|
assert _import_test() is not None
|
2014-02-11 16:57:31 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_import_error_reporting():
|
|
|
|
"Make sure that (import) reports errors correctly."
|
|
|
|
|
|
|
|
def _import_error_test():
|
|
|
|
try:
|
|
|
|
import_buffer_to_ast("(import \"sys\")", '')
|
|
|
|
except HyTypeError:
|
|
|
|
return "Error reported"
|
|
|
|
|
|
|
|
assert _import_error_test() == "Error reported"
|
|
|
|
assert _import_error_test() is not None
|