Skip to content

Commit

Permalink
fix(lint): Pylint warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
dapc11 committed Dec 15, 2023
1 parent 9acb0a9 commit b50190d
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 40 deletions.
Empty file added __init__.py
Empty file.
14 changes: 7 additions & 7 deletions lib/ThemeController.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []

Expand All @@ -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
File renamed without changes.
64 changes: 31 additions & 33 deletions tests/lib/test_theme_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

0 comments on commit b50190d

Please sign in to comment.