[core/widget] bump test coverage
This commit is contained in:
parent
9755a70578
commit
908ef67109
2 changed files with 38 additions and 9 deletions
|
@ -29,16 +29,10 @@ class Widget(util.store.Store, core.input.Object):
|
||||||
rv = []
|
rv = []
|
||||||
if self.get('state', None):
|
if self.get('state', None):
|
||||||
tmp = self.get('state')
|
tmp = self.get('state')
|
||||||
if isinstance(tmp, list):
|
rv = tmp[:] if isinstance(tmp, list) else [tmp]
|
||||||
rv.extend(tmp)
|
|
||||||
else:
|
|
||||||
rv.append(tmp)
|
|
||||||
if self._module:
|
if self._module:
|
||||||
tmp = self._module.state(self)
|
tmp = self._module.state(self)
|
||||||
if isinstance(tmp, list):
|
rv.extend(tmp if isinstance(tmp, list) else [tmp])
|
||||||
rv.extend(tmp)
|
return rv
|
||||||
else:
|
|
||||||
rv.append(tmp)
|
|
||||||
return rv if isinstance(rv, list) else [rv]
|
|
||||||
|
|
||||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||||
|
|
|
@ -2,6 +2,21 @@ import unittest
|
||||||
import unittest.mock
|
import unittest.mock
|
||||||
|
|
||||||
import core.widget
|
import core.widget
|
||||||
|
import core.module
|
||||||
|
import core.config
|
||||||
|
|
||||||
|
class TestModule(core.module.Module):
|
||||||
|
def __init__(self, widgets, config=core.config.Config([])):
|
||||||
|
super().__init__(config, widgets)
|
||||||
|
self.states = []
|
||||||
|
|
||||||
|
def update(self):
|
||||||
|
if self.fail:
|
||||||
|
raise Exception(self.error)
|
||||||
|
pass
|
||||||
|
|
||||||
|
def state(self, widget):
|
||||||
|
return self.states
|
||||||
|
|
||||||
class widget(unittest.TestCase):
|
class widget(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
@ -35,4 +50,24 @@ class widget(unittest.TestCase):
|
||||||
self.assertEqual(self.someWidget.full_text(), self.callbackReturnValue)
|
self.assertEqual(self.someWidget.full_text(), self.callbackReturnValue)
|
||||||
self.someCallback.assert_called_once_with(self.someWidget)
|
self.someCallback.assert_called_once_with(self.someWidget)
|
||||||
|
|
||||||
|
def test_state_defaults_to_empty(self):
|
||||||
|
self.assertEqual([], self.someWidget.state())
|
||||||
|
|
||||||
|
def test_single_widget_state(self):
|
||||||
|
self.someWidget.set('state', 'state1')
|
||||||
|
self.assertEqual(['state1'], self.someWidget.state())
|
||||||
|
|
||||||
|
def test_multiple_widget_states(self):
|
||||||
|
self.someWidget.set('state', ['state1', 'state2'])
|
||||||
|
self.assertEqual(['state1', 'state2'], self.someWidget.state())
|
||||||
|
|
||||||
|
def test_widget_module_state(self):
|
||||||
|
module = TestModule(widgets=self.someWidget)
|
||||||
|
self.someWidget.set('state', ['state1', 'state2'])
|
||||||
|
|
||||||
|
module.states = 'x'
|
||||||
|
self.assertEqual(['state1', 'state2', 'x'], self.someWidget.state())
|
||||||
|
module.states = ['a', 'b']
|
||||||
|
self.assertEqual(['state1', 'state2', 'a', 'b'], self.someWidget.state())
|
||||||
|
|
||||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||||
|
|
Loading…
Reference in a new issue