-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for mapek_framework components (#14)
* Add test suite skeleton * Add `Group` tests * Fix assert_called() AttributeError * Interaction TestCase * Update test dependecies * ManagedSystem TestCase * MapeElement TestSuite * Ticker TestCase
- Loading branch information
Showing
9 changed files
with
120 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/usr/bin/env python | ||
import unittest | ||
import rosunit | ||
from .test_group import GroupTestCase | ||
from .test_interaction import InteractionTestCase | ||
from .test_managed_system import ManagedSystemTestCase | ||
from .test_mape_element import MapeElementTestCase | ||
from .test_ticker import TickerTestCase | ||
|
||
|
||
if __name__ == '__main__': | ||
rosunit.unitrun('test_mapek_framework', | ||
'test_group_mapek_framework', GroupTestCase) | ||
rosunit.unitrun('test_mapek_framework', | ||
'test_interaction_mapek_framework', InteractionTestCase) | ||
rosunit.unitrun('test_mapek_framework', | ||
'test_managed_system_mapek_framework', ManagedSystemTestCase) | ||
rosunit.unitrun('test_mapek_framework', | ||
'test_mape_element_mapek_framework', MapeElementTestCase) | ||
rosunit.unitrun('test_mapek_framework', | ||
'test_ticker_mapek_framework', TickerTestCase) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import unittest | ||
import mock | ||
from mapek_framework import Group | ||
|
||
|
||
class GroupTestCase(unittest.TestCase): | ||
|
||
@mock.patch('rospy.spin') | ||
@mock.patch('rospy.init_node') | ||
def test_group_spin(self, mock_init_node, mock_spin): | ||
node_name = 'test_node' | ||
|
||
mock_monitor_element = mock.Mock() | ||
mock_analyze_element = mock.Mock() | ||
mock_plan_element = mock.Mock() | ||
mock_execute_element = mock.Mock() | ||
|
||
knowledge_instance = {} | ||
managed_system_instance = None | ||
|
||
class MyGroup(Group): | ||
elements = [ | ||
mock_monitor_element, | ||
mock_analyze_element, | ||
mock_plan_element, | ||
mock_execute_element | ||
] | ||
knowledge = knowledge_instance | ||
managed_system = managed_system_instance | ||
|
||
my_group_instance = MyGroup(node_name) | ||
self.assertEqual(mock_init_node.call_count, 1) | ||
self.assertEqual(mock_spin.call_count, 0) | ||
mock_monitor_element.assert_called_with(knowledge_instance, managed_system_instance) | ||
mock_analyze_element.assert_called_with(knowledge_instance, managed_system_instance) | ||
mock_plan_element.assert_called_with(knowledge_instance, managed_system_instance) | ||
mock_execute_element.assert_called_with(knowledge_instance, managed_system_instance) | ||
|
||
my_group_instance.spin() | ||
self.assertEqual(mock_init_node.call_count, 1) | ||
self.assertEqual(mock_spin.call_count, 1) |
14 changes: 14 additions & 0 deletions
14
mapek_framework/src/test_mapek_framework/test_interaction.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import unittest | ||
from std_msgs.msg import Empty | ||
from mapek_framework import Interaction | ||
|
||
|
||
class InteractionTestCase(unittest.TestCase): | ||
|
||
def test_interaxction_fields(self): | ||
name = 'foo' | ||
data_class = Empty | ||
|
||
interaction_instance = Interaction(name, data_class) | ||
self.assertEqual(interaction_instance.name, name) | ||
self.assertEqual(interaction_instance.data_class, data_class) |
6 changes: 6 additions & 0 deletions
6
mapek_framework/src/test_mapek_framework/test_managed_system.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import unittest | ||
from mapek_framework import ManagedSystem | ||
|
||
class ManagedSystemTestCase(unittest.TestCase): | ||
pass | ||
|
12 changes: 12 additions & 0 deletions
12
mapek_framework/src/test_mapek_framework/test_mape_element.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import unittest | ||
import mock | ||
from mapek_framework.mape_element import _MapeElement, MonitorElement, AnalyzeElement, PlanElement, ExecuteElement | ||
|
||
|
||
class MapeElementTestCase(unittest.TestCase): | ||
|
||
def test_mape_element_inheritance(self): | ||
self.assertTrue(issubclass(MonitorElement, _MapeElement)) | ||
self.assertTrue(issubclass(AnalyzeElement, _MapeElement)) | ||
self.assertTrue(issubclass(PlanElement, _MapeElement)) | ||
self.assertTrue(issubclass(ExecuteElement, _MapeElement)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import unittest | ||
from mapek_framework import Ticker | ||
|
||
|
||
class TickerTestCase(unittest.TestCase): | ||
|
||
def test_ticker_init(self): | ||
node_name = 'foo_name' | ||
topic = 'foo_topic' | ||
rate = 42 | ||
|
||
ticker_instance = Ticker(node_name, topic, rate) | ||
self.assertEqual(ticker_instance._node_name, node_name) | ||
self.assertEqual(ticker_instance._topic, topic) | ||
self.assertEqual(ticker_instance._rate, rate) |