From d42b7905c7fe3958bdbed5979f94b5105344af6c Mon Sep 17 00:00:00 2001 From: Charles Mita Date: Thu, 11 Aug 2016 14:17:24 +0100 Subject: [PATCH] Convert CounterController to CounterPart --- .../demo/counterpart.py} | 6 +-- .../test_countercontroller.py | 44 ------------------- tests/test_core/test_system_core.py | 11 ++--- .../test_parts/test_demo/test_counterpart.py | 37 ++++++++++++++++ 4 files changed, 46 insertions(+), 52 deletions(-) rename malcolm/{controllers/countercontroller.py => parts/demo/counterpart.py} (74%) delete mode 100644 tests/test_controllers/test_countercontroller.py create mode 100644 tests/test_parts/test_demo/test_counterpart.py diff --git a/malcolm/controllers/countercontroller.py b/malcolm/parts/demo/counterpart.py similarity index 74% rename from malcolm/controllers/countercontroller.py rename to malcolm/parts/demo/counterpart.py index 3ac132423..85014e2bc 100644 --- a/malcolm/controllers/countercontroller.py +++ b/malcolm/parts/demo/counterpart.py @@ -1,10 +1,10 @@ -from malcolm.core import Attribute, method_takes +from malcolm.core import Attribute, method_takes, Part from malcolm.core.vmetas import NumberMeta -from malcolm.controllers.defaultcontroller import DefaultController +from malcolm.controllers import DefaultController @method_takes() -class CounterController(DefaultController): +class CounterPart(Part): # Attribute for the counter value counter = None diff --git a/tests/test_controllers/test_countercontroller.py b/tests/test_controllers/test_countercontroller.py deleted file mode 100644 index 42cb81658..000000000 --- a/tests/test_controllers/test_countercontroller.py +++ /dev/null @@ -1,44 +0,0 @@ -import os -import sys -sys.path.append(os.path.join(os.path.dirname(__file__), "..")) -import setup_malcolm_paths - -# logging -# import logging -# logging.basicConfig(level=logging.DEBUG) - -import unittest -from mock import Mock, ANY - -from malcolm.controllers.countercontroller import CounterController -from malcolm.core.block import Block - - -class TestCounterController(unittest.TestCase): - - def test_increment_increments(self): - c = CounterController('block', Mock()) - self.assertEquals(0, c.counter.value) - c.increment() - self.assertEquals(1, c.counter.value) - c.increment() - self.assertEquals(2, c.counter.value) - - def test_increment_calls_on_changed(self): - c = CounterController('block', Mock()) - c.increment() - self.assertEquals(1, c.counter.value) - c.process.report_changes.assert_called_once_with( - [['block', 'counter', 'value'], 1]) - - def test_reset_sets_zero(self): - c = CounterController('block', Mock()) - c.counter.set_endpoint_data("value", 1234, notify=False) - c.do_reset() - self.assertEquals(0, c.counter.value) - c.process.report_changes.assert_called_once_with( - [['block', 'counter', 'value'], 0]) - - -if __name__ == "__main__": - unittest.main(verbosity=2) diff --git a/tests/test_core/test_system_core.py b/tests/test_core/test_system_core.py index 6108070cc..47f972481 100644 --- a/tests/test_core/test_system_core.py +++ b/tests/test_core/test_system_core.py @@ -11,7 +11,7 @@ # logging.basicConfig(level=logging.DEBUG) # module imports -from malcolm.controllers import CounterController, DefaultController +from malcolm.controllers import DefaultController from malcolm.core.attribute import Attribute from malcolm.core.block import Block from malcolm.core.process import Process @@ -19,7 +19,7 @@ from malcolm.core.request import Post, Subscribe from malcolm.core.response import Return, Update from malcolm.core.task import Task -from malcolm.parts.demo.hellopart import HelloPart +from malcolm.parts.demo import HelloPart, CounterPart class TestHelloDemoSystem(unittest.TestCase): @@ -56,12 +56,13 @@ def test_hello_with_process(self): process.stop() -class TestCounterControllerSystem(unittest.TestCase): +class TestCounterDemoSystem(unittest.TestCase): - def test_counter_controller_subscribe(self): + def test_counter_subscribe(self): sync_factory = SyncFactory("sched") process = Process("proc", sync_factory) - CounterController("counting", process) + part = CounterPart(process, None) + DefaultController("counting", process, parts={"counter":part}) process.start() q = sync_factory.create_queue() diff --git a/tests/test_parts/test_demo/test_counterpart.py b/tests/test_parts/test_demo/test_counterpart.py new file mode 100644 index 000000000..a327d9845 --- /dev/null +++ b/tests/test_parts/test_demo/test_counterpart.py @@ -0,0 +1,37 @@ +import os +import sys +sys.path.append(os.path.join(os.path.dirname(__file__), "..", "..")) +import setup_malcolm_paths + +# logging +# import logging +# logging.basicConfig(level=logging.DEBUG) + +import unittest +from mock import Mock, ANY + +from malcolm.parts.demo import CounterPart +from malcolm.core.block import Block + + +class TestCounterPart(unittest.TestCase): + + def setUp(self): + self.c = CounterPart(Mock(), None) + list(self.c.create_attributes()) + + def test_increment_increments(self): + self.assertEquals(0, self.c.counter.value) + self.c.increment() + self.assertEquals(1, self.c.counter.value) + self.c.increment() + self.assertEquals(2, self.c.counter.value) + + def test_reset_sets_zero(self): + self.c.counter.set_endpoint_data("value", 1234, notify=False) + self.c.do_reset() + self.assertEquals(0, self.c.counter.value) + + +if __name__ == "__main__": + unittest.main(verbosity=2)