1
- from dataclasses import dataclass
2
- from enum import Enum
3
- from typing import Dict , Tuple , Iterable , List , Set
4
1
import json
5
2
import random
6
3
import time
7
4
from collections import defaultdict
5
+ from dataclasses import dataclass
6
+ from enum import Enum
7
+ from pathlib import Path
8
+ from typing import Dict , Iterable , List , Set , Tuple
8
9
9
10
import requests
10
- from pathlib import Path
11
11
12
12
URL = "http://127.0.0.1:8000/"
13
13
TIMEOUT = 15
@@ -25,7 +25,7 @@ class FailedTest(Exception):
25
25
26
26
27
27
class ErrorType (str , Enum ):
28
- PATHFINDING = "PATHFINDING" ,
28
+ PATHFINDING = "PATHFINDING"
29
29
SCHEDULE = "SCHEDULE"
30
30
RESULT = "RESULT"
31
31
@@ -38,14 +38,16 @@ class InfraGraph:
38
38
39
39
40
40
def make_error (error_type : ErrorType , code : int , error : str , infra_name : str , path_payload : Dict , ** kwargs ):
41
- raise FailedTest ({
42
- "error_type" : error_type .value ,
43
- "code" : code ,
44
- "error" : error ,
45
- "infra_name" : infra_name ,
46
- "path_payload" : path_payload ,
47
- ** kwargs ,
48
- })
41
+ raise FailedTest (
42
+ {
43
+ "error_type" : error_type .value ,
44
+ "code" : code ,
45
+ "error" : error ,
46
+ "infra_name" : infra_name ,
47
+ "path_payload" : path_payload ,
48
+ ** kwargs ,
49
+ }
50
+ )
49
51
50
52
51
53
def run_test (infra : InfraGraph , base_url : str , infra_id : int , infra_name : str ):
@@ -70,25 +72,37 @@ def run_test(infra: InfraGraph, base_url: str, infra_id: int, infra_name: str):
70
72
if r .status_code // 100 == 4 :
71
73
print ("ignore: invalid user input" )
72
74
return
73
- make_error (ErrorType .SCHEDULE , r .status_code , r .content .decode ("utf-8" ), infra_name , path_payload ,
74
- schedule_payload = schedule_payload )
75
+ make_error (
76
+ ErrorType .SCHEDULE ,
77
+ r .status_code ,
78
+ r .content .decode ("utf-8" ),
79
+ infra_name ,
80
+ path_payload ,
81
+ schedule_payload = schedule_payload ,
82
+ )
75
83
76
84
schedule_id = r .json ()["ids" ][0 ]
77
85
r = requests .get (f"{ base_url } train_schedule/{ schedule_id } /result/" , timeout = TIMEOUT )
78
86
if r .status_code // 100 != 2 :
79
- make_error (ErrorType .RESULT , r .status_code , r .content .decode ("utf-8" ), infra_name , path_payload ,
80
- schedule_payload = schedule_payload , schedule_id = schedule_id )
87
+ make_error (
88
+ ErrorType .RESULT ,
89
+ r .status_code ,
90
+ r .content .decode ("utf-8" ),
91
+ infra_name ,
92
+ path_payload ,
93
+ schedule_payload = schedule_payload ,
94
+ schedule_id = schedule_id ,
95
+ )
96
+
97
+ payload = r .json ()
98
+ assert "line_code" in payload ["base" ]["stops" ][0 ]
99
+ assert "track_number" in payload ["base" ]["stops" ][0 ]
81
100
82
101
print ("test PASSED" )
83
102
84
103
85
104
def run (
86
- base_url : str ,
87
- infra_id : int ,
88
- n_test : int = 1000 ,
89
- log_folder : Path = None ,
90
- infra_name : str = None ,
91
- seed : int = 0
105
+ base_url : str , infra_id : int , n_test : int = 1000 , log_folder : Path = None , infra_name : str = None , seed : int = 0
92
106
):
93
107
"""
94
108
Runs every test
@@ -317,10 +331,10 @@ def make_random_ranges(path_length: float) -> List[Dict]:
317
331
transitions .sort ()
318
332
for begin , end in zip (transitions [:1 ], transitions [1 :]):
319
333
yield {
320
- "begin_position" : begin ,
321
- "end_position" : end ,
322
- "value" : make_random_allowance_value (end - begin ),
323
- }
334
+ "begin_position" : begin ,
335
+ "end_position" : end ,
336
+ "value" : make_random_allowance_value (end - begin ),
337
+ }
324
338
325
339
326
340
def make_random_allowances (path_length : float ) -> List [Dict ]:
0 commit comments