Compare commits

...

2 Commits

Author SHA1 Message Date
Profitroll
e09e8f29fb Changed test function argument type 2022-10-08 12:27:13 +02:00
Profitroll
d23d9a005d Some errors ignored 2022-10-08 12:26:48 +02:00
2 changed files with 66 additions and 66 deletions

View File

@ -57,7 +57,7 @@ class Client():
# Look for stops using all possible methods
stop_by_coords client.stop_by_coords(50.131140, 8.733362, radius=300, max_number=3)
stop_by_id = client.stop_by_id("A=1@O=Offenbach (Main)-Zentrum Marktplatz\/Frankf. Straße@X=8764456@Y=50105181@U=80@L=3002510@")
stop_by_id = client.stop_by_id("A=1@O=Offenbach (Main)-Zentrum Marktplatz/Frankf. Straße@X=8764456@Y=50105181@U=80@L=3002510@")
stop_by_name = client.stop_by_name("Groß Karben", max_number=3)
# Find a trip and reconstruct it
@ -110,10 +110,10 @@ class Client():
accessId=self.access_id,
id=id,
extId=id_ext,
direction=direction,
direction=direction, # type: ignore
date=date,
time=time,
duration=duration,
duration=duration, # type: ignore
maxJourneys=journeys_max,
operators=operators,
lines=lines,
@ -166,10 +166,10 @@ class Client():
accessId=self.access_id,
id=id,
extId=id_ext,
direction=direction,
direction=direction, # type: ignore
date=date,
time=time,
duration=duration,
duration=duration, # type: ignore
maxJourneys=journeys_max,
operators=operators,
lines=lines,
@ -182,28 +182,28 @@ class Client():
return BoardDeparture(board_raw, self)
def him_search(self,
date_begin: Union[str, datetime] = None,
date_end: Union[str, datetime] = None,
time_begin: Union[str, datetime] = None,
time_end: Union[str, datetime] = None,
weekdays: Union[str, OrderedDict[str, bool]] = None,
ids: list = None,
operators: list = None,
categories: list = None,
channels: list = None,
companies: list = None,
lines: list = None,
line_ids: list = None,
stations: Union[list, List[Stop]] = None,
station_from: Union[str, Stop] = None,
station_to: Union[str, Stop] = None,
both_ways: bool = None,
train_names: list = None,
search_mode: Literal[SearchMode.MATCH, SearchMode.NOMATCH, SearchMode.TFMATCH] = None,
affected_journey_mode: Literal[AffectedJourneyMode.ALL, AffectedJourneyMode.OFF] = None,
affected_journey_stop_mode: Literal[AffectedJourneyStopMode.ALL, AffectedJourneyStopMode.IMP, AffectedJourneyStopMode.OFF] = None,
priority_min: int = None,
priority_max: int = None
date_begin: Union[str, datetime] = None, # type: ignore
date_end: Union[str, datetime] = None, # type: ignore
time_begin: Union[str, datetime] = None, # type: ignore
time_end: Union[str, datetime] = None, # type: ignore
weekdays: Union[str, OrderedDict[str, bool]] = None, # type: ignore
ids: list = None, # type: ignore
operators: list = None, # type: ignore
categories: list = None, # type: ignore
channels: list = None, # type: ignore
companies: list = None, # type: ignore
lines: list = None, # type: ignore
line_ids: list = None, # type: ignore
stations: Union[list, List[Stop]] = None, # type: ignore
station_from: Union[str, Stop] = None, # type: ignore
station_to: Union[str, Stop] = None, # type: ignore
both_ways: bool = None, # type: ignore
train_names: list = None, # type: ignore
search_mode: Literal[SearchMode.MATCH, SearchMode.NOMATCH, SearchMode.TFMATCH] = None, # type: ignore
affected_journey_mode: Literal[AffectedJourneyMode.ALL, AffectedJourneyMode.OFF] = None, # type: ignore
affected_journey_stop_mode: Literal[AffectedJourneyStopMode.ALL, AffectedJourneyStopMode.IMP, AffectedJourneyStopMode.OFF] = None, # type: ignore
priority_min: int = None, # type: ignore
priority_max: int = None # type: ignore
) -> List[Message]:
"""The him_search method will deliver a list of HIM messages if matched by the given criteria as
well as affected products if any.
@ -239,10 +239,10 @@ class Client():
"""
if isinstance(station_from, Stop):
station_from = station_from.ext_id
station_from = station_from.ext_id # type: ignore
if isinstance(station_to, Stop):
station_to = station_to.ext_id
station_to = station_to.ext_id # type: ignore
if stations != None:
new_stations = []
@ -254,17 +254,17 @@ class Client():
stations = new_stations
if search_mode == None:
search_mode = None
search_mode = None # type: ignore
else:
search_mode = search_mode.code
if affected_journey_mode == None:
affected_journey_mode = None
affected_journey_mode = None # type: ignore
else:
affected_journey_mode = affected_journey_mode.code
if affected_journey_stop_mode == None:
affected_journey_stop_mode = None
affected_journey_stop_mode = None # type: ignore
else:
affected_journey_stop_mode = affected_journey_stop_mode.code
@ -284,13 +284,13 @@ class Client():
lines=lines,
lineids=line_ids,
stations=stations,
fromstation=station_from,
tostation=station_to,
fromstation=station_from, # type: ignore
tostation=station_to, # type: ignore
bothways=both_ways,
trainnames=train_names,
searchmode=search_mode,
affectedJourneyMode=affected_journey_mode,
affectedJourneyStopMode=affected_journey_stop_mode,
searchmode=search_mode, # type: ignore
affectedJourneyMode=affected_journey_mode, # type: ignore
affectedJourneyStopMode=affected_journey_stop_mode, # type: ignore
maxprio=priority_max,
minprio=priority_min
)
@ -332,7 +332,7 @@ class Client():
"""
if real_time_mode == None:
real_time_mode = None
real_time_mode = None # type: ignore
else:
real_time_mode = real_time_mode.code
@ -340,11 +340,11 @@ class Client():
accessId=self.access_id,
id=id,
date=date,
rtMode=real_time_mode,
rtMode=real_time_mode, # type: ignore
fromId=from_id,
fromIdx=from_index,
fromIdx=from_index, # type: ignore
toId=to_id,
toIdx=to_index
toIdx=to_index # type: ignore
)
find_exception(journey_raw)
@ -380,7 +380,7 @@ class Client():
"""
if selection_mode == None:
selection_mode = None
selection_mode = None # type: ignore
else:
selection_mode = selection_mode.code
@ -393,7 +393,7 @@ class Client():
radius=radius,
maxNo=max_number,
stopType=stop_type.code,
locationSelectionMode=selection_mode
locationSelectionMode=selection_mode # type: ignore
)
find_exception(stops_raw)
@ -478,7 +478,7 @@ class Client():
"""
if selection_mode == None:
selection_mode = None
selection_mode = None # type: ignore
else:
selection_mode = selection_mode.code
@ -489,7 +489,7 @@ class Client():
lang=lang.code,
maxNo=max_number,
stopType=stop_type.code,
locationSelectionMode=selection_mode,
locationSelectionMode=selection_mode, # type: ignore
coordLat=coord_lat,
coordLong=coord_lon,
radius=radius,
@ -623,7 +623,7 @@ class Client():
"""
if real_time_mode == None:
real_time_mode = None
real_time_mode = None # type: ignore
else:
real_time_mode = real_time_mode.code
@ -682,7 +682,7 @@ class Client():
showPassingPoints=passing_points,
rtMode=real_time_mode,
rtMode=real_time_mode, # type: ignore
includeEarlier=include_earlier,
withICTAlternatives=ict_alternatives,
@ -699,18 +699,18 @@ class Client():
return trips
def trip_recon(self,
context: Union[str, Journey],
date: Union[str, datetime] = None,
match_real_time: bool = None,
enable_replacements: bool = None,
arrival_dev_lower: int = None,
arrival_dev_upper: int = None,
departure_dev_lower: int = None,
departure_dev_upper: int = None,
passlist: bool = None,
context: Union[str, Trip],
date: Union[str, datetime] = None, # type: ignore
match_real_time: bool = None, # type: ignore
enable_replacements: bool = None, # type: ignore
arrival_dev_lower: int = None, # type: ignore
arrival_dev_upper: int = None, # type: ignore
departure_dev_lower: int = None, # type: ignore
departure_dev_upper: int = None, # type: ignore
passlist: bool = None, # type: ignore
passing_points: bool = False,
real_time_mode: Literal[RealTimeMode.FULL, RealTimeMode.INFOS, RealTimeMode.OFF, RealTimeMode.REALTIME, RealTimeMode.SERVER_DEFAULT] = None,
tariff: bool = None,
real_time_mode: Literal[RealTimeMode.FULL, RealTimeMode.INFOS, RealTimeMode.OFF, RealTimeMode.REALTIME, RealTimeMode.SERVER_DEFAULT] = None, # type: ignore
tariff: bool = None, # type: ignore
messages: bool = False
) -> List[Trip]:
"""Reconstructing a trip can be achieved using the reconstruction context provided by any trip result in the
@ -739,7 +739,7 @@ class Client():
"""
if real_time_mode == None:
real_time_mode = None
real_time_mode = None # type: ignore
else:
real_time_mode = real_time_mode.code
@ -749,7 +749,7 @@ class Client():
trips = []
trips_raw = raw_trip_recon(
accessId=self.access_id,
ctx=context,
ctx=context, # type: ignore
date=date,
matchRtType=match_real_time,
enableReplacements=enable_replacements,
@ -759,7 +759,7 @@ class Client():
depU=departure_dev_upper,
passlist=passlist,
showPassingPoints=passing_points,
rtMode=real_time_mode,
rtMode=real_time_mode, # type: ignore
tariff=tariff,
trafficMessages=messages,
)

