Skip to content

Commit

Permalink
Test holidays are only defined for valid regions
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Lauf <[email protected]>
  • Loading branch information
lauft committed Aug 19, 2024
1 parent f4fbb8e commit cfbcf34
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 11 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- Test holidays are only defined for valid regions
- Enable holidata to be calculated outside confirmed range

2024.8.0
Expand Down
1 change: 0 additions & 1 deletion src/holidata/holidays/AT.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 0 additions & 2 deletions src/holidata/holidays/BR.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 0 additions & 1 deletion src/holidata/holidays/CA.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 0 additions & 2 deletions src/holidata/holidays/CH.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 0 additions & 1 deletion src/holidata/holidays/DE/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

"""
Expand Down
4 changes: 0 additions & 4 deletions src/holidata/holidays/US.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
16 changes: 16 additions & 0 deletions tests/test_holidays.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)

0 comments on commit cfbcf34

Please sign in to comment.