[tests] Refactor by removing getter/setter methods

Instead of having get/set methods for simple attributes, use the
attributes directly.

see #23
This commit is contained in:
Tobi-wan Kenobi 2016-12-09 11:42:02 +01:00
parent c52cb99518
commit 068968bbf5
3 changed files with 19 additions and 34 deletions

View file

@ -60,7 +60,7 @@ class TestI3BarOutput(unittest.TestCase):
@mock.patch("sys.stdout", new_callable=StringIO)
def test_prefix(self, stdout):
self.theme.set_prefix(" - ")
self.theme.attr_prefix = " - "
self.output.draw(self.someWidget)
self.output.flush()
result = json.loads(stdout.getvalue())[0]
@ -70,7 +70,7 @@ class TestI3BarOutput(unittest.TestCase):
@mock.patch("sys.stdout", new_callable=StringIO)
def test_suffix(self, stdout):
self.theme.set_suffix(" - ")
self.theme.attr_suffix = " - "
self.output.draw(self.someWidget)
self.output.flush()
result = json.loads(stdout.getvalue())[0]
@ -80,8 +80,8 @@ class TestI3BarOutput(unittest.TestCase):
@mock.patch("sys.stdout", new_callable=StringIO)
def test_bothfix(self, stdout):
self.theme.set_suffix(" - ")
self.theme.set_prefix(" * ")
self.theme.attr_suffix = " - "
self.theme.attr_prefix = " * "
self.output.draw(self.someWidget)
self.output.flush()
result = json.loads(stdout.getvalue())[0]
@ -93,8 +93,8 @@ class TestI3BarOutput(unittest.TestCase):
@mock.patch("sys.stdout", new_callable=StringIO)
def test_colors(self, stdout):
self.theme.set_fg(self.anyColor)
self.theme.set_bg(self.anotherColor)
self.theme.attr_fg = self.anyColor
self.theme.attr_bg = self.anotherColor
self.output.draw(self.someWidget)
self.output.flush()
result = json.loads(stdout.getvalue())[0]

View file

@ -44,17 +44,17 @@ class TestTheme(unittest.TestCase):
self.assertEquals(self.theme.suffix(self.someWidget), self.defaultSuffix)
def test_widget_prefix(self):
self.someWidget.set_module(self.widgetTheme)
self.someWidget.attr_module = self.widgetTheme
self.assertEquals(self.theme.prefix(self.someWidget), self.widgetPrefix)
def test_widget_fg(self):
self.assertEquals(self.theme.fg(self.someWidget), self.defaultColor)
self.someWidget.set_module(self.widgetTheme)
self.someWidget.attr_module = self.widgetTheme
self.assertEquals(self.theme.fg(self.someWidget), self.widgetColor)
def test_widget_bg(self):
self.assertEquals(self.theme.bg(self.someWidget), self.defaultBgColor)
self.someWidget.set_module(self.widgetTheme)
self.someWidget.attr_module = self.widgetTheme
self.assertEquals(self.theme.bg(self.someWidget), self.widgetBgColor)
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4

View file

@ -31,49 +31,34 @@ class MockOutput(object):
class MockWidget(object):
def __init__(self, text):
self._text = text
self._module = None
def set_module(self, name):
self._module = name
self.attr_module = None
def update(self, widgets):
pass
def module(self):
return self._module
return self.attr_module
def full_text(self):
return self._text
class MockTheme(object):
def __init__(self):
self._prefix = None
self._suffix = None
self._fg = None
self._bg = None
def set_prefix(self, value):
self._prefix = value
def set_suffix(self, value):
self._suffix = value
def set_fg(self, value):
self._fg = value
def set_bg(self, value):
self._bg = value
self.attr_prefix = None
self.attr_suffix = None
self.attr_fg = None
self.attr_bg = None
def prefix(self, widget):
return self._prefix
return self.attr_prefix
def suffix(self, widget):
return self._suffix
return self.attr_suffix
def fg(self, widget):
return self._fg
return self.attr_fg
def bg(self, widget):
return self._bg
return self.attr_bg
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4