def test_country_flight_files(self):

        # process_airport_file
        airport1 = airports.Airport()
        with open(self.airports_file, "r", encoding="UTF-8") as f:
            reader = csv.reader(f)
            for row in reader:
                airport1.process_airport_row(row)

        # process_flight_file
        flight_per_country = country_flights.FlightPerCountry(
            airport1.airports_by_iata)
        with open(self.flights_file, "r", encoding="UTF-8") as f:
            reader = csv.reader(f)
            for row in reader:
                flight_per_country.process_flight(row)

        expected = {
            "Afghanistan": [14, 29],
            "Congo (Brazzaville)": [10, 34],
            "Denmark": [23, 286],
            "Guinea-Bissau": [0, 7],
            "Sweden": [167, 307],
            flight_per_country.unknown_country: [93, 636],
        }

        result = {}
        for country in expected:
            result[country] = flight_per_country.countries[country]

        self.assertEqual(result, expected)
예제 #2
0
 def test_airports_by_icao(self):
     airport1 = airports.Airport()
     for row in self.AirportData1:
         airport1.process_airport_row(row)
     icao1 = "ESSA"
     icao2 = "KLAX"
     expected = [
         (icao1, "Sweden"),
         (icao2, "United States"),
     ]
     result = [
         (icao1, airport1.airports_by_icao[icao1]),
         (icao2, airport1.airports_by_icao[icao2]),
     ]
     self.assertEqual(result, expected)
예제 #3
0
 def test_airports_by_iata(self):
     airport1 = airports.Airport()
     for row in self.AirportData1:
         airport1.process_airport_row(row)
     Iata1 = "ARN"
     Iata2 = "LAX"
     expected = [
         (Iata1, "Sweden"),
         (Iata2, "United States"),
     ]
     result = [
         (Iata1, airport1.airports_by_iata[Iata1]),
         (Iata2, airport1.airports_by_iata[Iata2]),
     ]
     self.assertEqual(result, expected)
예제 #4
0
 def test_airports_by_id(self):
     airport1 = airports.Airport()
     for row in self.AirportData1:
         airport1.process_airport_row(row)
     id1 = 737
     id2 = 3484
     expected = [
         (id1, "Sweden"),
         (id2, "United States"),
     ]
     result = [
         (id1, airport1.airports_by_id[id1]),
         (id2, airport1.airports_by_id[id2]),
     ]
     self.assertEqual(result, expected)
예제 #5
0
def test_airports_by_id():
    airport1 = airports.Airport()
    for row in AirportData1:
        airport1.process_airport_row(row)
    id1 = 737
    id2 = 3484
    expected = [
        (id1, "Sweden"),
        (id2, "United States"),
    ]
    result = [
        (id1, airport1.airports_by_id[id1]),
        (id2, airport1.airports_by_id[id2]),
    ]
    assert result == expected
예제 #6
0
def main():

    # go to src dir
    src_dir = os.path.dirname(os.path.realpath(__file__))

    # declare log file
    logging.basicConfig(
        filename=os.path.join(src_dir, "log", "flights.log"),
        format="%(levelname)s: %(asctime)s: %(process)d: %(filename)s:"
        " %(funcName)s: %(message)s",
        level=logging.INFO,
    )
    logging.info("Process started!")

    # output file
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--output_file",
        help="output file where results are stored",
        default="output_data/output.csv",
    )
    args = parser.parse_args()

    # input_data dir
    data_dir = os.path.join(src_dir, "..", "input_data")

    # process airports
    airports_file = os.path.join(data_dir, "airports.dat")
    airport1 = airports.Airport()
    process_airport_file(airports_file, airport1)

    # process flights
    flights_file = os.path.join(data_dir, "routes.dat")
    flight_per_country = country_flights.FlightPerCountry(
        airport1.airports_by_iata)
    process_flight_file(flights_file, flight_per_country)

    # save results
    results = flight_per_country.get_results_format1()
    save_data(args.output_file, results)

    msg = "Process completed!"
    logging.info(msg)
    print(msg)