From cfbcf34c402b9935f85cd65d0a9a4158efb70bcb Mon Sep 17 00:00:00 2001 From: Thomas Lauf Date: Fri, 14 Jun 2024 16:01:20 +0200 Subject: [PATCH] Test holidays are only defined for valid regions Signed-off-by: Thomas Lauf --- ChangeLog | 1 + src/holidata/holidays/AT.py | 1 - src/holidata/holidays/BR.py | 2 -- src/holidata/holidays/CA.py | 1 - src/holidata/holidays/CH.py | 2 -- src/holidata/holidays/DE/__init__.py | 1 - src/holidata/holidays/US.py | 4 ---- tests/test_holidays.py | 16 ++++++++++++++++ 8 files changed, 17 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 58b3e3a..a4b2181 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ +- Test holidays are only defined for valid regions - Enable holidata to be calculated outside confirmed range 2024.8.0 diff --git a/src/holidata/holidays/AT.py b/src/holidata/holidays/AT.py index e47988c..7127f7c 100644 --- a/src/holidata/holidays/AT.py +++ b/src/holidata/holidays/AT.py @@ -7,7 +7,6 @@ class AT(Country): id = "AT" languages = ["de"] default_lang = "de" - regions = ["1", "2", "3", "4", "5", "6", "7", "8", "9"] easter_type = EASTER_WESTERN def __init__(self): diff --git a/src/holidata/holidays/BR.py b/src/holidata/holidays/BR.py index 552c400..c7a8433 100644 --- a/src/holidata/holidays/BR.py +++ b/src/holidata/holidays/BR.py @@ -42,8 +42,6 @@ class BR(Country): id = "BR" languages = ["pt"] default_lang = "pt" - regions = ["AC", "AL", "AP", "AM", "BA", "CE", "DF", "ES", "GO", "MA", "MT", "MS", "MG", "PA", "PB", "PR", "PE", - "PI", "RJ", "RN", "RS", "RO", "RR", "SC", "SP", "SE", "TO"] easter_type = EASTER_WESTERN def __init__(self): diff --git a/src/holidata/holidays/CA.py b/src/holidata/holidays/CA.py index fb21474..ef469a3 100644 --- a/src/holidata/holidays/CA.py +++ b/src/holidata/holidays/CA.py @@ -31,7 +31,6 @@ class CA(Country): id = "CA" languages = ["en", "fr"] - regions = ["AB", "BC", "MB", "NB", "NL", "NS", "ON", "PE", "QC", "SK", "NT", "NU", "YT"] easter_type = EASTER_WESTERN def __init__(self): diff --git a/src/holidata/holidays/CH.py b/src/holidata/holidays/CH.py index 9447146..98e609d 100644 --- a/src/holidata/holidays/CH.py +++ b/src/holidata/holidays/CH.py @@ -7,8 +7,6 @@ class CH(Country): id = "CH" languages = ["de"] default_lang = "de" - regions = ["AG", "AI", "AR", "BE", "BL", "BS", "FR", "GE", "GL", "GR", "JU", "LU", "NE", "NW", "OW", "SG", "SH", - "SO", "SZ", "TI", "TG", "UR", "VD", "VS", "ZG", "ZH"] easter_type = EASTER_WESTERN def __init__(self): diff --git a/src/holidata/holidays/DE/__init__.py b/src/holidata/holidays/DE/__init__.py index 7b0b06a..8159cd6 100644 --- a/src/holidata/holidays/DE/__init__.py +++ b/src/holidata/holidays/DE/__init__.py @@ -27,7 +27,6 @@ class DE(Country): id = "DE" languages = ["de"] default_lang = "de" - regions = ["BB", "BE", "BW", "BY", "HB", "HE", "HH", "MV", "NI", "NW", "RP", "SH", "SL", "SN", "ST", "TH"] easter_type = EASTER_WESTERN """ diff --git a/src/holidata/holidays/US.py b/src/holidata/holidays/US.py index 56d4b56..9cf145c 100644 --- a/src/holidata/holidays/US.py +++ b/src/holidata/holidays/US.py @@ -8,10 +8,6 @@ class US(Country): id = "US" languages = ["en", "es"] default_lang = "en" - regions = ["AL", "AK", "AZ", "AR", "CA", "CO", "CT", "DE", "FL", "GA", "HI", "ID", "IL", "IN", "IA", "KS", "KY", - "LA", "ME", "MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE", "NV", "NH", "NJ", "NM", "NY", "NC", "ND", - "OH", "OK", "OR", "PA", "RI", "SC", "SD", "TN", "TX", "UT", "VT", "VA", "WA", "WV", "WI", "WY", "DC", - "AS", "GU", "MP", "PR", "UM", "VI"] easter_type = EASTER_WESTERN def __init__(self): diff --git a/tests/test_holidays.py b/tests/test_holidays.py index 7c352fd..40780c9 100644 --- a/tests/test_holidays.py +++ b/tests/test_holidays.py @@ -38,6 +38,14 @@ def country(request): return request.param() +@pytest.fixture() +def regions(locale): + try: + return [region.id for region in locale.country.regions] + except AttributeError: + return [] + + def test_country_should_be_constructable(country): pass @@ -68,3 +76,11 @@ def test_holiday_flags_should_be_in_the_correct_order(holidays): match = re.search(r"^N?R?[FV]?$", f"{holiday.flags}") assert match is not None, f"Flags for holiday '{holiday.description}' ({holiday.date.strftime('%Y-%m-%d')}) in locale {holiday.locale} are not in the correct order. Flags '{holiday.flags}' should match 'N?R?[FV]?'" + + +def test_holiday_should_only_be_defined_for_valid_regions(holidays, regions): + if regions is None or regions == []: + return + + for holiday in holidays: + assert holiday.region == "" or holiday.region in regions, "Holiday '{}' ({}) in locale {} is defined for unknown region '{}'".format(holiday.description, holiday.date.strftime("%Y-%m-%d"), holiday.locale, holiday.region)