diff --git a/emmental/nowplaying/autopause.py b/emmental/nowplaying/autopause.py index ae76463..c65fd10 100644 --- a/emmental/nowplaying/autopause.py +++ b/emmental/nowplaying/autopause.py @@ -91,6 +91,16 @@ class Entry(Gtk.Entry): self.set_icon_sensitive(Gtk.EntryIconPosition.SECONDARY, self.value < 99) + def decrement(self) -> None: + """Decrease the autopause count by 1.""" + if self.value > -1: + self.value -= 1 + + def increment(self) -> None: + """Increase the autopause count by 1.""" + if self.value < 99: + self.value += 1 + class Button(buttons.PopoverButton): """A PopoverButton that displays Autopause count.""" @@ -116,3 +126,11 @@ class Button(buttons.PopoverButton): def __notify_value(self, button: buttons.PopoverButton, param) -> None: text = str(self.value) if self.value > -1 else "" self._count.set_markup(f"{text}") + + def decrement(self) -> None: + """Decrease the autopause value.""" + self.popover_child.decrement() + + def increment(self) -> None: + """Increase the autopause value.""" + self.popover_child.increment() diff --git a/tests/nowplaying/test_autopause.py b/tests/nowplaying/test_autopause.py index d3c4c0c..0bfee60 100644 --- a/tests/nowplaying/test_autopause.py +++ b/tests/nowplaying/test_autopause.py @@ -148,6 +148,26 @@ class TestAutopauseEntry(unittest.TestCase): self.entry.emit("activate") self.assertEqual(self.entry.value, value, f"text=\"{text}\"") + def test_decrement(self): + """Test the decrement() function.""" + self.entry.value = 1 + self.entry.decrement() + self.assertEqual(self.entry.value, 0) + self.entry.decrement() + self.assertEqual(self.entry.value, -1) + self.entry.decrement() + self.assertEqual(self.entry.value, -1) + + def test_increment(self): + """Test the increment() function.""" + self.entry.value = 97 + self.entry.increment() + self.assertEqual(self.entry.value, 98) + self.entry.increment() + self.assertEqual(self.entry.value, 99) + self.entry.increment() + self.assertEqual(self.entry.value, 99) + class TestAutopauseButton(unittest.TestCase): """Test our Autopause Popover Button.""" @@ -194,3 +214,17 @@ class TestAutopauseButton(unittest.TestCase): self.button.value = -1 self.assertEqual(self.button._count.get_text(), "") + + def test_decrement(self): + """Test the decrement() function.""" + with unittest.mock.patch.object(self.button.popover_child, + "decrement") as mock_decrement: + self.button.decrement() + mock_decrement.assert_called() + + def test_increment(self): + """Test the increment() functions.""" + with unittest.mock.patch.object(self.button.popover_child, + "increment") as mock_increment: + self.button.increment() + mock_increment.assert_called()