From 7584366adc5f489bb5b73d0bb1be249d24735045 Mon Sep 17 00:00:00 2001 From: tobi-wan-kenobi Date: Sat, 16 May 2020 11:55:25 +0200 Subject: [PATCH] [tests] add more tests --- docs/other/NOTES.md | 1 + tests/core/test_config.py | 4 ++-- tests/core/test_decorators.py | 6 +++++- tests/core/test_module.py | 20 ++++++++++++++++++++ 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/docs/other/NOTES.md b/docs/other/NOTES.md index 1b4e699..3ba0c14 100644 --- a/docs/other/NOTES.md +++ b/docs/other/NOTES.md @@ -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 diff --git a/tests/core/test_config.py b/tests/core/test_config.py index 27931ff..e468f3a 100644 --- a/tests/core/test_config.py +++ b/tests/core/test_config.py @@ -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() diff --git a/tests/core/test_decorators.py b/tests/core/test_decorators.py index 4ad1410..e9c755a 100644 --- a/tests/core/test_decorators.py +++ b/tests/core/test_decorators.py @@ -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)) diff --git a/tests/core/test_module.py b/tests/core/test_module.py index 71f59ad..aad7ca5 100644 --- a/tests/core/test_module.py +++ b/tests/core/test_module.py @@ -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