bumblebee-status/tests/core/test_decorators.py

75 lines
2.6 KiB
Python
Raw Normal View History

2020-02-24 14:20:54 +01:00
import unittest
import core.decorators
import core.widget
import core.module
import core.config
2020-02-24 14:20:54 +01:00
class TestModule(core.module.Module):
def __init__(self, config=None, theme=None):
2020-02-24 14:20:54 +01:00
config = core.config.Config([])
super().__init__(config, theme, core.widget.Widget(self.get))
self.text = ""
2020-02-24 14:20:54 +01:00
@core.decorators.scrollable
def get(self, widget):
return self.text
2020-02-24 14:20:54 +01:00
class config(unittest.TestCase):
def setUp(self):
self.module = TestModule()
2020-03-01 14:36:12 +01:00
self.widget = self.module.widget()
2020-02-24 14:20:54 +01:00
self.width = 10
self.module.set("width", self.width)
2020-02-24 14:20:54 +01:00
def test_no_text(self):
self.assertEqual("", self.module.text)
self.assertEqual("", self.module.get(self.widget))
2020-02-24 14:20:54 +01:00
def test_smaller(self):
self.module.text = "test"
2020-02-24 14:20:54 +01:00
self.assertLess(len(self.module.text), self.width)
self.assertEqual("test", self.module.get(self.widget))
2020-02-24 14:20:54 +01:00
def test_bigger(self):
self.module.text = "abcdefghijklmnopqrst"
2020-02-24 14:20:54 +01:00
self.assertGreater(len(self.module.text), self.width)
self.assertEqual(self.module.text[: self.width], self.module.get(self.widget))
2020-02-24 14:20:54 +01:00
2020-02-27 21:39:04 +01:00
def test_bounce(self):
self.module.text = "abcd"
self.module.set("width", 2)
self.assertEqual("ab", self.module.get(self.widget))
self.assertEqual("bc", self.module.get(self.widget))
self.assertEqual("cd", self.module.get(self.widget))
self.assertEqual("bc", self.module.get(self.widget))
self.assertEqual("ab", self.module.get(self.widget))
self.assertEqual("bc", self.module.get(self.widget))
self.assertEqual("cd", self.module.get(self.widget))
self.assertEqual("bc", self.module.get(self.widget))
self.assertEqual("ab", self.module.get(self.widget))
2020-02-27 21:39:04 +01:00
def test_nobounce(self):
self.module.set("scrolling.bounce", False)
self.module.text = "abcd"
self.module.set("width", 2)
self.assertEqual("ab", self.module.get(self.widget))
self.assertEqual("bc", self.module.get(self.widget))
self.assertEqual("cd", self.module.get(self.widget))
self.assertEqual("ab", self.module.get(self.widget))
self.assertEqual("bc", self.module.get(self.widget))
self.assertEqual("cd", self.module.get(self.widget))
def test_changed_data(self):
self.module.text = "abcd"
self.module.set("width", 2)
self.assertEqual("ab", self.module.get(self.widget))
self.assertEqual("bc", self.module.get(self.widget))
self.module.text = "wxyz"
self.assertEqual("wx", self.module.get(self.widget))
2020-02-27 21:39:04 +01:00
2020-02-24 14:20:54 +01:00
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4