Skip to content

Commit

Permalink
Added system test for Method
Browse files Browse the repository at this point in the history
  • Loading branch information
coretl committed Jun 1, 2016
1 parent 1248998 commit 9e2ad3e
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions tests/test_core/test_system_core.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import unittest
import sys
import os
sys.path.append(os.path.join(os.path.dirname(__file__), "..", ".."))

# module imports
from malcolm.core.controller import Controller
from malcolm.core.method import Method
from malcolm.core.mapmeta import MapMeta
from malcolm.core.stringmeta import StringMeta
from malcolm.core.block import Block


class HelloController(Controller):
def say_hello(self, args):
"""Says Hello to name
Args:
name (str): The name of the person to say hello to
Returns:
str: The greeting
"""
return dict(greeting="Hello %s" % args["name"])

def create_methods(self):
"""Create a Method wrapper for say_hello and return it"""
method = Method("say_hello")
method.set_function(self.say_hello)
takes = MapMeta("takes")
takes.add_element(StringMeta("name"))
method.set_function_takes(takes)
returns = MapMeta("returns")
returns.add_element(StringMeta("greeting"))
method.set_function_returns(returns)
yield method


class TestSystemCore(unittest.TestCase):
def setUp(self):
self.block = Block("Hello")
self.controller = HelloController(self.block)

def test_hello_controller_good_input(self):
result = self.block.say_hello(name = "me")
self.assertEquals(result["greeting"], "Hello me")

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

0 comments on commit 9e2ad3e

Please sign in to comment.