1+ import contextlib
12from io import StringIO
23from types import SimpleNamespace
34
4- from linodecli import help_pages
5+ import pytest
6+
7+ from linodecli import CLI , help_pages
8+ from linodecli .baked import OpenAPIOperation
59from tests .unit .conftest import assert_contains_ordered_substrings
610
711
@@ -100,7 +104,7 @@ def test_help_with_ops(self, capsys, mocked_config):
100104
101105 def test_help_with_ops_with_plugins (self , capsys , mocker , mocked_config ):
102106 mocker .patch (
103- "linodecli.arg_helpers .plugins.available" ,
107+ "linodecli.help_pages .plugins.available" ,
104108 return_value = ["testing.plugin" ],
105109 )
106110 help_pages .print_help_plugins (mocked_config )
@@ -120,10 +124,28 @@ def test_help_topics(self, capsys):
120124 assert topic in captured .out
121125
122126 # arg_helpers.print_help_action(cli, command, action)
123- def test_action_help_value_error (self , capsys , mock_cli ):
124- help_pages .print_help_action (mock_cli , None , None )
125- captured = capsys .readouterr ()
126- assert not captured .out
127+ def test_action_help_value_error (
128+ self , capsys , mock_cli : CLI , create_operation : OpenAPIOperation
129+ ):
130+ mock_cli .ops = {
131+ "foo" : {
132+ "bar" : create_operation ,
133+ }
134+ }
135+
136+ stderr_buf = StringIO ()
137+
138+ with pytest .raises (SystemExit ), contextlib .redirect_stderr (stderr_buf ):
139+ help_pages .print_help_action (mock_cli , "fake" , "fake" )
140+
141+ assert "Command not found: fake" in stderr_buf .getvalue ()
142+
143+ stderr_buf = StringIO ()
144+
145+ with pytest .raises (SystemExit ), contextlib .redirect_stderr (stderr_buf ):
146+ help_pages .print_help_action (mock_cli , "foo" , "fake" )
147+
148+ assert "Action not found for command foo: fake" in stderr_buf .getvalue ()
127149
128150 def test_action_help_post_method (self , capsys , mocker , mock_cli ):
129151 mocked_ops = mocker .MagicMock ()
0 commit comments