class TestComponent(unittest.TestCase): def setUp(self): self.c = Component() # Creates a single set-up code for all test cases that need an instance of Component # It is called for every single test case def test_add_connection(self): self.assertRaises(Exception, self.c.add_connection, (from_subcomponent, from_interface), (to_subcomponent, to_interface)) # Assuming there should be an error if since the subcomponents have not been defined yet def test_add_interface_valueerror(self): self.assertRaises(ValueError, self.p.add_interface, "invalid_name", Port()) # A ValueError should be raised because the name cannot have underscores # Are there any other invalid characters? def test_get_interface(self): p = Port() self.c.add_interface("AnInterface", p) self.assertEqual(self.c.get_interface("AnInterface"), p) # Is this a correct comparison? # Adds an interface, and then checks it def test_get_subcomponent(self): self.c.add_subcomponent("TestSubcomponent", "Component") self.assertEqual( isinstance(self.c.get_subcomponent("TestSubcomponent"), Component()), True) def test_make(self): try: self.c.make() self.assertEqual(True, True) except: self.assertEqual(True, False) def test_delete_subcomponent(self): self.c.add_subcomponent("TestSubcomponent", "Component") try: self.c.delete_subcomponent("TestSubcomponent") self.assertEqual(True, True) except: self.assertEqual(True, False) def test_delete_interface(self): p = Port() self.c.add_interface("AnInterface", p) try: self.c.delete_interface("AnInterface") self.assertEqual(True, True) except: self.assertEqual(True, False) def test_define(self): try: self.c.define() self.assertEqual(True, True) except: self.assertEqual(True, False) def test_to_yaml(self): # p = Port(); self.c.add_interface("AnInterface",p) self.c.add_parameter("Width", 79) self.c.to_yaml("testfile") c2 = Component() c2.from_yaml("testfile") self.assertEqual(c2.get_parameter("Width"), 79) def test_assemble(self): try: self.c.assemble() self.assertEqual(True, True) except: self.assertEqual(True, False) def test_make(self): try: self.c.make() self.assertEqual(True, True) except: self.assertEqual(True, False) def test_reset(self): try: self.c.reset() self.assertEqual(True, True) except: self.assertEqual(True, False) def test_make_component_tree(self): try: self.c.make_component_tree("FileName", "TreeName") self.assertEqual(True, True) except: self.assertEqual(True, False)
from roco.api.component import Component from roco.library import * from roco.library import get_component c = Component(name='interface') c.add_subcomponent('button_one', 'web_button') c.add_subcomponent('button_two', 'web_button') c.add_subcomponent('button_three', 'web_button') c.get_subcomponent('button_one').set_parameter('buttonValue', 'GO') c.get_subcomponent('button_two').set_parameter('buttonValue', 'BACK') c.get_subcomponent('button_three').set_parameter('buttonValue', 'STOP') c.make_output()
from roco.api.component import Component from roco.library import * from roco.library import get_component if __name__ == "__main__": c = Component(name = 'Car') c.add_subcomponent('Constant0', 'Constant') c.add_subcomponent('Constant1', 'Constant') c.add_subcomponent('Constant2', 'Constant') c.add_subcomponent('Constant3', 'Constant') c.add_subcomponent('DrivenServo0', 'DrivenServo') c.add_subcomponent('DrivenServo1', 'DrivenServo') c.add_subcomponent('DrivenServo2', 'DrivenServo') c.add_subcomponent('DrivenServo3', 'DrivenServo') c.add_subcomponent('node_mcu0', 'node_mcu') c.add_connection(('node_mcu0', 'do1'), ('DrivenServo0', 'PWMin')) c.add_connection(('Constant0', 'num'), ('DrivenServo0', 'inInt')) c.add_connection(('node_mcu0', 'do2'), ('DrivenServo1', 'PWMin')) c.add_connection(('Constant1', 'num'), ('DrivenServo1', 'inInt')) c.add_connection(('node_mcu0', 'do3'), ('DrivenServo2', 'PWMin')) c.add_connection(('Constant2', 'num'), ('DrivenServo2', 'inInt')) c.add_connection(('node_mcu0', 'do4'), ('DrivenServo3', 'PWMin')) c.add_connection(('Constant3', 'num'), ('DrivenServo3', 'inInt')) c.get_subcomponent('Constant0').set_parameter('num', '130') c.get_subcomponent('Constant1').set_parameter('num', '130') c.get_subcomponent('Constant2').set_parameter('num', '130') c.get_subcomponent('Constant3').set_parameter('num', '130') c.to_yaml("library/car.yaml") c.make_output()