|
15 | 15 | """Tests for the normalizing parameters utility.""" |
16 | 16 |
|
17 | 17 | import pathlib |
| 18 | +from typing import List |
18 | 19 |
|
19 | 20 | from launch import LaunchContext |
20 | 21 | from launch.substitutions import TextSubstitution |
21 | 22 |
|
| 23 | +from launch_ros.parameter_descriptions import ParameterValue |
22 | 24 | from launch_ros.utilities import evaluate_parameters |
23 | 25 | from launch_ros.utilities import normalize_parameters |
24 | 26 |
|
@@ -339,3 +341,58 @@ def test_unallowed_yaml_types_in_substitutions(): |
339 | 341 | norm = normalize_parameters(orig) |
340 | 342 | evaluate_parameters(LaunchContext(), norm) |
341 | 343 | assert 'Expected a non-empty sequence' in str(exc.value) |
| 344 | + |
| 345 | + with pytest.raises(TypeError) as exc: |
| 346 | + orig = [{'foo': 1, 'fiz': TextSubstitution(text='Text That : Cannot Be Parsed As : Yaml')}] |
| 347 | + norm = normalize_parameters(orig) |
| 348 | + evaluate_parameters(LaunchContext(), norm) |
| 349 | + assert 'Unable to parse' in str(exc.value) |
| 350 | + |
| 351 | + |
| 352 | +def test_unallowed_yaml_types_as_strings(): |
| 353 | + # All the tests from test_unallowed_yaml_types_in_substitutions |
| 354 | + # but coerced to the proper type with ParameterValue |
| 355 | + orig = [{'foo': 1, 'fiz': ParameterValue(TextSubstitution(text="{'asd': 3}"), value_type=str)}] |
| 356 | + norm = normalize_parameters(orig) |
| 357 | + expected = ({'foo': 1, 'fiz': "{'asd': 3}"},) |
| 358 | + assert evaluate_parameters(LaunchContext(), norm) == expected |
| 359 | + |
| 360 | + orig = [{'foo': 1, 'fiz': ParameterValue(TextSubstitution(text='[1, 2.0, 3]'), |
| 361 | + value_type=str)}] |
| 362 | + norm = normalize_parameters(orig) |
| 363 | + evaluate_parameters(LaunchContext(), norm) |
| 364 | + expected = ({'foo': 1, 'fiz': '[1, 2.0, 3]'},) |
| 365 | + assert evaluate_parameters(LaunchContext(), norm) == expected |
| 366 | + |
| 367 | + orig = [{'foo': 1, 'fiz': ParameterValue(TextSubstitution(text='[[2, 3], [2, 3], [2, 3]]'), |
| 368 | + value_type=str)}] |
| 369 | + norm = normalize_parameters(orig) |
| 370 | + evaluate_parameters(LaunchContext(), norm) |
| 371 | + expected = ({'foo': 1, 'fiz': '[[2, 3], [2, 3], [2, 3]]'},) |
| 372 | + assert evaluate_parameters(LaunchContext(), norm) == expected |
| 373 | + |
| 374 | + orig = [{'foo': 1, 'fiz': ParameterValue(TextSubstitution(text='[]'), value_type=str)}] |
| 375 | + norm = normalize_parameters(orig) |
| 376 | + evaluate_parameters(LaunchContext(), norm) |
| 377 | + expected = ({'foo': 1, 'fiz': '[]'},) |
| 378 | + assert evaluate_parameters(LaunchContext(), norm) == expected |
| 379 | + |
| 380 | + orig = [{ |
| 381 | + 'foo': 1, |
| 382 | + 'fiz': ParameterValue([ |
| 383 | + [TextSubstitution(text="['asd', 'bsd']")], |
| 384 | + [TextSubstitution(text="['asd', 'csd']")] |
| 385 | + ], value_type=List[str]) |
| 386 | + }] |
| 387 | + norm = normalize_parameters(orig) |
| 388 | + evaluate_parameters(LaunchContext(), norm) |
| 389 | + expected = ({'foo': 1, 'fiz': ["['asd', 'bsd']", "['asd', 'csd']"]},) |
| 390 | + assert evaluate_parameters(LaunchContext(), norm) == expected |
| 391 | + |
| 392 | + orig = [{'foo': 1, |
| 393 | + 'fiz': ParameterValue(TextSubstitution(text='Text That : Cannot Be Parsed As : Yaml'), |
| 394 | + value_type=str)}] |
| 395 | + norm = normalize_parameters(orig) |
| 396 | + evaluate_parameters(LaunchContext(), norm) |
| 397 | + expected = ({'foo': 1, 'fiz': 'Text That : Cannot Be Parsed As : Yaml'},) |
| 398 | + assert evaluate_parameters(LaunchContext(), norm) == expected |
0 commit comments