bumblebee-status/tests/core/test_decorators.py

95 lines
3.8 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
2020-05-09 15:31:25 +02:00
self.module.set("scrolling.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"
2020-05-09 15:31:25 +02:00
self.module.set("scrolling.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"
2020-05-09 15:31:25 +02:00
self.module.set("scrolling.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"
2020-05-09 15:31:25 +02:00
self.module.set("scrolling.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))
def test_minimum_changed_data(self):
self.module.text = "this is a sample song (0:00)"
self.module.set("scrolling.width", 10)
self.assertEqual(self.module.text[0:10], self.module.get(self.widget))
self.module.text = "this is a sample song (0:01)"
self.assertEqual(self.module.text[1:11], self.module.get(self.widget))
self.module.text = "this is a sample song (0:12)"
self.assertEqual(self.module.text[2:12], self.module.get(self.widget))
self.module.text = "this is a different song (0:12)"
self.assertEqual(self.module.text[0:10], self.module.get(self.widget))
def test_n_plus_one(self):
self.module.text = "10 letters"
self.module.set("scrolling.width", 9)
self.assertEqual(self.module.text[0:9], self.module.get(self.widget))
self.assertEqual(self.module.text[1:10], self.module.get(self.widget))
self.assertEqual(self.module.text[0:9], self.module.get(self.widget))
self.assertEqual(self.module.text[1:10], self.module.get(self.widget))
self.assertEqual(self.module.text[0:9], 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