Skip to content

Commit

Permalink
Fix method decorators
Browse files Browse the repository at this point in the history
  • Loading branch information
c-mita committed Jun 20, 2016
1 parent a03116d commit 07b4012
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 30 deletions.
3 changes: 2 additions & 1 deletion malcolm/core/controller.py
Expand Up @@ -29,4 +29,5 @@ def create_methods(self):

for member in members:
if hasattr(member, "Method"):
yield member
member.Method.set_function(member)
yield member.Method
1 change: 0 additions & 1 deletion malcolm/core/method.py
Expand Up @@ -129,7 +129,6 @@ def wrap_method(cls, func):
name = func.__name__
description = getdoc(func)
method = cls(name, description)
method.set_function(func)
func.Method = method

return func
Expand Down
8 changes: 4 additions & 4 deletions tests/test_controllers/test_countercontroller.py
Expand Up @@ -14,10 +14,10 @@ def test_init(self):
self.assertEquals(2, len(block.add_method.call_args_list))
method_1 = block.add_method.call_args_list[0][0][0]
method_2 = block.add_method.call_args_list[1][0][0]
self.assertEquals("increment", method_1.Method.name)
self.assertEquals(c.increment, method_1)
self.assertEquals("reset", method_2.Method.name)
self.assertEquals(c.reset, method_2)
self.assertEquals("increment", method_1.name)
self.assertEquals(c.increment, method_1.func)
self.assertEquals("reset", method_2.name)
self.assertEquals(c.reset, method_2.func)

def test_increment_increments(self):
c = CounterController(Mock())
Expand Down
2 changes: 1 addition & 1 deletion tests/test_controllers/test_hellocontroller.py
Expand Up @@ -11,7 +11,7 @@ def test_init(self):
block = Mock()
c = HelloController(block)
self.assertIs(block, c.block)
self.assertEquals(c.say_hello, block.add_method.call_args[0][0])
self.assertEquals(c.say_hello.Method, block.add_method.call_args[0][0])

def test_say_hello(self):
c = HelloController(Mock())
Expand Down
26 changes: 3 additions & 23 deletions tests/test_core/test_controller.py
Expand Up @@ -8,10 +8,6 @@


class DummyController(Controller):
def __init__(self, mock_methods, block):
self.mock_methods = mock_methods
super(DummyController, self).__init__(block)

def say_hello(self, name):
print("Hello" + name)
say_hello.Method = MagicMock()
Expand All @@ -24,27 +20,11 @@ def say_goodbye(self, name):
class TestController(unittest.TestCase):

def test_init(self):
m1 = MagicMock()
m2 = MagicMock()
b = MagicMock()
c = DummyController([m1, m2], b)
c = DummyController(b)
self.assertEqual(c.block, b)
b.add_method.assert_has_calls([call(c.say_goodbye), call(c.say_hello)])

def test_find_decorated_functions(self):
m1 = MagicMock()
m2 = MagicMock()
b = MagicMock()
c = DummyController([m1, m2], b)

methods = []
for member in c.create_methods():
methods.append(member)

self.assertEqual(2, len(methods))
method_names = [method.__func__.__name__ for method in methods]
self.assertIn("say_hello", method_names)
self.assertIn("say_goodbye", method_names)
b.add_method.assert_has_calls(
[call(c.say_goodbye.Method), call(c.say_hello.Method)])

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

0 comments on commit 07b4012

Please sign in to comment.