[core/output] Add widget drawing
Add basic drawing of widgets. Each module instance returns a list of widgets using the widgets() method which is then forwarded to the draw() method of the configured output. see #23
This commit is contained in:
parent
6f52825ef0
commit
712d958e18
5 changed files with 41 additions and 1 deletions
0
tests/__init__.py
Normal file
0
tests/__init__.py
Normal file
|
@ -1,4 +1,5 @@
|
|||
# pylint: disable=C0103,C0111
|
||||
|
||||
import json
|
||||
import unittest
|
||||
import mock
|
||||
|
@ -8,12 +9,14 @@ except ImportError:
|
|||
from io import StringIO
|
||||
|
||||
from bumblebee.output import I3BarOutput
|
||||
from tests.util import MockWidget
|
||||
|
||||
class TestI3BarOutput(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.output = I3BarOutput()
|
||||
self.expectedStart = json.dumps({"version": 1, "click_events": True}) + "[\n"
|
||||
self.expectedStop = "]\n"
|
||||
self.someWidget = MockWidget("foo bar baz")
|
||||
|
||||
@mock.patch("sys.stdout", new_callable=StringIO)
|
||||
def test_start(self, stdout):
|
||||
|
@ -25,4 +28,17 @@ class TestI3BarOutput(unittest.TestCase):
|
|||
self.output.stop()
|
||||
self.assertEquals(self.expectedStop, stdout.getvalue())
|
||||
|
||||
@mock.patch("sys.stdout", new_callable=StringIO)
|
||||
def test_draw_single_widget(self, stdout):
|
||||
self.output.draw(self.someWidget)
|
||||
result = json.loads(stdout.getvalue())[0]
|
||||
self.assertEquals(result["full_text"], self.someWidget.text())
|
||||
|
||||
@mock.patch("sys.stdout", new_callable=StringIO)
|
||||
def test_draw_multiple_widgets(self, stdout):
|
||||
self.output.draw([self.someWidget, self.someWidget])
|
||||
result = json.loads(stdout.getvalue())
|
||||
for res in result:
|
||||
self.assertEquals(res["full_text"], self.someWidget.text())
|
||||
|
||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||
|
|
10
tests/util.py
Normal file
10
tests/util.py
Normal file
|
@ -0,0 +1,10 @@
|
|||
# pylint: disable=C0103,C0111
|
||||
|
||||
class MockWidget(object):
|
||||
def __init__(self, text):
|
||||
self._text = text
|
||||
|
||||
def text(self):
|
||||
return self._text
|
||||
|
||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
Loading…
Add table
Add a link
Reference in a new issue