diff --git a/sopel/plugins/handlers.py b/sopel/plugins/handlers.py index 91d18639c..5896ba838 100644 --- a/sopel/plugins/handlers.py +++ b/sopel/plugins/handlers.py @@ -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] diff --git a/test/plugins/test_plugins_handlers.py b/test/plugins/test_plugins_handlers.py index 34ccaadbe..ef77596e3 100644 --- a/test/plugins/test_plugins_handlers.py +++ b/test/plugins/test_plugins_handlers.py @@ -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() @@ -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)