Skip to content

armgit / fli

Public Imported from GitHub
0

Google Flights MCP, CLI and Python Library

2.0 KB
Raw Blame
"""Tests guarding against alias regressions in the Airport / Airline enums.

``fli/models/airport.py`` and ``fli/models/airline.py`` are generated by
``scripts/generate_enums.py`` from CSV data. Enum *values* are human-readable
names, and Python's ``Enum`` silently turns a member with a value equal to an
earlier member's value into an *alias* of that earlier member — it never gets
its own ``__members__`` entry, and code that iterates ``for m in Airport``
(which skips aliases) can never see it. Concretely this used to mean
``Airport.OKA.name == "NAH"`` (searching for Okinawa, Japan actually resolved
to Naha, Indonesia) because both airports share the CSV name "Naha Airport".

These tests confirm the generator's disambiguation step (``_disambiguate_names``)
keeps every member distinct end to end, in the generated modules that ship.
"""

from __future__ import annotations

from fli.models import Airline, Airport


class TestAirportNoAliases:
    """Every Airport member must be independently addressable."""

    def test_no_aliases(self):
        assert len(Airport.__members__) == len(list(Airport))

    def test_tri_and_psc_are_distinct(self):
        assert Airport.TRI.name == "TRI"
        assert Airport.PSC.name == "PSC"
        assert Airport.TRI.value != Airport.PSC.value

    def test_oka_and_nah_are_distinct(self):
        assert Airport.OKA.name == "OKA"
        assert Airport.NAH.name == "NAH"
        assert Airport.OKA.value != Airport.NAH.value

    def test_ntl_and_ncl_are_distinct(self):
        assert Airport.NTL.name == "NTL"
        assert Airport.NCL.name == "NCL"
        assert Airport.NTL.value != Airport.NCL.value


class TestAirlineNoAliases:
    """Every Airline member must be independently addressable."""

    def test_no_aliases(self):
        assert len(Airline.__members__) == len(list(Airline))


def test_w4_is_wizz_air():
    """IATA reassigned W4 from the defunct LC Péru to Wizz Air (issue #127)."""
    from fli.models import Airline, display_name

    assert display_name(Airline.W4) == "Wizz Air"