From 1da29417fea8c618bfcba1f97de28e7f52a8d831 Mon Sep 17 00:00:00 2001 From: "Brandon T. Willard" Date: Wed, 22 Aug 2018 17:32:57 -0500 Subject: [PATCH] Add test for circular imports Closes hylang/hy#1134. --- tests/importer/test_importer.py | 12 ++++++++++++ tests/resources/importer/circular.hy | 5 +++++ 2 files changed, 17 insertions(+) create mode 100644 tests/resources/importer/circular.hy diff --git a/tests/importer/test_importer.py b/tests/importer/test_importer.py index 8b0e720..f10c2a6 100644 --- a/tests/importer/test_importer.py +++ b/tests/importer/test_importer.py @@ -15,6 +15,7 @@ from fractions import Fraction import pytest import hy +from hy._compat import bytes_type from hy.errors import HyTypeError from hy.lex import LexException from hy.compiler import hy_compile @@ -220,3 +221,14 @@ def test_reload(): del sys.path[0] unlink(source) del sys.modules[TESTFN] + + +def test_circular(): + """Test circular imports by creating a temporary file/module that calls a + function that imports itself.""" + sys.path.insert(0, os.path.abspath('tests/resources/importer')) + try: + mod = runpy.run_module('circular') + assert mod['f']() == 1 + finally: + sys.path.pop(0) diff --git a/tests/resources/importer/circular.hy b/tests/resources/importer/circular.hy new file mode 100644 index 0000000..4825b5f --- /dev/null +++ b/tests/resources/importer/circular.hy @@ -0,0 +1,5 @@ +(setv a 1) +(defn f [] + (import circular) + circular.a) +(print (f))