[tests] Add (partial) decorator tests

This commit is contained in:
Tobias Witek 2020-02-24 14:20:54 +01:00
parent 0a266b607e
commit 37e1deaa6f
2 changed files with 40 additions and 1 deletions

View file

@ -17,7 +17,7 @@ def scrollable(func):
direction = widget.get('scrolling.direction', 'right') direction = widget.get('scrolling.direction', 'right')
start += scroll_speed if direction == 'right' else -(scroll_speed) 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: if bounce:
widget.set('scrolling.direction', 'left') widget.set('scrolling.direction', 'left')
else: else:

View file

@ -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