From 5bca51abd6818a057c40e8a45e0e8a10032aab9c Mon Sep 17 00:00:00 2001 From: Claas Date: Sat, 25 Nov 2023 01:00:10 +0100 Subject: [PATCH] test_read_files.py : Improved tests to be more robust to random changes of reading sequence on GitHub runners. --- tests/test_read_files.py | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/tests/test_read_files.py b/tests/test_read_files.py index bfc8e07..f4a174b 100644 --- a/tests/test_read_files.py +++ b/tests/test_read_files.py @@ -1,7 +1,7 @@ """Tests reading files.""" from pathlib import Path -from typing import List +from typing import List, Set, Union from trafficgen.read_files import ( read_encounter_settings_file, @@ -99,20 +99,20 @@ def test_read_situations_one_to_many_situations(situations_folder_test_05: Path) assert len(situations) == 3 # sourcery skip: no-loop-in-tests + num_situations_values_found: Set[Union[int, None]] = set() for situation in situations: assert situation.own_ship is not None assert situation.target_ship is None assert situation.encounter is not None assert len(situation.encounter) in {1, 2, 3} + num_situations_values_found.add(situation.num_situations) for encounter in situation.encounter: assert encounter.desired_encounter_type is not None assert encounter.beta is None assert encounter.relative_speed is None assert encounter.vector_time is None - assert situations[0].num_situations == 6 - assert situations[1].num_situations == 3 - assert situations[2].num_situations is None + assert num_situations_values_found == {6, 3, None} def test_read_situations_with_different_encounter_types(situations_folder_test_07: Path): @@ -123,28 +123,27 @@ def test_read_situations_with_different_encounter_types(situations_folder_test_0 assert len(situations) == 5 # sourcery skip: no-loop-in-tests + desired_encounter_types_found: Set[EncounterType] = set() for situation in situations: assert situation.own_ship is not None assert situation.target_ship is None assert situation.num_situations is None assert situation.encounter is not None assert len(situation.encounter) == 1 + desired_encounter_types_found.add(situation.encounter[0].desired_encounter_type) for encounter in situation.encounter: assert encounter.desired_encounter_type is not None assert encounter.beta is not None assert encounter.relative_speed is None assert encounter.vector_time is None - assert situations[0].encounter is not None - assert situations[0].encounter[0].desired_encounter_type is EncounterType.HEAD_ON - assert situations[1].encounter is not None - assert situations[1].encounter[0].desired_encounter_type is EncounterType.OVERTAKING_GIVE_WAY - assert situations[2].encounter is not None - assert situations[2].encounter[0].desired_encounter_type is EncounterType.OVERTAKING_STAND_ON - assert situations[3].encounter is not None - assert situations[3].encounter[0].desired_encounter_type is EncounterType.CROSSING_GIVE_WAY - assert situations[4].encounter is not None - assert situations[4].encounter[0].desired_encounter_type is EncounterType.CROSSING_STAND_ON + assert desired_encounter_types_found == { + EncounterType.HEAD_ON, + EncounterType.OVERTAKING_GIVE_WAY, + EncounterType.OVERTAKING_STAND_ON, + EncounterType.CROSSING_GIVE_WAY, + EncounterType.CROSSING_STAND_ON, + } def test_read_own_ship(own_ship_file: Path): @@ -166,17 +165,17 @@ def test_read_target_ships(target_ships_folder: Path): assert len(target_ships) == 3 # sourcery skip: no-loop-in-tests + ship_types_found: Set[ShipType] = set() for target_ship in target_ships: assert target_ship.static is not None + ship_types_found.add(target_ship.static.ship_type) assert target_ship.start_pose is None assert target_ship.waypoints is None - assert target_ships[0].static is not None - assert target_ships[0].static.ship_type is ShipType.PASSENGER_RORO - assert target_ships[1].static is not None - assert target_ships[1].static.ship_type is ShipType.GENERAL_CARGO - assert target_ships[2].static is not None - assert target_ships[2].static.ship_type is ShipType.PASSENGER_RORO + assert ship_types_found == { + ShipType.PASSENGER_RORO, + ShipType.GENERAL_CARGO, + } def test_read_encounter_settings_file(settings_file: Path):