Skip to content

Commit

Permalink
Add a test for module docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonwillard committed Aug 27, 2018
1 parent 2ea1e8e commit 5d325a5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
11 changes: 5 additions & 6 deletions hy/importer.py
Expand Up @@ -256,8 +256,8 @@ def __init__(self, fullname, filename, fileobj=None, etc=None):

def exec_module(self, module, fullname=None):
fullname = self._fix_name(fullname)
ast = self.get_code(fullname)
eval(ast, module.__dict__)
code = self.get_code(fullname)
eval(code, module.__dict__)

def load_module(self, fullname=None):
"""Same as `pkgutil.ImpLoader`, with an extra check for Hy
Expand Down Expand Up @@ -287,7 +287,6 @@ def load_module(self, fullname=None):
mod.__file__ = self.get_filename(fullname)
mod.__package__ = '.'.join(fullname.split('.')[:-1])

# TODO: Set `mod.__doc__`.
mod.__name__ = fullname

self.exec_module(mod, fullname=fullname)
Expand All @@ -314,16 +313,16 @@ def _reopen(self):
else:
super(HyLoader, self)._reopen()


def byte_compile_hy(self, fullname=None):
fullname = self._fix_name(fullname)
if fullname is None:
fullname = self.fullname
try:
hy_source = self.get_source(fullname)
hy_tree = hy_parse(hy_source)
ast = hy_compile(hy_tree, fullname)
code = compile(ast, self.filename, 'exec',
hy_ast = hy_compile(hy_tree, fullname)

code = compile(hy_ast, self.filename, 'exec',
hy_ast_compile_flags)
except (HyTypeError, LexException) as e:
if e.source is None:
Expand Down
13 changes: 13 additions & 0 deletions tests/importer/test_importer.py
Expand Up @@ -253,3 +253,16 @@ def test_shadowed_basename():
assert some_mod.ext == 'hy'
finally:
sys.path.pop(0)


def test_docstring():
"""Make sure a module's docstring is loaded."""
sys.path.insert(0, os.path.realpath('tests/resources/importer'))
try:
mod = importlib.import_module('docstring')
expected_doc = ("This module has a docstring.\n\n"
"It covers multiple lines, too!\n")
assert mod.__doc__ == expected_doc
assert mod.a == 1
finally:
sys.path.pop(0)
5 changes: 5 additions & 0 deletions tests/resources/importer/docstring.hy
@@ -0,0 +1,5 @@
"This module has a docstring.
It covers multiple lines, too!
"
(setv a 1)

0 comments on commit 5d325a5

Please sign in to comment.