From 47950240d04635be8b9a8757544283fc7da6d9e9 Mon Sep 17 00:00:00 2001 From: Tobias Witek Date: Thu, 5 Mar 2020 21:17:06 +0100 Subject: [PATCH] [tests/core/module] Add tests for widget retrieval by name --- tests/core/test_module.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/core/test_module.py b/tests/core/test_module.py index 6e1542e..cf8e387 100644 --- a/tests/core/test_module.py +++ b/tests/core/test_module.py @@ -16,8 +16,9 @@ class module(unittest.TestCase): def setUp(self): self.invalidModuleName = 'invalid-module-name' self.validModuleName = 'test' - self.someWidget = core.widget.Widget('randomeWidgetContent') - self.anotherWidget = core.widget.Widget('more Widget content') + self.someWidget = core.widget.Widget('randomeWidgetContent', name='A') + self.anotherWidget = core.widget.Widget('more Widget content', name='B') + self.unusedWidgetName = 'C' def test_loadinvalid_module(self): config = unittest.mock.MagicMock() @@ -80,4 +81,13 @@ class module(unittest.TestCase): self.assertEqual(1, len(module.widgets())) self.assertEqual('error: !!', module.widget().full_text()) + def test_get_widget_by_name(self): + cfg = core.config.Config([]) + module = TestModule(config=cfg, widgets=[self.someWidget, self.anotherWidget]) + + self.assertEqual(self.someWidget, module.widget(self.someWidget.name())) + self.assertEqual(self.anotherWidget, module.widget(self.anotherWidget.name())) + self.assertEqual(None, module.widget(self.unusedWidgetName)) + self.assertEqual(self.someWidget, module.widget()) + # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4