2020-02-24 14:20:54 +01:00
|
|
|
import unittest
|
|
|
|
|
|
|
|
import core.decorators
|
|
|
|
import core.widget
|
|
|
|
import core.module
|
|
|
|
import core.config
|
|
|
|
|
2020-05-03 11:15:52 +02:00
|
|
|
|
2020-02-24 14:20:54 +01:00
|
|
|
class TestModule(core.module.Module):
|
2020-04-26 16:39:13 +02:00
|
|
|
def __init__(self, config=None, theme=None):
|
2020-02-24 14:20:54 +01:00
|
|
|
config = core.config.Config([])
|
2020-04-26 16:39:13 +02:00
|
|
|
super().__init__(config, theme, core.widget.Widget(self.get))
|
2020-05-03 11:15:52 +02:00
|
|
|
self.text = ""
|
2020-02-24 14:20:54 +01:00
|
|
|
|
|
|
|
@core.decorators.scrollable
|
|
|
|
def get(self, widget):
|
|
|
|
return self.text
|
|
|
|
|
2020-05-03 11:15:52 +02:00
|
|
|
|
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):
|
2020-05-03 11:15:52 +02:00
|
|
|
self.assertEqual("", self.module.text)
|
|
|
|
self.assertEqual("", self.module.get(self.widget))
|
2020-02-24 14:20:54 +01:00
|
|
|
|
|
|
|
def test_smaller(self):
|
2020-05-03 11:15:52 +02:00
|
|
|
self.module.text = "test"
|
2020-02-24 14:20:54 +01:00
|
|
|
self.assertLess(len(self.module.text), self.width)
|
2020-05-03 11:15:52 +02:00
|
|
|
self.assertEqual("test", self.module.get(self.widget))
|
2020-02-24 14:20:54 +01:00
|
|
|
|
|
|
|
def test_bigger(self):
|
2020-05-03 11:15:52 +02:00
|
|
|
self.module.text = "abcdefghijklmnopqrst"
|
2020-02-24 14:20:54 +01:00
|
|
|
self.assertGreater(len(self.module.text), self.width)
|
2020-05-03 11:15:52 +02:00
|
|
|
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):
|
2020-05-03 11:15:52 +02:00
|
|
|
self.module.text = "abcd"
|
2020-05-09 15:31:25 +02:00
|
|
|
self.module.set("scrolling.width", 2)
|
2020-05-03 11:15:52 +02:00
|
|
|
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):
|
2020-05-03 11:15:52 +02:00
|
|
|
self.module.set("scrolling.bounce", False)
|
|
|
|
self.module.text = "abcd"
|
2020-05-09 15:31:25 +02:00
|
|
|
self.module.set("scrolling.width", 2)
|
2020-05-03 11:15:52 +02:00
|
|
|
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))
|
|
|
|
|
2020-05-04 20:11:10 +02:00
|
|
|
def test_changed_data(self):
|
|
|
|
self.module.text = "abcd"
|
2020-05-09 15:31:25 +02:00
|
|
|
self.module.set("scrolling.width", 2)
|
2020-05-04 20:11:10 +02:00
|
|
|
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-05-14 20:35:09 +02:00
|
|
|
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))
|
|
|
|
|
2020-05-15 20:31:00 +02:00
|
|
|
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
|