How to use _create_node method in lisa

Best Python code snippet using lisa_python

test_node.py

Source:test_node.py Github

copy

Full Screen

...30 ld = LaunchDescription(actions)31 ls = LaunchService()32 ls.include_launch_description(ld)33 assert 0 == ls.run()34 def _create_node(self, *, parameters=None, remappings=None):35 return launch_ros.actions.Node(36 package='demo_nodes_py', node_executable='talker_qos', output='screen',37 # The node name is required for parameter dicts.38 # See https://github.com/ros2/launch/issues/139.39 node_name='my_node', node_namespace='my_ns',40 arguments=['--number_of_cycles', '1'],41 parameters=parameters,42 remappings=remappings,43 )44 def _assert_type_error_creating_node(self, *, parameters=None, remappings=None):45 with self.assertRaises(TypeError):46 self._create_node(parameters=parameters, remappings=remappings)47 def test_launch_invalid_node(self):48 """Test launching an invalid node."""49 node_action = launch_ros.actions.Node(50 package='nonexistent_package', node_executable='node', output='screen')51 self._assert_launch_errors([node_action])52 def test_launch_node(self):53 """Test launching a node."""54 self._assert_launch_no_errors([self._create_node()])55 def test_launch_node_with_remappings(self):56 """Test launching a node with remappings."""57 # Pass remapping rules to node in a variety of forms.58 # It is redundant to pass the same rule, but the goal is to test different parameter types.59 os.environ['TOPIC_NAME'] = 'chatter'60 topic_prefix = 'new_'61 node_action = self._create_node(62 remappings=[63 ('chatter', 'new_chatter'),64 (EnvironmentVariable(name='TOPIC_NAME'), [65 topic_prefix, EnvironmentVariable(name='TOPIC_NAME')])66 ],67 )68 self._assert_launch_no_errors([node_action])69 # Check the expanded parameters.70 expanded_remappings = node_action._Node__expanded_remappings71 assert len(expanded_remappings) == 272 for i in range(2):73 assert expanded_remappings[i] == ('chatter', 'new_chatter')74 def test_create_node_with_invalid_remappings(self):75 """Test creating a node with invalid remappings."""76 self._assert_type_error_creating_node(77 remappings={'chatter': 'new_chatter'}, # Not a list.78 )79 self._assert_type_error_creating_node(80 remappings=[{'chatter': 'new_chatter'}], # List with elements not tuple.81 )82 def test_launch_node_with_parameter_files(self):83 """Test launching a node with parameters specified in yaml files."""84 parameters_file_dir = pathlib.Path(__file__).resolve().parent85 parameters_file_path = parameters_file_dir / 'example_parameters.yaml'86 # Pass parameter files to node in a variety of forms.87 # It is redundant to pass the same file, but the goal is to test different parameter types.88 os.environ['FILE_PATH'] = str(parameters_file_dir)89 node_action = self._create_node(90 parameters=[91 parameters_file_path,92 str(parameters_file_path),93 [EnvironmentVariable(name='FILE_PATH'), os.sep, 'example_parameters.yaml'],94 ],95 )96 self._assert_launch_no_errors([node_action])97 # Check the expanded parameters.98 expanded_parameter_files = node_action._Node__expanded_parameter_files99 assert len(expanded_parameter_files) == 3100 for i in range(3):101 assert expanded_parameter_files[i] == str(parameters_file_path)102 def test_launch_node_with_parameter_dict(self):103 """Test launching a node with parameters specified in a dictionary."""104 os.environ['PARAM1_VALUE'] = 'param1_value'105 os.environ['PARAM2'] = 'param2'106 node_action = self._create_node(107 parameters=[{108 'param1': EnvironmentVariable(name='PARAM1_VALUE'),109 EnvironmentVariable(name='PARAM2'): (EnvironmentVariable(name='PARAM2'), '_value'),110 'param_group1': {111 'list_params': [1.2, 3.4],112 'param_group2': {113 (EnvironmentVariable('PARAM2'), '_values'): ['param2_value'],114 }115 }116 }],117 )118 self._assert_launch_no_errors([node_action])119 # Check the expanded parameters (will be written to a file).120 expanded_parameter_files = node_action._Node__expanded_parameter_files121 assert len(expanded_parameter_files) == 1122 with open(expanded_parameter_files[0], 'r') as h:123 expanded_parameters_dict = yaml.load(h)124 assert expanded_parameters_dict == {125 '/my_ns': {126 'my_node': {127 'ros__parameters': {128 'param1': 'param1_value',129 'param2': 'param2_value',130 'param_group1': {131 'list_params': [1.2, 3.4],132 'param_group2': {133 'param2_values': ['param2_value'],134 }135 }136 }137 }138 }139 }140 def test_create_node_with_invalid_parameters(self):141 """Test launching a node with invalid parameters."""142 self._assert_type_error_creating_node(parameters=[5.0]) # Invalid list values.143 self._assert_type_error_creating_node(parameters={'a': 5}) # Valid dict, not in a list.144 parameter_file_path = pathlib.Path(__file__).resolve().parent / 'example_parameters.yaml'145 self._assert_type_error_creating_node(146 parameters=str(parameter_file_path)) # Valid path, but not in a list.147 # If a parameter dictionary is specified, the node name must be also.148 with self.assertRaisesRegex(RuntimeError, 'node name must also be specified'):149 launch_ros.actions.Node(150 package='demo_nodes_py', node_executable='talker_qos', output='screen',151 arguments=['--number_of_cycles', '1'],152 parameters=[{'my_param': 'value'}],153 )154 def test_launch_node_with_invalid_parameter_dicts(self):155 """Test launching a node with invalid parameter dicts."""156 # Substitutions aren't expanded until the node action is executed, at which time a type157 # error should be raised and cause the launch to fail.158 # For each type of invalid parameter, check that they are detected at both the top-level159 # and at a nested level in the dictionary.160 # Key must be a string/Substitution evaluating to a string.161 self._assert_launch_errors(actions=[162 self._create_node(parameters=[{5: 'asdf'}])163 ])164 self._assert_launch_errors(actions=[165 self._create_node(parameters=[{166 'param_group': {167 'param_subgroup': {168 5: 'asdf',169 },170 },171 }])172 ])173 # Nested lists are not supported.174 self._assert_launch_errors(actions=[175 self._create_node(parameters=[{'param': [1, 2, [3, 4]]}])176 ])177 self._assert_launch_errors(actions=[178 self._create_node(parameters=[{179 'param_group': {180 'param_subgroup': {181 'param': [1, 2, [3, 4]],182 },183 },184 }])185 ])186 # Tuples are only supported for Substitutions.187 self._assert_launch_errors(actions=[188 self._create_node(parameters=[{'param': (1, 2)}])189 ])190 self._assert_launch_errors(actions=[191 self._create_node(parameters=[{192 'param_group': {193 'param_subgroup': {194 'param': (1, 2),195 },196 },197 }])198 ])199 # Other types are not supported.200 self._assert_launch_errors(actions=[201 self._create_node(parameters=[{'param': {1, 2}}])202 ])203 self._assert_launch_errors(actions=[204 self._create_node(parameters=[{205 'param_group': {206 'param_subgroup': {207 'param': {1, 2},208 },209 },210 }])211 ])212 self._assert_launch_errors(actions=[213 self._create_node(parameters=[{'param': self}])214 ])215 self._assert_launch_errors(actions=[216 self._create_node(parameters=[{217 'param_group': {218 'param_subgroup': {219 'param': self,220 },221 },222 }])...

Full Screen

Full Screen

meta_dao_read_tests.py

Source:meta_dao_read_tests.py Github

copy

Full Screen

...55 assert top_nodes != None56 assert len(top_nodes) == 357 print top_nodes58 """ Helpers """59 def _create_node(self, name, orig_id, parent_node=None):60 node = self._dao.create_node(name, orig_id)61 if parent_node:62 if isinstance(parent_node, list):63 for pn in parent_node:64 self._dao.create_rel_is(node, pn)65 print "%s(%s) --> %s(%s)" %(node.name, node._id, pn.name, pn._id)66 else:67 self._dao.create_rel_is(node, parent_node)68 print "%s(%s) --> %s(%s)" %(node.name, node._id, parent_node.name, parent_node._id)69 else:70 print "%s(%s)" %(node.name, node._id)71 72 return node 73 74 def _create_test_graph(self):75 a1 = self._create_node("a1", 101)76 a11 = self._create_node("a11", 1011, a1)77 a111 = self._create_node("a111", 10111, a11)78 a112 = self._create_node("a112", 10112, a11)79 a113 = self._create_node("a113", 10113, a11)80 a12 = self._create_node("a12", 1012, a1)81 a121 = self._create_node("a121", 10121, a12)82 a13 = self._create_node("a13", 1013, a1)83 b1 = self._create_node("b1", 201)84 b11 = self._create_node("b11", 2011, b1)85 b111 = self._create_node("b111", 20111, b11)86 b12 = self._create_node("b12", 2012, b1)87 88 c1 = self._create_node("c1", 301)89 c11 = self._create_node("c11", 3011, c1)90 c111 = self._create_node("c111", 30111, [c11, a13, b111])91 ...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run lisa automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful