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-03 11:15:52 +02:00
|
|
|
self.module.set("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"
|
|
|
|
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):
|
2020-05-03 11:15:52 +02:00
|
|
|
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))
|
|
|
|
|
2020-02-27 21:39:04 +01:00
|
|
|
|
2020-02-24 14:20:54 +01:00
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|