From cf1693548b0fe595319074a1549b984ce36f8742 Mon Sep 17 00:00:00 2001 From: Tobi-wan Kenobi Date: Sun, 4 Dec 2016 08:37:01 +0100 Subject: [PATCH] [engine] Add initial version of event loop engine Re-add the engine that is responsible for tying together input, output, etc. see #23 --- bumblebee-status | 18 ++++++++++++++++++ bumblebee/engine.py | 25 +++++++++++++++++++++++++ tests/test_engine.py | 13 +++++++++++++ 3 files changed, 56 insertions(+) mode change 100644 => 100755 bumblebee-status create mode 100644 bumblebee/engine.py create mode 100644 tests/test_engine.py diff --git a/bumblebee-status b/bumblebee-status old mode 100644 new mode 100755 index e69de29..b048a61 --- a/bumblebee-status +++ b/bumblebee-status @@ -0,0 +1,18 @@ +#!/usr/bin/env python + +import sys +import bumblebee.engine +import bumblebee.config + +def main(): + config = bumblebee.config.Config(sys.argv[1:]) + engine = bumblebee.engine.Engine( + config=config + ) + + engine.run() + +if __name__ == "__main__": + main() + +# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 diff --git a/bumblebee/engine.py b/bumblebee/engine.py new file mode 100644 index 0000000..f9996b6 --- /dev/null +++ b/bumblebee/engine.py @@ -0,0 +1,25 @@ +"""Core application engine""" + +class Engine(object): + """Engine for driving the application + + This class connects input/output, instantiates all + required modules and drives the "event loop" + """ + def __init__(self, config): + self._running = True + + def running(self): + """Check whether the event loop is running""" + return self._running + + def stop(self): + """Stop the event loop""" + self._running = False + + def run(self): + """Start the event loop""" + while self.running(): + pass + +# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 diff --git a/tests/test_engine.py b/tests/test_engine.py new file mode 100644 index 0000000..0d81578 --- /dev/null +++ b/tests/test_engine.py @@ -0,0 +1,13 @@ +# pylint: disable=C0103,C0111 +import unittest + +from bumblebee.engine import Engine + +class TestEngine(unittest.TestCase): + def setUp(self): + self.engine = Engine(None) + + def test_stop(self): + self.assertTrue(self.engine.running()) + self.engine.stop() + self.assertFalse(self.engine.running())