bumblebee-status/tests/core/test_decorators.py

115 lines
3.4 KiB
Python
Raw Permalink Normal View History

2020-06-20 14:53:44 +02:00
import pytest
2020-02-24 14:20:54 +01:00
import core.decorators
import core.widget
import core.module
import core.config
2020-06-20 15:11:53 +02:00
2020-06-20 14:53:44 +02:00
@pytest.fixture
def module():
class TestModule(core.module.Module):
@core.decorators.never
def __init__(self, config=None, theme=None):
config = core.config.Config([])
super().__init__(config, theme, core.widget.Widget(self.get))
self.text = ""
@core.decorators.scrollable
def get(self, widget):
return self.text
2020-06-20 15:11:53 +02:00
2020-06-20 14:53:44 +02:00
module = TestModule()
module.set("scrolling.width", 10)
return module
2020-06-20 15:11:53 +02:00
2020-06-20 14:53:44 +02:00
def test_never(module):
assert module.parameter("interval") == "never"
2020-06-20 15:11:53 +02:00
2020-06-20 14:53:44 +02:00
def test_no_text(module):
assert module.text == ""
assert module.get(module.widget()) == ""
2020-06-20 15:11:53 +02:00
2020-06-20 14:53:44 +02:00
def test_smaller(module):
module.text = "test"
assert module.parameter("scrolling.width") > len(module.text)
assert module.get(module.widget()) == module.text
2020-06-20 15:11:53 +02:00
2020-06-20 14:53:44 +02:00
def test_bigger(module):
module.text = "this is a really really long sample text"
maxwidth = module.parameter("scrolling.width")
assert maxwidth < len(module.text)
assert module.get(module.widget()) == module.text[:maxwidth]
2020-06-20 15:11:53 +02:00
2020-06-20 14:53:44 +02:00
def test_bounce(module):
module.text = "abcd"
module.set("scrolling.width", 2)
assert module.get(module.widget()) == "ab"
assert module.get(module.widget()) == "bc"
assert module.get(module.widget()) == "cd"
assert module.get(module.widget()) == "bc"
assert module.get(module.widget()) == "ab"
assert module.get(module.widget()) == "bc"
assert module.get(module.widget()) == "cd"
assert module.get(module.widget()) == "bc"
assert module.get(module.widget()) == "ab"
2020-06-20 15:11:53 +02:00
2020-06-20 14:53:44 +02:00
def test_nobounce(module):
module.set("scrolling.bounce", False)
module.set("scrolling.width", 2)
module.text = "abcd"
assert module.get(module.widget()) == "ab"
assert module.get(module.widget()) == "bc"
assert module.get(module.widget()) == "cd"
assert module.get(module.widget()) == "ab"
assert module.get(module.widget()) == "bc"
assert module.get(module.widget()) == "cd"
2020-06-20 15:11:53 +02:00
2020-06-20 14:53:44 +02:00
def test_completely_changed_data(module):
module.text = "abcd"
module.set("scrolling.width", 2)
assert module.get(module.widget()) == "ab"
assert module.get(module.widget()) == "bc"
module.text = "wxyz"
assert module.get(module.widget()) == "wx"
assert module.get(module.widget()) == "xy"
2020-06-20 15:11:53 +02:00
2020-06-20 14:53:44 +02:00
def test_slightly_changed_data(module):
module.text = "this is a sample song (0:00)"
module.set("scrolling.width", 10)
assert module.get(module.widget()) == module.text[0:10]
module.text = "this is a sample song (0:01)"
assert module.get(module.widget()) == module.text[1:11]
module.text = "this is a sample song (0:02)"
assert module.get(module.widget()) == module.text[2:12]
module.text = "this is a sample song (0:13)"
assert module.get(module.widget()) == module.text[3:13]
module.text = "this is a different song (0:13)"
assert module.get(module.widget()) == module.text[0:10]
2020-06-20 15:11:53 +02:00
2020-06-20 14:53:44 +02:00
def test_n_plus_one(module):
module.text = "10 letters"
module.set("scrolling.width", 9)
assert module.get(module.widget()) == module.text[0:9]
assert module.get(module.widget()) == module.text[1:10]
assert module.get(module.widget()) == module.text[0:9]
assert module.get(module.widget()) == module.text[1:10]
assert module.get(module.widget()) == module.text[0:9]
2020-02-27 21:39:04 +01:00
2020-02-24 14:20:54 +01:00
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4