Add test for shadowed-basename imports

This test ensures that Hy will load a `.hy` instead of a `.py` counterpart.
This commit is contained in:
Brandon T. Willard 2018-08-24 18:50:58 -05:00
parent 1da29417fe
commit bbc66d0042
5 changed files with 29 additions and 0 deletions

View File

@ -232,3 +232,24 @@ def test_circular():
assert mod['f']() == 1
finally:
sys.path.pop(0)
def test_shadowed_basename():
"""Make sure Hy loads `.hy` files instead of their `.py` counterparts (.e.g
`__init__.py` and `__init__.hy`).
"""
sys.path.insert(0, os.path.realpath('tests/resources/importer'))
try:
assert os.path.isfile('tests/resources/importer/foo/__init__.hy')
assert os.path.isfile('tests/resources/importer/foo/__init__.py')
assert os.path.isfile('tests/resources/importer/foo/some_mod.hy')
assert os.path.isfile('tests/resources/importer/foo/some_mod.py')
foo = importlib.import_module('foo')
assert foo.__file__.endswith('foo/__init__.hy')
assert foo.ext == 'hy'
some_mod = importlib.import_module('foo.some_mod')
assert some_mod.__file__.endswith('foo/some_mod.hy')
assert some_mod.ext == 'hy'
finally:
sys.path.pop(0)

View File

@ -0,0 +1,2 @@
(print "This is __init__.hy")
(setv ext "hy")

View File

@ -0,0 +1,2 @@
print('This is __init__.py')
ext = 'py'

View File

@ -0,0 +1,2 @@
(print "This is test_mod.hy")
(setv ext "hy")

View File

@ -0,0 +1,2 @@
print('This is test_mod.py')
ext = 'py'