[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 = []
|
||||
if self.get('state', None):
|
||||
tmp = self.get('state')
|
||||
if isinstance(tmp, list):
|
||||
rv.extend(tmp)
|
||||
else:
|
||||
rv.append(tmp)
|
||||
rv = tmp[:] if isinstance(tmp, list) else [tmp]
|
||||
if self._module:
|
||||
tmp = self._module.state(self)
|
||||
if isinstance(tmp, list):
|
||||
rv.extend(tmp)
|
||||
else:
|
||||
rv.append(tmp)
|
||||
return rv if isinstance(rv, list) else [rv]
|
||||
rv.extend(tmp if isinstance(tmp, list) else [tmp])
|
||||
return rv
|
||||
|
||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||
|
|
|
@ -2,6 +2,21 @@ import unittest
|
|||
import unittest.mock
|
||||
|
||||
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):
|
||||
def setUp(self):
|
||||
|
@ -35,4 +50,24 @@ class widget(unittest.TestCase):
|
|||
self.assertEqual(self.someWidget.full_text(), self.callbackReturnValue)
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue