Skip to content

Commit

Permalink
test_read_files.py : Improved tests to be more robust to random chang…
Browse files Browse the repository at this point in the history
…es of reading sequence on GitHub runners.
  • Loading branch information
ClaasRostock committed Nov 25, 2023
1 parent 23d96c3 commit 5bca51a
Showing 1 changed file with 19 additions and 20 deletions.
39 changes: 19 additions & 20 deletions tests/test_read_files.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand Down

0 comments on commit 5bca51a

Please sign in to comment.