def check_flight_sequence(routes: RouteDict, path: str, info_text): """If path represents a valid series of direct flight IATA codes, display in info_text the airport information for the airports. Otherwise, display that the path is invalid. """ if path.strip() == '': info_str = "Please enter a list of valid IATA codes." else: flight_sequence = path.split() is_valid = flight_functions.is_valid_flight_sequence( flight_sequence, routes) if not is_valid: info_str = 'Invalid flight sequence.' else: airport_info = get_airport_info_list(airport_data, flight_sequence) airports_strs = [ '{}) {}'.format(str(i), airport_info[i]) for i in range(len(airport_info)) ] info_str = ''.join(airports_strs) info_str = f'{path} is a valid flight sequence:\n{info_str}' info_text.delete("1.0", tk.END) info_text.insert('insert', info_str)
assert isinstance(result, str), \ TYPECHECK_FEEBACK.format('get_airport_info', 'str', type(result)) assert airports == fdata.TEST_AIRPORTS_DICT, \ 'get_airport_info should not mutate the parameter' # Type check flight_functions.is_direct_flight routes = copy.deepcopy(fdata.TEST_ROUTES_DICT_FOUR_CITIES) result = flight_functions.is_direct_flight('AA1', 'AA2', routes) assert isinstance(result, bool), \ TYPECHECK_FEEBACK.format('is_direct_flight', 'bool', type(result)) assert routes == fdata.TEST_ROUTES_DICT_FOUR_CITIES, \ 'is_direct_flight should not mutate the parameter' # Type check flight_functions.is_valid_flight_sequence routes = copy.deepcopy(fdata.TEST_ROUTES_DICT_FOUR_CITIES) result = flight_functions.is_valid_flight_sequence(['AA3', 'AA2', 'AA1'], routes) assert isinstance(result, bool), \ TYPECHECK_FEEBACK.format('is_valid_flight_sequence', 'bool', type(result)) assert routes == fdata.TEST_ROUTES_DICT_FOUR_CITIES, \ 'is_valid_flight_sequence should not mutate the parameter' # Type check flight_functions.count_outgoing_flights routes = copy.deepcopy(fdata.TEST_ROUTES_DICT_FOUR_CITIES) result = flight_functions.count_outgoing_flights('AA1', routes) assert isinstance(result, int), \ TYPECHECK_FEEBACK.format('count_outgoing_flights', 'int', type(result)) assert routes == fdata.TEST_ROUTES_DICT_FOUR_CITIES, \ 'count_outgoing_flights should not mutate the parameter' # Type check flight_functions.count_incoming_flights routes = copy.deepcopy(fdata.TEST_ROUTES_DICT_FOUR_CITIES)
def test_not_valid_flight(self): expected = False sequence = ['AA2', 'AA3', 'BB2'] actual = is_valid_flight_sequence(sequence, TEST_ROUTES_DICT_FOUR_CITIES) self.assertEqual(actual, expected)
def test_only_one_valid_flight(self): expected = True sequence = ['AA2'] actual = is_valid_flight_sequence(sequence, TEST_ROUTES_DICT_FOUR_CITIES) self.assertEqual(actual, expected)
def test_empty_list(self): expected = False sequence = [] actual = is_valid_flight_sequence(sequence, TEST_ROUTES_DICT_FOUR_CITIES) self.assertEqual(actual, expected)
def test_valid_direct_flight(self): expected = True sequence = ['AA1', 'AA2'] actual = is_valid_flight_sequence(sequence, SMALL_ROUTES_DICT) self.assertEqual(actual, expected)