Skip to content

Commit

Permalink
plugins.handlers: handle & test case when module __doc__ is None
Browse files Browse the repository at this point in the history
  • Loading branch information
SnoopJ authored and dgw committed Jun 21, 2023
1 parent f475524 commit 3b948e5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sopel/plugins/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def get_label(self):
if not self.is_loaded() or not hasattr(self.module, '__doc__'):
return default_label

module_doc = getattr(self.module, '__doc__', "")
module_doc = self.module.__doc__ or ""
lines = inspect.cleandoc(module_doc).splitlines()
return default_label if not lines else lines[0]

Expand Down
20 changes: 20 additions & 0 deletions test/plugins/test_plugins_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ def plugin_tmpfile(tmpdir):
return mod_file


@pytest.fixture
def plugin_tmpfile_nodoc(tmpdir):
root = tmpdir.mkdir('loader_mods')
mod_file = root.join('file_mod_nodoc.py')
mod_file.write("")

return mod_file


def test_get_label_pymodule():
plugin = handlers.PyModulePlugin('coretasks', 'sopel')
meta = plugin.get_meta_description()
Expand Down Expand Up @@ -62,6 +71,17 @@ def test_get_label_pyfile_loaded(plugin_tmpfile):
assert meta['source'] == plugin_tmpfile.strpath


def test_get_label_pyfile_loaded_nodoc(plugin_tmpfile_nodoc):
plugin = handlers.PyFilePlugin(plugin_tmpfile_nodoc.strpath)
plugin.load()
meta = plugin.get_meta_description()

assert meta['name'] == 'file_mod_nodoc'
assert meta['label'] == 'file_mod_nodoc plugin', 'Expecting default label'
assert meta['type'] == handlers.PyFilePlugin.PLUGIN_TYPE
assert meta['source'] == plugin_tmpfile_nodoc.strpath


def test_get_label_entrypoint(plugin_tmpfile):
# set up for manual load/import
distrib_dir = os.path.dirname(plugin_tmpfile.strpath)
Expand Down

0 comments on commit 3b948e5

Please sign in to comment.