Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/specify_cli/extensions/command_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
3 changes: 2 additions & 1 deletion src/specify_cli/extensions/command_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions tests/specify_cli/extensions/test_command_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
[
Expand Down
21 changes: 21 additions & 0 deletions tests/specify_cli/extensions/test_command_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])

Expand Down
Loading