Skip to content

Commit

Permalink
tests: add integration tests for arrival on stop signal
Browse files Browse the repository at this point in the history
  • Loading branch information
bougue-pe committed May 31, 2024
1 parent c38362e commit 9179115
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from tests.scenario import Scenario
from tests.services import EDITOAST_URL
from tests.test_e2e import FAST_ROLLING_STOCK_JSON_PATH, TestRollingStock
from tests.timetable_v2 import TimetableV2
from tests.utils.timetable import create_scenario, create_scenario_v2


Expand Down Expand Up @@ -238,3 +239,16 @@ def west_to_south_east_simulations(
},
)
yield response.json()


@pytest.fixture
def timetable_v2() -> TimetableV2:
timetable_payload = {}
r = requests.post(
f"{EDITOAST_URL}v2/timetable/",
json=timetable_payload,
)
if r.status_code // 100 != 2:
err = f"Error creating timetable {r.status_code}: {r.content}, payload={json.dumps(timetable_payload)}"
raise RuntimeError(err)
return TimetableV2(**r.json())
95 changes: 95 additions & 0 deletions tests/tests/test_timetable_v2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import pytest
import requests

from .infra import Infra
from .services import EDITOAST_URL
from .timetable_v2 import TimetableV2


def test_get_timetable_v2(
timetable_v2: TimetableV2,
):
timetable_id = timetable_v2.id

response = requests.get(f"{EDITOAST_URL}/v2/timetable/{timetable_id}/")
assert response.status_code == 200
json = response.json()
assert "id" in json
assert "train_ids" in json


@pytest.mark.parametrize(
["on_stop_signal", "expected_conflict_types"], [(False, {"Spacing", "Routing"}), (True, set())]
)
def test_conflicts(
small_infra: Infra,
timetable_v2: TimetableV2,
fast_rolling_stock: int,
on_stop_signal: bool,
expected_conflict_types: set[str],
):
requests.post(f"{EDITOAST_URL}infra/{small_infra.id}/load").raise_for_status()
train_schedule_payload = [
{
"comfort": "STANDARD",
"constraint_distribution": "STANDARD",
"initial_speed": 0,
"labels": [],
"options": {"use_electrical_profiles": False},
"path": [
{"id": "start", "track": "TC0", "offset": 185000},
{"id": "stop", "track": "TC0", "offset": 685000},
{"id": "end", "track": "TD0", "offset": 24820000},
],
"power_restrictions": [],
"rolling_stock_name": "fast_rolling_stock",
"schedule": [
{
"at": "start",
},
{"at": "stop", "on_stop_signal": on_stop_signal, "stop_for": "PT10M"},
{
"at": "end",
},
],
"speed_limit_tag": "MA100",
"start_time": "2024-05-22T08:00:00.000Z",
"train_name": "with_stop",
}
]
response = requests.post(
f"{EDITOAST_URL}/v2/timetable/{timetable_v2.id}/train_schedule", json=train_schedule_payload
)
train_schedule_payload = [
{
"comfort": "STANDARD",
"constraint_distribution": "STANDARD",
"initial_speed": 0,
"labels": [],
"options": {"use_electrical_profiles": False},
"path": [
{"id": "start", "track": "TC1", "offset": 185000},
{"id": "end", "track": "TD0", "offset": 24820000},
],
"power_restrictions": [],
"rolling_stock_name": "fast_rolling_stock",
"schedule": [
{
"at": "start",
},
{
"at": "end",
},
],
"speed_limit_tag": "MA100",
"start_time": "2024-05-22T08:00:01.000Z",
"train_name": "pass",
}
]
response = requests.post(
f"{EDITOAST_URL}/v2/timetable/{timetable_v2.id}/train_schedule", json=train_schedule_payload
)
response = requests.get(f"{EDITOAST_URL}/v2/timetable/{timetable_v2.id}/conflicts/?infra_id={small_infra.id}")
assert response.status_code == 200
actual_conflicts = {conflict["conflict_type"] for conflict in response.json()}
assert actual_conflicts == expected_conflict_types
9 changes: 9 additions & 0 deletions tests/tests/timetable_v2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from dataclasses import dataclass
from typing import Optional


@dataclass(frozen=True)
class TimetableV2:
id: int
electrical_profile_set_id: Optional[int] = None
train_ids: Optional[list[int]] = None

0 comments on commit 9179115

Please sign in to comment.