def lookup_station_code( duids: List[str], station_name: str, station_code_map: dict ) -> Optional[str]: station_code = None station_name = station_name.strip() for facility_duid in duids: if facility_duid in station_code_map: station_code = station_code_map[facility_duid] continue if not station_code: station_code = station_name_code_map(station_name) if not station_code: station_code = station_code_from_duids(duids) if not station_code: print( "Coult not get a station code for {}: {}".format( station_name, ",".join(duids) ) ) return station_code
def lookup_station_code(duids: List[str], station_name: str, station_code_map: dict) -> Optional[str]: station_code = None station_name = station_name.strip() for facility_duid in duids: if facility_duid in station_code_map: station_code = station_code_map[facility_duid] continue if not station_code: station_code = station_name_code_map(station_name) if not station_code: station_code = station_code_from_duids(duids) logger.info( "Had to generate station code from duids: {} from {}".format( station_code, ",".join(duids))) return station_code
def test_station_code_from_duid(subject: List[str], expected: str) -> None: return_val = station_code_from_duids(subject) assert expected == return_val, "Got correct response"
def test_none(self): subject = station_code_from_duids(None) assert subject == None, "None is none"
def test_ferguson_wf(self): subject = station_code_from_duids(["FNWF1"]) assert subject == "FNWF", "Trims and strips numbers"
def test_osbag_two(self): subject = station_code_from_duids(["OSBAG", "OSBAG"]) assert subject == "OSBAG", "OSBAG convertts to OSBAG"
def test_barron(self): subject = station_code_from_duids(["BARRON1", "BARRON2"]) assert subject == "BARRON", "Barron convertts to BARRON"
def test_empty(self): subject = station_code_from_duids([]) assert subject == None, "None is none"
def test_not_list(self): subject = station_code_from_duids("") assert subject == None, "None is none"