From f2511ae6064e9d369a2e16c9271f2cab6820aabd Mon Sep 17 00:00:00 2001 From: antazoey Date: Fri, 17 Nov 2023 04:39:20 -0600 Subject: [PATCH] fix: empty plugins sections repr (#1738) --- src/ape_plugins/utils.py | 3 +++ tests/functional/test_plugins.py | 13 +++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/ape_plugins/utils.py b/src/ape_plugins/utils.py index 9f19d64094..00dba29df0 100644 --- a/src/ape_plugins/utils.py +++ b/src/ape_plugins/utils.py @@ -441,6 +441,9 @@ def __str__(self) -> str: if PluginType.AVAILABLE in self.include and self.metadata.available: sections.append(self.metadata.available) + if not sections: + return "" + # Use a single max length for all the sections. max_length = max(x.max_name_length for x in sections) diff --git a/tests/functional/test_plugins.py b/tests/functional/test_plugins.py index 37f163b630..c6e551e1ea 100644 --- a/tests/functional/test_plugins.py +++ b/tests/functional/test_plugins.py @@ -115,8 +115,8 @@ def test_is_available(self): class TestApePluginsRepr: def test_str(self, plugin_metadata): - plugin_map = ApePluginsRepr(plugin_metadata) - actual = str(plugin_map) + representation = ApePluginsRepr(plugin_metadata) + actual = str(representation) expected = f""" Installed Plugins installed {VERSION} @@ -127,8 +127,8 @@ def test_str(self, plugin_metadata): assert actual == expected.strip() def test_str_all_types(self, plugin_metadata): - plugin_map = ApePluginsRepr(plugin_metadata, include=list(PluginType)) - actual = str(plugin_map) + representation = ApePluginsRepr(plugin_metadata, include=list(PluginType)) + actual = str(representation) expected = f""" Core Plugins run @@ -143,3 +143,8 @@ def test_str_all_types(self, plugin_metadata): available """ assert actual == expected.strip() + + def test_str_no_plugins(self): + plugins = PluginMetadataList.from_package_names([]) + representation = ApePluginsRepr(plugins) + assert str(representation) == ""