From 67dbdd5fe275824976613d13da98b7d640f15126 Mon Sep 17 00:00:00 2001 From: Lena Garber Date: Thu, 17 Aug 2023 10:08:48 -0400 Subject: [PATCH] Fix existing unit tests --- tests/unit/test_output.py | 69 ++++++++++++++------------------------- 1 file changed, 25 insertions(+), 44 deletions(-) diff --git a/tests/unit/test_output.py b/tests/unit/test_output.py index 8f9be4a51..fad26ca94 100644 --- a/tests/unit/test_output.py +++ b/tests/unit/test_output.py @@ -1,4 +1,3 @@ -import contextlib import io from rich import box @@ -96,7 +95,9 @@ def test_table_output_columns(self, mock_cli): ) mock_table = io.StringIO() - tab = Table("h1", "h2", header_style="", box=box.SQUARE) + tab = Table( + "h1", "h2", header_style="", box=box.SQUARE, title_justify="left" + ) for row in [["foo", "bar"], ["oof", "rab"]]: tab.add_row(*row) tab.title = "cool table" @@ -124,7 +125,7 @@ def test_table_output_models( ) mock_table = io.StringIO() - tab = Table("h1", header_style="", box=box.SQUARE) + tab = Table("h1", header_style="", box=box.SQUARE, title_justify="left") for row in [["foo"], ["bar"]]: tab.add_row(*row) tab.title = "cool table" @@ -152,7 +153,12 @@ def test_table_output_models_no_headers( ) mock_table = io.StringIO() - tab = Table(header_style="", show_header=False, box=box.SQUARE) + tab = Table( + header_style="", + show_header=False, + box=box.SQUARE, + title_justify="left", + ) for row in [["foo"], ["bar"]]: tab.add_row(*row) tab.title = "cool table" @@ -181,8 +187,8 @@ def test_ascii_table_output( print(output.getvalue()) assert ( - output.getvalue() == " cool \n" - " table \n" + output.getvalue() == "cool \n" + "table \n" "+-----+\n" "| h1 |\n" "|-----|\n" @@ -196,9 +202,9 @@ def test_get_columns_from_model( ): output_handler = mock_cli.output_handler - response_model = list_operation_for_output_tests.response_model - - result = output_handler._get_columns(response_model) + result = output_handler._get_columns( + list_operation_for_output_tests.response_model.attrs + ) assert len(result) == 3 assert result[0].name == "cool" @@ -209,11 +215,12 @@ def test_get_columns_from_model_all( self, mock_cli, list_operation_for_output_tests ): output_handler = mock_cli.output_handler - response_model = list_operation_for_output_tests.response_model output_handler.columns = "*" - result = output_handler._get_columns(response_model) + result = output_handler._get_columns( + list_operation_for_output_tests.response_model.attrs + ) assert len(result) == 3 assert result[0].name == "cool" @@ -225,28 +232,27 @@ def test_get_columns_from_model_select( ): output_handler = mock_cli.output_handler - response_model = list_operation_for_output_tests.response_model - output_handler.columns = "cool,bar" - result = output_handler._get_columns(response_model) + result = output_handler._get_columns( + list_operation_for_output_tests.response_model.attrs + ) assert len(result) == 2 assert result[0].name == "cool" assert result[1].name == "bar" # Let's test a single print case - def test_print(self, mock_cli, list_operation_for_output_tests): + def test_print_response(self, mock_cli, list_operation_for_output_tests): output = io.StringIO() response_model = list_operation_for_output_tests.response_model mock_cli.output_handler.mode = OutputMode.json - mock_cli.output_handler.print( + mock_cli.output_handler.print_response( response_model, [{"cool": "blah", "bar": "blah2", "test": "blah3"}], - title="cool table", to=output, ) @@ -278,7 +284,7 @@ def test_truncated_table(self, mock_cli, list_operation_for_output_tests): data[0]["cool"] = test_str_truncated mock_table = io.StringIO() - tab = Table("h1", header_style="", box=box.SQUARE) + tab = Table("h1", header_style="", box=box.SQUARE, title_justify="left") tab.add_row(test_str_truncated) tab.title = "cool table" rprint(tab, file=mock_table) @@ -311,7 +317,7 @@ def test_nontruncated_table( data[0]["cool"] = test_str_truncated mock_table = io.StringIO() - tab = Table("h1", header_style="", box=box.SQUARE) + tab = Table("h1", header_style="", box=box.SQUARE, title_justify="left") tab.add_row(test_str_truncated) tab.title = "cool table" rprint(tab, file=mock_table) @@ -319,28 +325,3 @@ def test_nontruncated_table( print(output.getvalue()) assert output.getvalue() != mock_table.getvalue() - - def test_warn_broken_output(self, mock_cli): - stderr_buf = io.StringIO() - - try: - with contextlib.redirect_stderr(stderr_buf): - mock_cli.handle_command("linodes", "ips-list", ["10"]) - except SystemExit: - pass - - assert ( - "This output contains a nested structure that may not properly be displayed by linode-cli." - in stderr_buf.getvalue() - ) - - try: - with contextlib.redirect_stderr(stderr_buf): - mock_cli.handle_command("firewalls", "rules-list", ["10"]) - except SystemExit: - pass - - assert ( - "This output contains a nested structure that may not properly be displayed by linode-cli." - in stderr_buf.getvalue() - )