Skip to content

Commit ce68102

Browse files
committed
tests: use editoast pathfinding endpoints
1 parent 154c913 commit ce68102

File tree

3 files changed

+30
-11
lines changed

3 files changed

+30
-11
lines changed

tests/conftest.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def west_to_south_east_path(small_infra: Infra, fast_rolling_stock: int) -> Trai
113113
"""west_to_south_east_path screenshot in `tests/README.md`"""
114114
requests.post(f"{EDITOAST_URL}infra/{small_infra.id}/load").raise_for_status()
115115
response = requests.post(
116-
f"{API_URL}pathfinding/",
116+
f"{EDITOAST_URL}pathfinding/",
117117
json={
118118
"infra": small_infra.id,
119119
"steps": [

tests/tests/test_pathfinding.py

+26-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from itertools import chain
2+
from typing import Any, Iterable
23

34
import pytest
45

@@ -130,16 +131,32 @@
130131
)
131132

132133

134+
def assert_line_strings_are_equals(geometry, expected_geometry):
135+
assert geometry["type"] == expected_geometry["type"]
136+
assert list(chain.from_iterable(geometry["coordinates"])) == pytest.approx(
137+
list(chain.from_iterable(expected_geometry["coordinates"]))
138+
)
139+
140+
141+
def assert_points_are_equals(geometry, expected_geometry):
142+
assert geometry["type"] == expected_geometry["type"]
143+
assert geometry["coordinates"] == pytest.approx(expected_geometry["coordinates"])
144+
145+
146+
def assert_steps_are_equals(steps: Iterable[Any], expected_steps: Iterable[Any]):
147+
assert len(steps) == len(expected_steps)
148+
149+
for i in range(len(steps)):
150+
assert_points_are_equals(steps[i].pop("sch"), expected_steps[i].pop("sch"))
151+
assert_points_are_equals(steps[i].pop("geo"), expected_steps[i].pop("geo"))
152+
assert steps[i] == expected_steps[i]
153+
154+
133155
def test_west_to_south_east_path(west_to_south_east_path: Path):
134156
assert west_to_south_east_path.owner == _EXPECTED_WEST_TO_SOUTH_EAST_PATH.owner
135157
assert west_to_south_east_path.slopes == pytest.approx(_EXPECTED_WEST_TO_SOUTH_EAST_PATH.slopes)
136158
assert west_to_south_east_path.curves == pytest.approx(_EXPECTED_WEST_TO_SOUTH_EAST_PATH.curves)
137-
assert west_to_south_east_path.steps == _EXPECTED_WEST_TO_SOUTH_EAST_PATH.steps
138-
assert west_to_south_east_path.geographic["type"] == _EXPECTED_WEST_TO_SOUTH_EAST_PATH.geographic["type"]
139-
assert list(chain.from_iterable(west_to_south_east_path.geographic["coordinates"])) == pytest.approx(
140-
list(chain.from_iterable(_EXPECTED_WEST_TO_SOUTH_EAST_PATH.geographic["coordinates"]))
141-
)
142-
assert west_to_south_east_path.schematic["type"] == _EXPECTED_WEST_TO_SOUTH_EAST_PATH.schematic["type"]
143-
assert list(chain.from_iterable(west_to_south_east_path.schematic["coordinates"])) == pytest.approx(
144-
list(chain.from_iterable(_EXPECTED_WEST_TO_SOUTH_EAST_PATH.schematic["coordinates"]))
145-
)
159+
assert_steps_are_equals(west_to_south_east_path.steps, _EXPECTED_WEST_TO_SOUTH_EAST_PATH.steps)
160+
161+
assert_line_strings_are_equals(west_to_south_east_path.geographic, _EXPECTED_WEST_TO_SOUTH_EAST_PATH.geographic)
162+
assert_line_strings_are_equals(west_to_south_east_path.schematic, _EXPECTED_WEST_TO_SOUTH_EAST_PATH.schematic)

tests/tests/test_regressions.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ def _reproduce_test(path_to_json: Path, scenario: Scenario, rolling_stock_id: in
5959

6060
assert "small_infra" == fuzzer_output["infra_name"]
6161
timetable = scenario.timetable
62-
path_id = _pathfinding_with_payload(API_URL, fuzzer_output["path_payload"], scenario.infra, stop_after_pathfinding)
62+
path_id = _pathfinding_with_payload(
63+
EDITOAST_URL, fuzzer_output["path_payload"], scenario.infra, stop_after_pathfinding
64+
)
6365
if stop_after_pathfinding:
6466
return
6567

0 commit comments

Comments
 (0)