diff --git a/bumblebee/engine.py b/bumblebee/engine.py index 0264083..0213062 100644 --- a/bumblebee/engine.py +++ b/bumblebee/engine.py @@ -19,7 +19,8 @@ class Engine(object): This class connects input/output, instantiates all required modules and drives the "event loop" """ - def __init__(self, config): + def __init__(self, config, output=None): + self._output = output self._running = True self._modules = [] self.load_modules(config.modules()) @@ -45,7 +46,10 @@ class Engine(object): def run(self): """Start the event loop""" + self._output.start() while self.running(): pass + self._output.stop() + # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 diff --git a/bumblebee/output.py b/bumblebee/output.py new file mode 100644 index 0000000..d09f63a --- /dev/null +++ b/bumblebee/output.py @@ -0,0 +1,21 @@ +# pylint: disable=R0201 + +"""Output classes""" + +import sys +import json + +class I3BarOutput(object): + """Manage output according to the i3bar protocol""" + def __init__(self): + pass + + def start(self): + """Print start preamble for i3bar protocol""" + sys.stdout.write(json.dumps({"version": 1, "click_events": True}) + "[\n") + + def stop(self): + """Finish i3bar protocol""" + sys.stdout.write("]\n") + +# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 diff --git a/runlint.sh b/runlint.sh index 0d35fb5..022534d 100755 --- a/runlint.sh +++ b/runlint.sh @@ -1,3 +1,3 @@ #!/bin/sh -find . -name "*.py"|xargs pylint +find . -name "*.py"|xargs pylint --disable=R0903 diff --git a/tests/test_engine.py b/tests/test_engine.py index 7a6152f..cc5c69f 100644 --- a/tests/test_engine.py +++ b/tests/test_engine.py @@ -10,8 +10,8 @@ class TestEngine(unittest.TestCase): self.testModule = "test" self.testModuleSpec = "bumblebee.modules.{}".format(self.testModule) self.testModules = [ - { "module": "test", "name": "a" }, - { "module": "test", "name": "b" }, + {"module": "test", "name": "a"}, + {"module": "test", "name": "b"}, ] def test_stop(self): @@ -27,8 +27,8 @@ class TestEngine(unittest.TestCase): modules = self.engine.load_modules(self.testModules) self.assertEquals(len(modules), len(self.testModules)) self.assertEquals( - [ module.__module__ for module in modules ], - [ self.testModuleSpec for module in modules ] + [module.__module__ for module in modules], + [self.testModuleSpec for module in modules] ) # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 diff --git a/tests/test_i3baroutput.py b/tests/test_i3baroutput.py new file mode 100644 index 0000000..9fff324 --- /dev/null +++ b/tests/test_i3baroutput.py @@ -0,0 +1,28 @@ +# pylint: disable=C0103,C0111 +import json +import unittest +import mock +try: + from StringIO import StringIO +except ImportError: + from io import StringIO + +from bumblebee.output import I3BarOutput + +class TestI3BarOutput(unittest.TestCase): + def setUp(self): + self.output = I3BarOutput() + self.expectedStart = json.dumps({"version": 1, "click_events": True}) + "[\n" + self.expectedStop = "]\n" + + @mock.patch("sys.stdout", new_callable=StringIO) + def test_start(self, stdout): + self.output.start() + self.assertEquals(self.expectedStart, stdout.getvalue()) + + @mock.patch("sys.stdout", new_callable=StringIO) + def test_stop(self, stdout): + self.output.stop() + self.assertEquals(self.expectedStop, stdout.getvalue()) + +# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4