test_xosc_load.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/usr/bin/env python
  2. # Copyright (c) 2021 Intel Corporation
  3. #
  4. # This work is licensed under the terms of the MIT license.
  5. # For a copy, see <https://opensource.org/licenses/MIT>.
  6. """
  7. This module provides some basic unit tests for the OpenSCENARIO feature of ScenarioRunner
  8. """
  9. from unittest import TestCase
  10. import glob
  11. import carla
  12. from srunner.scenarioconfigs.openscenario_configuration import OpenScenarioConfiguration
  13. from srunner.scenariomanager.carla_data_provider import CarlaDataProvider
  14. from srunner.scenarios.open_scenario import OpenScenario
  15. class TestLoadingXOSC(TestCase):
  16. """
  17. Test class to load OpenSCENARIO files and test for exceptions
  18. """
  19. def test_all_xosc(self):
  20. """
  21. Load all examples OpenSCENARIO files
  22. """
  23. all_test_files = glob.glob('**/srunner/examples/*.xosc', recursive=True)
  24. for filename in all_test_files:
  25. client = carla.Client()
  26. config = OpenScenarioConfiguration(filename, client, {})
  27. self.assertTrue(config is not None)
  28. CarlaDataProvider.set_client(client)
  29. ego_vehicles = []
  30. for vehicle in config.ego_vehicles:
  31. ego_vehicles.append(CarlaDataProvider.request_new_actor(vehicle.model,
  32. vehicle.transform,
  33. vehicle.rolename,
  34. color=vehicle.color,
  35. actor_category=vehicle.category))
  36. scenario = OpenScenario(world=client.get_world(),
  37. ego_vehicles=ego_vehicles,
  38. config=config,
  39. config_file=filename,
  40. timeout=100000)
  41. self.assertTrue(scenario is not None)
  42. CarlaDataProvider.cleanup()