10
test.py
View File

@ -1,6 +1,6 @@
from datetime import datetime, timedelta
from os import makedirs
from typing import Union
from typing import Any, Union
from ujson import loads, dumps, JSONDecodeError
from test_colors import *
@ -24,7 +24,7 @@ except FileNotFoundError:
print("To skip entering your key every time create file 'test_key.json' with your apikey as a value for 'key' dict key.", flush=True)
def test(name: str, data: Union[str, dict], raw: bool = False) -> None:
def test(name: str, data: Any, raw: bool = False) -> None:
makedirs("tests", exist_ok=True)
@ -56,7 +56,7 @@ def test(name: str, data: Union[str, dict], raw: bool = False) -> None:
file.close()
if data in ["", "\n"]:
print(f"{BBLACK}[{BRED}ER{BBLACK}] {RESET}Test of {YELLOW}{name} {RESET}did not go well. ErrorCode is {BRED}{data['errorCode']}{RESET}. Check {CYAN}tests/{name}.txt {RESET}for more information.", flush=True)
print(f"{BBLACK}[{BRED}ER{BBLACK}] {RESET}Test of {YELLOW}{name} {RESET}did not go well. ErrorCode is {BRED}{data['errorCode']}{RESET}. Check {CYAN}tests/{name}.txt {RESET}for more information.", flush=True) # type: ignore
else:
print(f"{BBLACK}[{BGREEN}OK{BBLACK}] {RESET}Test of {YELLOW}{name} {RESET}is not empty, so might be fine. Check {CYAN}tests/{name}.txt {RESET}for more information.", flush=True)
@ -69,14 +69,14 @@ test("raw_journey_detail", pyrmv.raw.journey_detail(key, id="2|#VN#1#ST#16649065
test("raw_stop_by_name", pyrmv.raw.stop_by_name(key, "Groß Karben", maxNo=3), raw=True)
test("raw_stop_by_coords", pyrmv.raw.stop_by_coords(key, 50.131140, 8.733362, radius=300, maxNo=3), raw=True)
test("raw_trip_find", pyrmv.raw.trip_find(key, originCoordLat="50.084659", originCoordLong="8.785948", destCoordLat=50.1233048, destCoordLong=8.6129742, trafficMessages=True, numF=3), raw=True)
test("raw_trip_recon", pyrmv.raw.trip_recon(key, ctx="¶HKI¶G@F$A=2@O=50.084659, 8.785948@X=8785948@Y=50084659@u=0@a=128@$A=1@O=Offenbach (Main)-Tempelsee Wilhelm-Schramm-Straße@L=3008012@a=128@$202210061243$202210061247$$$1$$$$$$§T$A=1@O=Offenbach (Main)-Tempelsee Wilhelm-Schramm-Straße@L=3008012@a=128@$A=1@O=Offenbach (Main)-Zentrum Marktplatz\/Frankf. Straße@L=3002510@a=128@$202210061247$202210061300$Bus 101 $$1$$$$$$§W$A=1@O=Offenbach (Main)-Zentrum Marktplatz\/Frankf. Straße@L=3002510@a=128@$A=1@O=Offenbach (Main)-Zentrum Marktplatz@L=3011265@a=128@$202210061300$202210061304$$$1$$$$$$§T$A=1@O=Offenbach (Main)-Zentrum Marktplatz@L=3011265@a=128@$A=1@O=Frankfurt (Main) Taunusanlage@L=3000011@a=128@$202210061306$202210061319$ S2$$1$$$$$$§T$A=1@O=Frankfurt (Main) Taunusanlage@L=3000011@a=128@$A=1@O=Frankfurt (Main) Rödelheim Bahnhof@L=3001217@a=128@$202210061322$202210061333$ S5$$1$$$$$$§G@F$A=1@O=Frankfurt (Main) Rödelheim Bahnhof@L=3001217@a=128@$A=2@O=50.123304, 8.612974@X=8612974@Y=50123304@u=0@a=128@$202210061333$202210061344$$$1$$$$$$¶GP¶ft@0@2000@120@1@100@1@@0@@@@@false@0@-1@0@-1@-1@$f@$f@$f@$f@$f@$§bt@0@2000@120@1@100@1@@0@@@@@false@0@-1@0@-1@-1@$f@$f@$f@$f@$f@$§tt@0@2000@120@1@100@1@@0@@@@@false@0@-1@0@-1@-1@$f@$f@$f@$f@$f@$§¶KRCC¶#VE#1#"), raw=True)
test("raw_trip_recon", pyrmv.raw.trip_recon(key, ctx="¶HKI¶G@F$A=2@O=50.084659, 8.785948@X=8785948@Y=50084659@u=0@a=128@$A=1@O=Offenbach (Main)-Tempelsee Wilhelm-Schramm-Straße@L=3008012@a=128@$202210061243$202210061247$$$1$$$$$$§T$A=1@O=Offenbach (Main)-Tempelsee Wilhelm-Schramm-Straße@L=3008012@a=128@$A=1@O=Offenbach (Main)-Zentrum Marktplatz/Frankf. Straße@L=3002510@a=128@$202210061247$202210061300$Bus 101 $$1$$$$$$§W$A=1@O=Offenbach (Main)-Zentrum Marktplatz/Frankf. Straße@L=3002510@a=128@$A=1@O=Offenbach (Main)-Zentrum Marktplatz@L=3011265@a=128@$202210061300$202210061304$$$1$$$$$$§T$A=1@O=Offenbach (Main)-Zentrum Marktplatz@L=3011265@a=128@$A=1@O=Frankfurt (Main) Taunusanlage@L=3000011@a=128@$202210061306$202210061319$ S2$$1$$$$$$§T$A=1@O=Frankfurt (Main) Taunusanlage@L=3000011@a=128@$A=1@O=Frankfurt (Main) Rödelheim Bahnhof@L=3001217@a=128@$202210061322$202210061333$ S5$$1$$$$$$§G@F$A=1@O=Frankfurt (Main) Rödelheim Bahnhof@L=3001217@a=128@$A=2@O=50.123304, 8.612974@X=8612974@Y=50123304@u=0@a=128@$202210061333$202210061344$$$1$$$$$$¶GP¶ft@0@2000@120@1@100@1@@0@@@@@false@0@-1@0@-1@-1@$f@$f@$f@$f@$f@$§bt@0@2000@120@1@100@1@@0@@@@@false@0@-1@0@-1@-1@$f@$f@$f@$f@$f@$§tt@0@2000@120@1@100@1@@0@@@@@false@0@-1@0@-1@-1@$f@$f@$f@$f@$f@$§¶KRCC¶#VE#1#"), raw=True)
test("board_arrival", client.board_arrival("A=1@O=Frankfurt (Main) Taunusanlage@X=8668765@Y=50113478@U=80@L=3000011@", journeys_max=5))
test("board_departure", client.board_departure("A=1@O=Frankfurt (Main) Taunusanlage@X=8668765@Y=50113478@U=80@L=3000011@", journeys_max=5))
test("him_search", client.him_search(date_end=datetime.now()+timedelta(days=10), priority_min=2, train_names=["S9"]))
test("journey_detail", client.journey_detail("2|#VN#1#ST#1664906549#PI#0#ZI#12709#TA#0#DA#61022#1S#3008007#1T#1248#LS#3008043#LT#1323#PU#80#RT#1#CA#1aE#ZE#101#ZB#Bus 101 #PC#6#FR#3008007#FT#1248#TO#3008043#TT#1323#", real_time_mode=pyrmv.enums.RealTimeMode.FULL))
test("stop_by_coords", client.stop_by_coords(50.131140, 8.733362, radius=300, max_number=3))
test("stop_by_id", client.stop_by_id("A=1@O=Offenbach (Main)-Zentrum Marktplatz\/Frankf. Straße@X=8764456@Y=50105181@U=80@L=3002510@"))
test("stop_by_id", client.stop_by_id("A=1@O=Offenbach (Main)-Zentrum Marktplatz/Frankf. Straße@X=8764456@Y=50105181@U=80@L=3002510@"))
test("stop_by_name", client.stop_by_name("Groß Karben", max_number=3))
test("trip_find", client.trip_find(origin_coord_lat="50.084659", origin_coord_lon="8.785948", destination_coord_lat=50.1233048, destination_coord_lon=8.6129742, messages=True))
test("trip_recon", client.trip_recon( client.trip_find(origin_coord_lat="50.084659", origin_coord_lon="8.785948", destination_coord_lat=50.1233048, destination_coord_lon=8.6129742, messages=True, trips_after_time=1)[0] ))