diff --git a/src/specify_cli/extensions/command_info.py b/src/specify_cli/extensions/command_info.py index cf7796a653..74dd1c7e35 100644 --- a/src/specify_cli/extensions/command_info.py +++ b/src/specify_cli/extensions/command_info.py @@ -240,7 +240,8 @@ def _print_extension_info(ext_info: dict, manager): # Same untrusted-value/Rich-markup hazard as `downloads` above, in the # same joined string. stats.append(f"Stars: {_escape_markup(str(stars))}") - if stats: + # Community catalog zeroes are placeholders, not measured usage. + if stats and not (downloads == 0 and stars == 0): _commands.console.print(f"[bold]Statistics:[/bold] {' | '.join(stats)}") _commands.console.print() diff --git a/src/specify_cli/extensions/command_search.py b/src/specify_cli/extensions/command_search.py index 8a0deca520..0f0cb9e1b3 100644 --- a/src/specify_cli/extensions/command_search.py +++ b/src/specify_cli/extensions/command_search.py @@ -84,7 +84,8 @@ def extension_search( # Same untrusted-value/Rich-markup hazard as `downloads` above, # in the same joined string. stats.append(f"Stars: {_escape_markup(str(stars))}") - if stats: + # Community catalog zeroes are placeholders, not measured usage. + if stats and not (downloads == 0 and stars == 0): console.print(f" [dim]{' | '.join(stats)}[/dim]") # Links diff --git a/tests/specify_cli/extensions/test_command_info.py b/tests/specify_cli/extensions/test_command_info.py index 5c32f3ad53..26e488b57e 100644 --- a/tests/specify_cli/extensions/test_command_info.py +++ b/tests/specify_cli/extensions/test_command_info.py @@ -27,6 +27,27 @@ class TestExtensionInfoRendering: """Rendering tests for ``specify extension info``.""" + @pytest.mark.parametrize( + ("downloads", "stars", "expected"), + [(0, 0, False), (12, 3, True)], + ) + def test_info_omits_unmeasured_statistics( + self, capsys, downloads, stars, expected + ): + from specify_cli.extensions._commands import _print_extension_info + + manager = MagicMock() + manager.registry.is_installed.return_value = False + ext_info = { + "id": "example", "name": "Example", "version": "1.0.0", + "description": "Example extension", "_catalog_name": "community", + "downloads": downloads, "stars": stars, + } + _print_extension_info(ext_info, manager) + output = capsys.readouterr().out + assert ("Statistics:" in output) is expected + assert ("Downloads:" in output) is expected + @pytest.mark.parametrize( "downloads", [ diff --git a/tests/specify_cli/extensions/test_command_search.py b/tests/specify_cli/extensions/test_command_search.py index 2dd6326203..5cdf3afb41 100644 --- a/tests/specify_cli/extensions/test_command_search.py +++ b/tests/specify_cli/extensions/test_command_search.py @@ -22,6 +22,27 @@ class TestExtensionSearchCLI: """CLI tests for ``specify extension search``.""" + @pytest.mark.parametrize( + ("downloads", "stars", "expected"), + [(0, 0, False), (12, 3, True)], + ) + def test_search_omits_unmeasured_statistics( + self, project_dir, downloads, stars, expected + ): + entry = { + "id": "example", "name": "Example", "version": "1.0.0", + "description": "Example extension", "_catalog_name": "community", + "downloads": downloads, "stars": stars, + } + with patch.object(ExtensionCatalog, "_get_merged_extensions", return_value=[entry]), \ + patch("specify_cli.extensions._commands._require_specify_project", + return_value=project_dir): + result = CliRunner().invoke(app, ["extension", "search", "Example"]) + + assert result.exit_code == 0, result.output + assert ("Downloads:" in result.output) is expected + assert ("Stars:" in result.output) is expected + def test_search_shows_incomplete_catalog_entry(self, incomplete_catalog_entry): result = CliRunner().invoke(app, ["extension", "search"])