Skip to content

Commit f4718e0

Browse files
committed
fix menu config & test case
1 parent 228185e commit f4718e0

File tree

3 files changed

+25
-29
lines changed

3 files changed

+25
-29
lines changed

git_py_stats/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ def get_config() -> Dict[str, Union[str, int]]:
120120
menu_theme: Optional[str] = os.environ.get("_MENU_THEME")
121121
if menu_theme == "legacy":
122122
config["menu_theme"] = "legacy"
123+
elif menu_theme == "none":
124+
config["menu_theme"] = "none"
123125
else:
124126
config["menu_theme"] = ""
125127

git_py_stats/menu.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def interactive_menu(config: Dict[str, Union[str, int]]) -> str:
3939
NUMS = BOLD
4040
HELP_TXT = ""
4141
EXIT_TXT = BOLD
42-
NORMAL = ""
42+
NORMAL = ""
4343
else:
4444
TITLES = f"{BOLD}{CYAN}"
4545
TEXT = f"{NORMAL}{WHITE}"

git_py_stats/tests/test_menu.py

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def setUp(self):
2727
self.config_legacy = {"menu_theme": "legacy"} # Legacy theme
2828
self.config_none = {"menu_theme": "none"} # Alternate colorless theme alias
2929

30+
# Test cases for default theme
3031
@patch("builtins.input", return_value="1")
3132
@patch("sys.stdout", new_callable=StringIO)
3233
def test_default_theme_option_1(self, mock_stdout, mock_input):
@@ -77,23 +78,11 @@ def test_default_theme_invalid_input(self, mock_stdout, mock_input):
7778
output = strip_ansi_codes(mock_stdout.getvalue())
7879
self.assertIn("Generate:", output)
7980

80-
@patch("builtins.input", return_value="1")
81-
@patch("sys.stdout", new_callable=StringIO)
82-
def test_legacy_theme_option_1(self, mock_stdout, mock_input):
83-
"""
84-
Test the interactive_menu with legacy theme and user selects option '1'.
85-
"""
86-
choice = interactive_menu(self.config_legacy)
87-
self.assertEqual(choice, "1")
88-
output = strip_ansi_codes(mock_stdout.getvalue())
89-
self.assertIn("Generate:", output)
90-
self.assertIn("1) Contribution stats (by author)", output)
91-
9281
@patch("builtins.input", return_value="3")
9382
@patch("sys.stdout", new_callable=StringIO)
9483
def test_none_theme_option_3(self, mock_stdout, mock_input):
9584
"""
96-
Test the interactive_menu with 'none' theme (alias for colorless) and user selects option '3'.
85+
Test the interactive_menu with 'none' theme and user selects option '3'.
9786
"""
9887
choice = interactive_menu(self.config_none)
9988
self.assertEqual(choice, "3")
@@ -103,41 +92,43 @@ def test_none_theme_option_3(self, mock_stdout, mock_input):
10392
self.assertNotIn("\033[36m", output)
10493
self.assertIn("\033[1m", output)
10594

106-
@patch("builtins.input", return_value="22")
95+
@patch("builtins.input", return_value="1")
10796
@patch("sys.stdout", new_callable=StringIO)
108-
def test_default_theme_option_22(self, mock_stdout, mock_input):
97+
def test_none_theme_option_1(self, mock_stdout, mock_input):
10998
"""
110-
Test the interactive_menu with default theme and user selects option '22'.
99+
Test the interactive_menu with 'none' theme and user selects option '1'.
111100
"""
112-
choice = interactive_menu(self.config_default)
113-
self.assertEqual(choice, "22")
114-
output = strip_ansi_codes(mock_stdout.getvalue())
115-
self.assertIn("Suggest:", output)
116-
self.assertIn("22) Code reviewers (based on git history)", output)
101+
choice = interactive_menu(self.config_none)
102+
self.assertEqual(choice, "1")
103+
output = mock_stdout.getvalue()
104+
self.assertNotIn("\033[31m", output)
105+
self.assertNotIn("\033[33m", output)
106+
self.assertNotIn("\033[36m", output)
107+
self.assertIn("\033[1m", output)
117108

118109
@patch("builtins.input", return_value="")
119110
@patch("sys.stdout", new_callable=StringIO)
120-
def test_default_theme_exit(self, mock_stdout, mock_input):
111+
def test_none_theme_exit(self, mock_stdout, mock_input):
121112
"""
122-
Test the interactive_menu with default theme and user presses Enter to exit.
113+
Test the interactive_menu with none theme and user presses Enter to exit.
123114
"""
124-
choice = interactive_menu(self.config_default)
115+
choice = interactive_menu(self.config_none)
125116
self.assertEqual(choice, "")
126117
output = strip_ansi_codes(mock_stdout.getvalue())
127118
self.assertIn("press Enter to exit", output)
128119

129120
@patch("builtins.input", return_value="invalid")
130121
@patch("sys.stdout", new_callable=StringIO)
131-
def test_default_theme_invalid_input(self, mock_stdout, mock_input):
122+
def test_none_theme_invalid_input(self, mock_stdout, mock_input):
132123
"""
133-
Test the interactive_menu with default theme and user enters an invalid option.
124+
Test the interactive_menu with none theme and user enters an invalid option.
134125
"""
135-
choice = interactive_menu(self.config_default)
126+
choice = interactive_menu(self.config_none)
136127
self.assertEqual(choice, "invalid")
137-
# Since interactive_menu doesn't print 'Invalid selection', we don't assert that here.
138128
output = strip_ansi_codes(mock_stdout.getvalue())
139129
self.assertIn("Generate:", output)
140130

131+
# Test cases for legacy theme
141132
@patch("builtins.input", return_value="1")
142133
@patch("sys.stdout", new_callable=StringIO)
143134
def test_legacy_theme_option_1(self, mock_stdout, mock_input):
@@ -183,6 +174,7 @@ def test_legacy_theme_invalid_input(self, mock_stdout, mock_input):
183174
output = strip_ansi_codes(mock_stdout.getvalue())
184175
self.assertIn("Generate:", output)
185176

177+
# Test cases for handling multiple inputs and edge cases
186178
@patch("builtins.input", side_effect=["1", ""])
187179
@patch("sys.stdout", new_callable=StringIO)
188180
def test_multiple_inputs(self, mock_stdout, mock_input):
@@ -207,6 +199,7 @@ def test_input_with_whitespace(self, mock_stdout, mock_input):
207199
output = strip_ansi_codes(mock_stdout.getvalue())
208200
self.assertIn("5) My daily status", output)
209201

202+
# Test cases for handling exit commands
210203
@patch("builtins.input", return_value="QUIT")
211204
@patch("sys.stdout", new_callable=StringIO)
212205
def test_input_quit(self, mock_stdout, mock_input):
@@ -251,5 +244,6 @@ def test_keyboard_interrupt(self, mock_stdout, mock_input):
251244
output = strip_ansi_codes(mock_stdout.getvalue())
252245
self.assertIn("Generate:", output)
253246

247+
254248
if __name__ == "__main__":
255249
unittest.main()

0 commit comments

Comments
 (0)