[tests] add more tests

This commit is contained in:
tobi-wan-kenobi 2020-05-16 11:55:25 +02:00
parent eea3c758de
commit 7584366adc
4 changed files with 28 additions and 3 deletions

View file

@ -14,6 +14,7 @@
- themes: use colors to improve theme readability
- convert some stuff to simple attributes to reduce LOCs
- use widget index for bumblebee-ctl as alternative (??)
- use pytest?
# documentation
Add info about error widget and events for error logging

View file

@ -52,8 +52,8 @@ class config(unittest.TestCase):
def test_logfile(self):
cfg = core.config.Config(["-f", "my-custom-logfile"])
self.assertEquals(None, self.defaultConfig.logfile())
self.assertEquals("my-custom-logfile", cfg.logfile())
self.assertEqual(None, self.defaultConfig.logfile())
self.assertEqual("my-custom-logfile", cfg.logfile())
def test_all_modules(self):
modules = core.config.all_modules()

View file

@ -7,6 +7,7 @@ import core.config
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))
@ -16,7 +17,6 @@ class TestModule(core.module.Module):
def get(self, widget):
return self.text
class config(unittest.TestCase):
def setUp(self):
self.module = TestModule()
@ -24,6 +24,10 @@ class config(unittest.TestCase):
self.width = 10
self.module.set("scrolling.width", self.width)
def test_never(self):
self.module = TestModule()
self.assertEqual("never", self.module.parameter("interval"))
def test_no_text(self):
self.assertEqual("", self.module.text)
self.assertEqual("", self.module.get(self.widget))

View file

@ -6,6 +6,7 @@ import shlex
import core.module
import core.widget
import core.config
import core.input
class TestModule(core.module.Module):
@ -137,5 +138,24 @@ class module(unittest.TestCase):
self.assertEqual(None, module.threshold_state(80, 80, 100))
self.assertEqual(None, module.threshold_state(10, 80, 100))
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
)
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4