diff --git a/tests/importer/test_importer.py b/tests/importer/test_importer.py index f10c2a6..bb92bce 100644 --- a/tests/importer/test_importer.py +++ b/tests/importer/test_importer.py @@ -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) diff --git a/tests/resources/importer/foo/__init__.hy b/tests/resources/importer/foo/__init__.hy new file mode 100644 index 0000000..5909d57 --- /dev/null +++ b/tests/resources/importer/foo/__init__.hy @@ -0,0 +1,2 @@ +(print "This is __init__.hy") +(setv ext "hy") diff --git a/tests/resources/importer/foo/__init__.py b/tests/resources/importer/foo/__init__.py new file mode 100644 index 0000000..5ea3615 --- /dev/null +++ b/tests/resources/importer/foo/__init__.py @@ -0,0 +1,2 @@ +print('This is __init__.py') +ext = 'py' diff --git a/tests/resources/importer/foo/some_mod.hy b/tests/resources/importer/foo/some_mod.hy new file mode 100644 index 0000000..10db45c --- /dev/null +++ b/tests/resources/importer/foo/some_mod.hy @@ -0,0 +1,2 @@ +(print "This is test_mod.hy") +(setv ext "hy") diff --git a/tests/resources/importer/foo/some_mod.py b/tests/resources/importer/foo/some_mod.py new file mode 100644 index 0000000..d9533b2 --- /dev/null +++ b/tests/resources/importer/foo/some_mod.py @@ -0,0 +1,2 @@ +print('This is test_mod.py') +ext = 'py'