From 37e1deaa6f94abed296e4697e14903fca07809dc Mon Sep 17 00:00:00 2001 From: Tobias Witek Date: Mon, 24 Feb 2020 14:20:54 +0100 Subject: [PATCH] [tests] Add (partial) decorator tests --- core/decorators.py | 2 +- tests/core/test_decorators.py | 39 +++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 tests/core/test_decorators.py diff --git a/core/decorators.py b/core/decorators.py index 91727f9..9480de1 100644 --- a/core/decorators.py +++ b/core/decorators.py @@ -17,7 +17,7 @@ def scrollable(func): direction = widget.get('scrolling.direction', 'right') start += scroll_speed if direction == 'right' else -(scroll_speed) - if width + start > len(text) + (scroll_speed -1): + if width + start > len(text) + (scroll_speed - 1): if bounce: widget.set('scrolling.direction', 'left') else: diff --git a/tests/core/test_decorators.py b/tests/core/test_decorators.py new file mode 100644 index 0000000..37c9759 --- /dev/null +++ b/tests/core/test_decorators.py @@ -0,0 +1,39 @@ +import unittest + +import core.decorators +import core.widget +import core.module +import core.config + +class TestModule(core.module.Module): + def __init__(self, config=None): + config = core.config.Config([]) + super().__init__(config, core.widget.Widget(self.get)) + self.text = '' + + @core.decorators.scrollable + def get(self, widget): + return self.text + +class config(unittest.TestCase): + def setUp(self): + self.module = TestModule() + self.widget = self.module.widgets()[0] + self.width = 10 + self.module.set('width', self.width) + + def test_no_text(self): + self.assertEqual('', self.module.text) + self.assertEqual('', self.module.get(self.widget)) + + def test_smaller(self): + self.module.text = 'test' + self.assertLess(len(self.module.text), self.width) + self.assertEqual('test', self.module.get(self.widget)) + + def test_bigger(self): + self.module.text = 'abcdefghijklmnopqrst' + self.assertGreater(len(self.module.text), self.width) + self.assertEqual(self.module.text[:self.width], self.module.get(self.widget)) + +# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4