Skip to content

Commit

Permalink
Create Part and add to Controller
Browse files Browse the repository at this point in the history
  • Loading branch information
c-mita committed Jul 13, 2016
1 parent 55fb349 commit 3de8de0
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
5 changes: 3 additions & 2 deletions malcolm/core/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def __init__(self, process, block):

self.writeable_methods = OrderedDict()
self.process = process

self.parts = []
self.block = block
for attribute in self.create_attributes():
block.add_attribute(attribute)
Expand Down Expand Up @@ -66,7 +66,8 @@ def create_attributes(self):
"Busy", BooleanMeta("meta", "Whether Block busy or not"))
yield self.busy


def add_parts(self, parts):
self.parts.extend(parts)

def transition(self, state, message):
"""
Expand Down
10 changes: 10 additions & 0 deletions malcolm/core/part.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from malcolm.core.loggable import Loggable

class Part(Loggable):

def __init__(self, name, process, block):
self.set_logger_name("Part")
self.process = process
self.block = block
self.name = name
self.set_logger_name("%s.%s", block, name)
6 changes: 6 additions & 0 deletions tests/test_core/test_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def test_init(self):
self.c.process.add_block.assert_called_once_with(self.c.block)
self.c.block.add_method.assert_has_calls(
[call(self.c.say_goodbye.Method), call(self.c.say_hello.Method)])
self.assertEqual([], self.c.parts)

self.assertEqual(self.c.state.name, "State")
self.assertEqual(
Expand Down Expand Up @@ -87,5 +88,10 @@ def test_set_writeable_methods(self):

self.assertEqual(["configure"], self.c.writeable_methods['Idle'])

def test_add_part(self):
parts = [MagicMock(), MagicMock()]
self.c.add_parts(parts)
self.assertEqual(parts, self.c.parts)

if __name__ == "__main__":
unittest.main(verbosity=2)
21 changes: 21 additions & 0 deletions tests/test_core/test_part.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import os
import sys
sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
import setup_malcolm_paths

import unittest
from mock import Mock

from malcolm.core.part import Part

class TestPart(unittest.TestCase):
def test_init(self):
process = Mock()
block = Mock()
p = Part("part", process, block)
self.assertIs(process, p.process)
self.assertIs(block, p.block)
self.assertEquals("part", p.name)

if __name__ == "__main__":
unittest.main(verbosity=2)

0 comments on commit 3de8de0

Please sign in to comment.