Skip to content

Commit

Permalink
Add unit test for extension module with submodule
Browse files Browse the repository at this point in the history
For portability reasons, this unit test only simulates how an extension
model would look like. It doesn't actually package an extension module,
because then we'd have to provide a separte extension module for each
platform, os, and python version.
  • Loading branch information
robamler committed Mar 3, 2021
1 parent f379105 commit 33b7322
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions pdoc/test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,35 @@ def test_module(self):
self.assertEqual(sorted(m.name for m in m.submodules()),
[EXAMPLE_MODULE + '.' + m for m in submodules])

@ignore_warnings
def test_module_without_path(self):
# GH-319: https://github.com/pdoc3/pdoc/issues/319
parent_module = ModuleType('parent_module')
child_module1 = ModuleType('child_module1')
child_module2 = ModuleType('child_module2')
grandchild_module = ModuleType('grandchild_module')

child_module1.grandchild_module = grandchild_module
child_module1.__all__ = ['grandchild_module']

parent_module.child_module1 = child_module1
parent_module.child_module2 = child_module2
parent_module.__all__ = ['child_module1', 'child_module2']

assert not hasattr(parent_module, '__path__')
assert not hasattr(child_module1, '__path__')
assert not hasattr(child_module2, '__path__')
assert not hasattr(grandchild_module, '__path__')

parent_module_pdoc = pdoc.Module(parent_module)

children_modules_pdoc = sorted(parent_module_pdoc.submodules(), key=lambda m: m.name)
self.assertEqual(
[m.name for m in children_modules_pdoc], ['child_module1', 'child_module2'])
self.assertEqual(
[m.name for m in children_modules_pdoc[0].submodules()], ['grandchild_module'])
self.assertEqual(children_modules_pdoc[1].submodules(), [])

def test_Module_find_class(self):
class A:
pass
Expand Down

0 comments on commit 33b7322

Please sign in to comment.