diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/lib/ThemeController.py b/lib/ThemeController.py index 8ad17a9..44bf20b 100644 --- a/lib/ThemeController.py +++ b/lib/ThemeController.py @@ -11,7 +11,7 @@ def __init__(self, args) -> None: self.theme = args.theme @staticmethod - def _get_themes(): + def get_themes(): """Visualize which themes that are available.""" theme_names = [] @@ -22,19 +22,19 @@ def _get_themes(): return theme_names - def _print_available_themes(self) -> None: + def print_available_themes(self) -> None: print("Specify theme with --theme (-t) flag.\nAvailable themes:") - for theme in self._get_themes(): + for theme in self.get_themes(): print(f" - {theme}") sys.exit(0) - def _validate_theme(self, themes) -> bool: + def validate_theme(self, themes) -> bool: return self.theme is not None and self.theme in themes def get_theme(self) -> str: """Get theme if valid, otherwise print list of available themes.""" - themes = self._get_themes() - if not self._validate_theme(themes) or self.list_themes: - self._print_available_themes() + themes = self.get_themes() + if not self.validate_theme(themes) or self.list_themes: + self.print_available_themes() return self.theme diff --git a/rice_it b/rice_it.py similarity index 100% rename from rice_it rename to rice_it.py diff --git a/tests/lib/test_theme_controller.py b/tests/lib/test_theme_controller.py index 661c4cf..95a57e3 100644 --- a/tests/lib/test_theme_controller.py +++ b/tests/lib/test_theme_controller.py @@ -7,70 +7,72 @@ class TestThemeController(unittest.TestCase): - def setUp(self): self.args = MagicMock() self.args.list = False self.args.theme = None - def test__get_themes(self): - with patch('glob.glob') as mock_glob: + def test_get_themes(self): + with patch("glob.glob") as mock_glob: mock_glob.return_value = [ - 'themes/catpuccin.json', - 'themes/doom-one.json', - 'themes/settings.json' + "themes/catpuccin.json", + "themes/doom-one.json", + "themes/settings.json", ] controller = ThemeController(self.args) - themes = controller._get_themes() - expected_themes = ['catpuccin', 'doom-one'] + themes = controller.get_themes() + expected_themes = ["catpuccin", "doom-one"] self.assertEqual(themes, expected_themes) - @patch('sys.exit') - def test__print_available_themes(self, mock_exit): + @patch("sys.exit") + def test_print_available_themes(self, mock_exit): controller = ThemeController(self.args) - controller._get_themes = MagicMock(return_value=['catpuccin', 'doom-one']) + controller.get_themes = MagicMock(return_value=["catpuccin", "doom-one"]) # Capture print output using StringIO output = io.StringIO() sys.stdout = output - controller._print_available_themes() + controller.print_available_themes() # Reset sys.stdout sys.stdout = sys.__stdout__ - expected_output = "Specify theme with --theme (-t) flag.\nAvailable themes:\n - catpuccin\n - doom-one\n" + expected_output = ( + "Specify theme with --theme (-t) flag.\n" + "Available themes:\n - catpuccin\n - doom-one\n" + ) self.assertEqual(output.getvalue(), expected_output) mock_exit.assert_called_with(0) - def test__validate_theme(self): + def test_validate_theme(self): controller = ThemeController(self.args) - controller.theme = 'catpuccin' - themes = ['catpuccin', 'doom-one'] - self.assertTrue(controller._validate_theme(themes)) + controller.theme = "catpuccin" + themes = ["catpuccin", "doom-one"] + self.assertTrue(controller.validate_theme(themes)) - @patch('builtins.print') - @patch('sys.exit') + @patch("builtins.print") + @patch("sys.exit") def test_get_theme_valid(self, mock_exit, mock_print): controller = ThemeController(self.args) - controller._validate_theme = MagicMock(return_value=True) - controller._get_themes = MagicMock(return_value=['catpuccin', 'doom-one']) + controller.validate_theme = MagicMock(return_value=True) + controller.get_themes = MagicMock(return_value=["catpuccin", "doom-one"]) theme = controller.get_theme() self.assertEqual(theme, None) mock_exit.assert_not_called() mock_print.assert_not_called() - @patch('builtins.print') - @patch('sys.exit') + @patch("builtins.print") + @patch("sys.exit") def test_get_theme_invalid(self, mock_exit, mock_print): controller = ThemeController(self.args) - controller._validate_theme = MagicMock(return_value=False) - controller._get_themes = MagicMock(return_value=['catpuccin', 'doom-one']) + controller.validate_theme = MagicMock(return_value=False) + controller.get_themes = MagicMock(return_value=["catpuccin", "doom-one"]) theme = controller.get_theme() expected_output = [ - call('Specify theme with --theme (-t) flag.\nAvailable themes:'), - call(' - catpuccin'), - call(' - doom-one') + call("Specify theme with --theme (-t) flag.\nAvailable themes:"), + call(" - catpuccin"), + call(" - doom-one"), ] mock_print.assert_has_calls(expected_output) mock_exit.assert_called_with(0) @@ -79,10 +81,6 @@ def test_get_theme_invalid(self, mock_exit, mock_print): def test_get_theme_list_themes(self): self.args.list = True controller = ThemeController(self.args) - controller._get_themes = MagicMock(return_value=['catpuccin', 'doom-one']) + controller.get_themes = MagicMock(return_value=["catpuccin", "doom-one"]) with self.assertRaises(SystemExit): controller.get_theme() - - -if __name__ == '__main__': - unittest.main