Skip to content

Commit

Permalink
Convert CounterController to CounterPart
Browse files Browse the repository at this point in the history
  • Loading branch information
c-mita committed Aug 11, 2016
1 parent 3120f05 commit d42b790
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 52 deletions.
@@ -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

Expand Down
44 changes: 0 additions & 44 deletions tests/test_controllers/test_countercontroller.py

This file was deleted.

11 changes: 6 additions & 5 deletions tests/test_core/test_system_core.py
Expand Up @@ -11,15 +11,15 @@
# 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
from malcolm.core.syncfactory import SyncFactory
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):
Expand Down Expand Up @@ -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()

Expand Down
37 changes: 37 additions & 0 deletions 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)

0 comments on commit d42b790

Please sign in to comment.