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]
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"
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"
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"
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]
def test_configured_callbacks(mocker, empty_config, widget_a, widget_b): module = SampleModule(config=empty_config, widgets=[widget_a, widget_b]) cmd = "sample-tool arg1 arg2 arg3" module.set("left-click", cmd) module.register_callbacks() cli = mocker.patch("core.input.util.cli") cli.execute.return_value = "" core.input.trigger({ "button": core.input.LEFT_MOUSE, "instance": module.id, }) cli.execute.assert_called_once_with(cmd, wait=False, shell=True)
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 module = TestModule() module.set("scrolling.width", 10) return module
def test_configured_callbacks(self): cfg = core.config.Config([]) module = TestModule(config=cfg, widgets=[self.someWidget, self.anotherWidget]) cmd = "sample-tool arg1 arg2 arg3" module.set("left-click", cmd) module.register_callbacks() with unittest.mock.patch("core.input.util.cli") as cli: cli.execute.return_value = "" core.input.trigger( {"button": core.input.LEFT_MOUSE, "instance": module.id,} ) cli.execute.assert_called_once_with(cmd, wait=False, shell=True)
def test_multiple_widget_themes(): widget1 = core.widget.Widget(full_text="a") widget2 = core.widget.Widget(full_text="b") widget3 = core.widget.Widget(full_text="c") module = SampleModule(widgets=[widget1, widget2, widget3]) module.set("theme.test", "1,2,3") module.set("theme.test2", "x") assert widget1.theme("test") == "1" assert widget2.theme("test") == "2" assert widget3.theme("test") == "3" assert widget1.theme("test2") == "x" assert widget2.theme("test2") == None assert widget3.theme("test2") == None
def test_multiple_widget_themes(self): widget1 = core.widget.Widget(full_text="a") widget2 = core.widget.Widget(full_text="b") widget3 = core.widget.Widget(full_text="c") module = TestModule(widgets=[widget1, widget2, widget3]) module.set("theme.test", "1,2,3") module.set("theme.test2", "x") self.assertEqual("1", widget1.theme("test")) self.assertEqual("2", widget2.theme("test")) self.assertEqual("3", widget3.theme("test")) self.assertEqual("x", widget1.theme("test2")) self.assertEqual(None, widget2.theme("test2")) self.assertEqual(None, widget3.theme("test2"))
def test_configured_callbacks_with_parameters(mocker, empty_config, widget_a): module = SampleModule(config=empty_config, widgets=[widget_a]) cmd = "sample-tool {instance} {name}" module.set("left-click", cmd) module.register_callbacks() cli = mocker.patch("core.input.util.cli") cli.execute.return_value = "" core.input.trigger({ "button": core.input.LEFT_MOUSE, "instance": module.id, "name": "sample-name", }) cli.execute.assert_called_once_with( cmd.format(instance=module.id, name="sample-name"), wait=False, shell=True, )
def test_configured_callbacks_with_parameters(self): cfg = core.config.Config([]) module = TestModule(config=cfg, widgets=[self.someWidget]) cmd = "sample-tool {instance} {name}" module.set("left-click", cmd) module.register_callbacks() with unittest.mock.patch("core.input.util.cli") as cli: cli.execute.return_value = "" core.input.trigger( { "button": core.input.LEFT_MOUSE, "instance": module.id, "name": "sample-name", } ) cli.execute.assert_called_once_with( cmd.format(instance=module.id, name="sample-name"), wait=False, shell=True, )