Skip to content

Commit 2603bc1

Browse files
committed
replace the the pretty_print_table call with rich.table.Table in testcases
1 parent 3154052 commit 2603bc1

2 files changed

Lines changed: 15 additions & 11 deletions

File tree

cloudsmith_cli/core/download.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import click
99
import cloudsmith_api
1010
import requests
11+
from rich.console import Console
12+
from rich.table import Table
1113

1214
from . import keyring, ratelimits, utils
1315
from .api.exceptions import catch_raise_api_exception
@@ -295,9 +297,6 @@ def resolve_package(
295297

296298
def _display_multiple_packages(packages: List[Dict]) -> None:
297299
"""Display a table of multiple matching packages."""
298-
from rich.console import Console
299-
from rich.table import Table
300-
301300
click.echo("Multiple packages found:")
302301
click.echo()
303302

cloudsmith_cli/core/tests/test_download.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@ def test_resolve_package_multiple_matches_yes(
107107
mock_select_best.assert_called_once_with(mock_packages)
108108

109109
@patch("cloudsmith_cli.core.download.list_packages")
110-
@patch("cloudsmith_cli.cli.utils.pretty_print_table")
110+
@patch("cloudsmith_cli.core.download.Console")
111111
@patch("click.echo")
112112
def test_resolve_package_multiple_matches_no_yes(
113-
self, mock_echo, mock_pretty_print, mock_list_packages
113+
self, mock_echo, mock_console_cls, mock_list_packages
114114
):
115115
"""Test package resolution with multiple matches without --yes."""
116116
mock_packages = [
@@ -127,7 +127,7 @@ def test_resolve_package_multiple_matches_no_yes(
127127
download.resolve_package("owner", "repo", "test-package", yes=False)
128128

129129
self.assertEqual(cm.exception.exit_code, 3)
130-
mock_pretty_print.assert_called_once()
130+
mock_console_cls().print.assert_called_once()
131131

132132
@patch("cloudsmith_cli.core.download.list_packages")
133133
def test_resolve_package_with_filters(self, mock_list_packages):
@@ -677,9 +677,12 @@ def test_resolve_package_error_mentions_download_all(self, mock_list_packages):
677677
class TestDisplayMultiplePackages(unittest.TestCase):
678678
"""Test _display_multiple_packages function."""
679679

680-
@patch("cloudsmith_cli.cli.utils.pretty_print_table")
680+
@patch("cloudsmith_cli.core.download.Console")
681+
@patch("cloudsmith_cli.core.download.Table")
681682
@patch("click.echo")
682-
def test_display_includes_filename_column(self, mock_echo, mock_table):
683+
def test_display_includes_filename_column(
684+
self, mock_echo, mock_table_cls, mock_console_cls
685+
):
683686
"""Test that the multiple packages table includes filename."""
684687
packages = [
685688
{
@@ -694,9 +697,11 @@ def test_display_includes_filename_column(self, mock_echo, mock_table):
694697

695698
download._display_multiple_packages(packages)
696699

697-
mock_table.assert_called_once()
698-
headers = mock_table.call_args[0][0]
699-
self.assertIn("Filename", headers)
700+
# Verify that add_column was called with "Filename"
701+
column_names = [
702+
call.args[0] for call in mock_table_cls().add_column.call_args_list
703+
]
704+
self.assertIn("Filename", column_names)
700705

701706

702707
if __name__ == "__main__":

0 commit comments

Comments
 (0)