|
1 | 1 | """Tests for console module.""" |
| 2 | + |
2 | 3 | from unittest.mock import patch, MagicMock |
3 | 4 | import pytest |
4 | 5 |
|
|
8 | 9 | class TestConsole: |
9 | 10 | """Test Console class.""" |
10 | 11 |
|
11 | | - @patch('rich.console.Console.print') |
| 12 | + @patch("rich.console.Console.print") |
12 | 13 | def test_println(self, mock_print): |
13 | 14 | """Test printing message.""" |
14 | 15 | Console.println("Test message") |
15 | | - |
| 16 | + |
16 | 17 | mock_print.assert_called_once_with("Test message") |
17 | 18 |
|
18 | | - @patch('rich.console.Console.print') |
| 19 | + @patch("rich.console.Console.print") |
19 | 20 | def test_println_with_format(self, mock_print): |
20 | 21 | """Test printing formatted message.""" |
21 | 22 | Console.println("Test %s", "value") |
22 | | - |
| 23 | + |
23 | 24 | mock_print.assert_called_once_with("Test value") |
24 | 25 |
|
25 | 26 | def test_set_use_pretty_prompts(self): |
26 | 27 | """Test setting pretty prompts flag.""" |
27 | 28 | Console.set_use_pretty_prompts(False) |
28 | 29 | assert Console._use_pretty_prompts is False |
29 | | - |
| 30 | + |
30 | 31 | Console.set_use_pretty_prompts(True) |
31 | 32 | assert Console._use_pretty_prompts is True |
32 | 33 |
|
33 | | - @patch('questionary.text') |
| 34 | + @patch("questionary.text") |
34 | 35 | def test_prompt_input(self, mock_text): |
35 | 36 | """Test prompting for input.""" |
36 | 37 | mock_text.return_value.ask.return_value = "test value" |
37 | | - |
| 38 | + |
38 | 39 | result = Console.prompt_input("Enter value:") |
39 | | - |
| 40 | + |
40 | 41 | assert result == "test value" |
41 | 42 | mock_text.assert_called_once_with("Enter value:", default="") |
42 | 43 |
|
43 | | - @patch('questionary.text') |
| 44 | + @patch("questionary.text") |
44 | 45 | def test_prompt_input_with_default(self, mock_text): |
45 | 46 | """Test prompting for input with default.""" |
46 | 47 | mock_text.return_value.ask.return_value = None |
47 | | - |
| 48 | + |
48 | 49 | result = Console.prompt_input("Enter value:", default="default") |
49 | | - |
| 50 | + |
50 | 51 | assert result == "default" |
51 | 52 |
|
52 | | - @patch('questionary.confirm') |
| 53 | + @patch("questionary.confirm") |
53 | 54 | def test_prompt_confirm_yes(self, mock_confirm): |
54 | 55 | """Test prompting for confirmation (yes).""" |
55 | 56 | mock_confirm.return_value.ask.return_value = True |
56 | | - |
| 57 | + |
57 | 58 | result = Console.prompt_confirm("Continue?") |
58 | | - |
| 59 | + |
59 | 60 | assert result is True |
60 | 61 | mock_confirm.assert_called_once_with("Continue?", default=True) |
61 | 62 |
|
62 | | - @patch('questionary.confirm') |
| 63 | + @patch("questionary.confirm") |
63 | 64 | def test_prompt_confirm_no(self, mock_confirm): |
64 | 65 | """Test prompting for confirmation (no).""" |
65 | 66 | mock_confirm.return_value.ask.return_value = False |
66 | | - |
| 67 | + |
67 | 68 | result = Console.prompt_confirm("Continue?", default=False) |
68 | | - |
| 69 | + |
69 | 70 | assert result is False |
70 | 71 |
|
71 | | - @patch('questionary.confirm') |
| 72 | + @patch("questionary.confirm") |
72 | 73 | def test_prompt_confirm_none(self, mock_confirm): |
73 | 74 | """Test prompting for confirmation (None returned, use default).""" |
74 | 75 | mock_confirm.return_value.ask.return_value = None |
75 | | - |
| 76 | + |
76 | 77 | result = Console.prompt_confirm("Continue?", default=True) |
77 | | - |
| 78 | + |
78 | 79 | assert result is True |
79 | 80 |
|
80 | | - @patch('questionary.select') |
| 81 | + @patch("questionary.select") |
81 | 82 | def test_prompt_select(self, mock_select): |
82 | 83 | """Test prompting to select from list.""" |
83 | 84 | mock_select.return_value.ask.return_value = "Option 2" |
84 | | - |
| 85 | + |
85 | 86 | result = Console.prompt_select("Choose:", ["Option 1", "Option 2", "Option 3"]) |
86 | | - |
| 87 | + |
87 | 88 | assert result == "Option 2" |
88 | | - mock_select.assert_called_once_with("Choose:", choices=["Option 1", "Option 2", "Option 3"], default=None) |
| 89 | + mock_select.assert_called_once_with( |
| 90 | + "Choose:", choices=["Option 1", "Option 2", "Option 3"], default=None |
| 91 | + ) |
89 | 92 |
|
90 | | - @patch('questionary.select') |
| 93 | + @patch("questionary.select") |
91 | 94 | def test_prompt_select_with_default(self, mock_select): |
92 | 95 | """Test prompting to select from list with default.""" |
93 | 96 | mock_select.return_value.ask.return_value = "Option 1" |
94 | | - |
| 97 | + |
95 | 98 | result = Console.prompt_select("Choose:", ["Option 1", "Option 2"], default="Option 1") |
96 | | - |
| 99 | + |
97 | 100 | assert result == "Option 1" |
0 commit comments