From 068968bbf557d20977d87c9bfb029c60f9a3c976 Mon Sep 17 00:00:00 2001 From: Tobi-wan Kenobi Date: Fri, 9 Dec 2016 11:42:02 +0100 Subject: [PATCH] [tests] Refactor by removing getter/setter methods Instead of having get/set methods for simple attributes, use the attributes directly. see #23 --- tests/test_i3baroutput.py | 12 ++++++------ tests/test_theme.py | 6 +++--- tests/util.py | 35 ++++++++++------------------------- 3 files changed, 19 insertions(+), 34 deletions(-) diff --git a/tests/test_i3baroutput.py b/tests/test_i3baroutput.py index a836247..60ed671 100644 --- a/tests/test_i3baroutput.py +++ b/tests/test_i3baroutput.py @@ -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] diff --git a/tests/test_theme.py b/tests/test_theme.py index 51b10a9..3b5690a 100644 --- a/tests/test_theme.py +++ b/tests/test_theme.py @@ -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 diff --git a/tests/util.py b/tests/util.py index 564fe54..7eb73ce 100644 --- a/tests/util.py +++ b/tests/util.py @@ -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