Skip to content

Commit

Permalink
Introduce common.WorkingDaysTests
Browse files Browse the repository at this point in the history
  • Loading branch information
KJhellico committed Jan 2, 2025
1 parent a387595 commit 7541664
Show file tree
Hide file tree
Showing 13 changed files with 864 additions and 157 deletions.
4 changes: 2 additions & 2 deletions holidays/countries/azerbaijan.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,10 @@ class AzerbaijanStaticHolidays:
2018: (APR, 11, presidential_elections),
2019: (DEC, 27, municipal_elections),
2020: (
(MAR, 27, MAR, 29),
(MAY, 27, MAY, 30),
(JAN, 3, DEC, 28, 2019),
(JAN, 6, DEC, 29, 2019),
(MAR, 27, MAR, 29),
(MAY, 27, MAY, 30),
),
2021: (
(MAY, 11, MAY, 8),
Expand Down
2 changes: 1 addition & 1 deletion holidays/countries/belarus.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ class BelarusStaticHolidays:
),
2024: (
(MAY, 13, MAY, 18),
(NOV, 16, NOV, 8),
(NOV, 8, NOV, 16),
),
2025: (
(JAN, 6, JAN, 11),
Expand Down
4 changes: 2 additions & 2 deletions holidays/countries/kazakhstan.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@ class KazakhstanStaticHolidays:
2019: (MAY, 10, MAY, 4),
2020: (
(JAN, 3, JAN, 5),
(MAY, 8, MAY, 11),
(DEC, 18, DEC, 20),
),
2021: (JUL, 5, JUL, 3),
Expand All @@ -293,5 +292,6 @@ class KazakhstanStaticHolidays:
}

special_public_holidays_observed = {
2020: (MAY, 8, MAY, 11),
# Victory Day.
2020: (MAY, 8, tr("Жеңіс күні")),
}
2 changes: 1 addition & 1 deletion snapshots/countries/BY_COMMON.json
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@
"2024-09-17": "Day of People's Unity",
"2024-11-02": "Dzyady (All Souls' Day)",
"2024-11-07": "October Revolution Day",
"2024-11-16": "Day off (substituted from 11/08/2024)",
"2024-11-08": "Day off (substituted from 11/16/2024)",
"2024-12-25": "Catholic Christmas Day",
"2025-01-01": "New Year's Day",
"2025-01-02": "New Year's Day",
Expand Down
2 changes: 1 addition & 1 deletion snapshots/countries/KZ_COMMON.json
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@
"2020-03-25": "Nowruz holiday (observed)",
"2020-05-01": "Kazakhstan's People Solidarity Holiday",
"2020-05-07": "Defender of the Fatherland Day",
"2020-05-08": "Day off (substituted from 05/11/2020)",
"2020-05-08": "Victory Day (observed)",
"2020-05-09": "Victory Day",
"2020-07-06": "Capital Day",
"2020-07-31": "Eid al-Adha",
Expand Down
22 changes: 22 additions & 0 deletions tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,3 +419,25 @@ def assertSundays(self, cls): # noqa: N802
):
self.assertNotEqual(parse(non_sunday).weekday(), SUN)
self.assertNoHoliday(holidays, non_sunday)


class WorkingDaysTests(TestCase):
"""Common class to test countries with holidays substituted from non-working days."""

# Workday.
def _assertWorkday(self, instance_name, *args): # noqa: N802
"""Helper: assert each date is a working day."""
holidays, dates = self._parse_arguments(args, instance_name=instance_name)
self._verify_type(holidays)

for dt in dates:
self.assertTrue(holidays._is_weekend(parse(dt)))
self.assertTrue(holidays.is_working_day(dt))

def assertWorkday(self, *args): # noqa: N802
"""Assert each date is a working day."""
self._assertWorkday("holidays", *args)

def assertNonObservedWorkday(self, *args): # noqa: N802
"""Assert each date is a non-observed working day."""
self._assertWorkday("holidays_non_observed", *args)
36 changes: 31 additions & 5 deletions tests/countries/test_azerbaijan.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@

from holidays.constants import PUBLIC, WORKDAY
from holidays.countries.azerbaijan import Azerbaijan, AZ, AZE
from tests.common import CommonCountryTests
from tests.common import CommonCountryTests, WorkingDaysTests


class TestAzerbaijan(CommonCountryTests, TestCase):
class TestAzerbaijan(CommonCountryTests, WorkingDaysTests, TestCase):
@classmethod
def setUpClass(cls):
super().setUpClass(Azerbaijan, years=range(1990, 2050))
Expand Down Expand Up @@ -66,6 +66,34 @@ def test_substituted_holidays(self):
"2025-01-03",
)

def test_workdays(self):
self.assertWorkday(
"2011-08-27",
"2012-12-29",
"2012-12-30",
"2013-12-28",
"2013-12-29",
"2019-12-28",
"2019-12-29",
"2020-03-29",
"2020-05-30",
"2021-05-08",
"2021-05-16",
"2021-07-17",
"2022-03-05",
"2022-11-05",
"2023-06-24",
"2023-06-25",
"2023-11-04",
"2023-12-30",
"2024-01-07",
"2024-04-06",
"2024-11-16",
"2024-11-23",
"2024-12-28",
"2024-12-29",
)

for year, dts in {
2012: (
"2012-12-29",
Expand All @@ -82,9 +110,7 @@ def test_substituted_holidays(self):
2023: ("2023-12-30",),
2024: ("2024-12-29",),
}.items():
az_holidays = Azerbaijan(years=year)
for dt in dts:
self.assertTrue(az_holidays.is_working_day(dt))
self.assertWorkday(Azerbaijan(years=year), dts)

def test_new_years_day(self):
name = "Yeni il bayramı"
Expand Down
121 changes: 106 additions & 15 deletions tests/countries/test_belarus.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@

from holidays.constants import PUBLIC, WORKDAY
from holidays.countries.belarus import Belarus, BY, BLR
from tests.common import CommonCountryTests
from tests.common import CommonCountryTests, WorkingDaysTests


class TestBelarus(CommonCountryTests, TestCase):
class TestBelarus(CommonCountryTests, WorkingDaysTests, TestCase):
@classmethod
def setUpClass(cls):
years = range(1991, 2050)
Expand Down Expand Up @@ -225,18 +225,6 @@ def test_radunitsa(self):
"2030-05-07",
)

for year, dts in {
2006: (
"2006-01-21",
"2006-05-06",
"2006-11-04",
"2006-12-30",
),
}.items():
be_holidays = Belarus(years=year)
for dt in dts:
self.assertTrue(be_holidays.is_working_day(dt))

def test_dzyady(self):
name = "Дзень памяці"

Expand Down Expand Up @@ -333,13 +321,116 @@ def test_substituted_holidays(self):
"2023-05-08",
"2023-11-06",
"2024-05-13",
"2024-11-16",
"2024-11-08",
"2025-01-06",
"2025-04-28",
"2025-07-04",
"2025-12-26",
)

def test_workdays(self):
self.assertWorkday(
"1998-01-10",
"1998-04-25",
"1999-01-16",
"1999-04-17",
"2000-05-13",
"2000-11-11",
"2001-01-20",
"2001-03-03",
"2001-04-21",
"2001-04-28",
"2001-07-07",
"2001-12-22",
"2001-12-29",
"2002-01-05",
"2002-05-18",
"2002-11-16",
"2003-01-04",
"2003-05-03",
"2004-01-10",
"2004-01-17",
"2004-01-31",
"2004-04-17",
"2005-03-12",
"2006-01-21",
"2006-05-06",
"2006-11-04",
"2006-12-30",
"2007-03-17",
"2007-04-14",
"2007-05-05",
"2007-07-07",
"2007-12-22",
"2007-12-29",
"2008-01-12",
"2008-05-03",
"2008-06-28",
"2008-12-20",
"2009-01-10",
"2009-04-25",
"2010-01-23",
"2010-04-17",
"2010-05-15",
"2011-03-12",
"2011-05-14",
"2012-03-11",
"2012-04-28",
"2012-06-30",
"2012-12-22",
"2012-12-29",
"2013-01-05",
"2013-05-18",
"2014-01-04",
"2014-01-11",
"2014-05-03",
"2014-07-12",
"2014-12-20",
"2015-01-10",
"2015-04-25",
"2016-01-16",
"2016-03-05",
"2017-01-21",
"2017-04-29",
"2017-05-06",
"2017-11-04",
"2018-01-20",
"2018-03-03",
"2018-04-14",
"2018-04-28",
"2018-07-07",
"2018-12-22",
"2018-12-29",
"2019-05-04",
"2019-05-11",
"2019-11-16",
"2020-01-04",
"2020-04-04",
"2021-01-16",
"2021-05-15",
"2022-03-12",
"2022-05-14",
"2023-04-29",
"2023-05-13",
"2023-11-11",
"2024-05-18",
"2024-11-16",
"2025-01-11",
"2025-04-26",
"2025-07-12",
"2025-12-20",
)

for year, dts in {
2006: (
"2006-01-21",
"2006-05-06",
"2006-11-04",
"2006-12-30",
),
}.items():
self.assertWorkday(Belarus(years=year), dts)

def test_l10n_default(self):
self.assertLocalizedHolidays(
("2022-01-01", "Новы год"),
Expand Down
Loading

0 comments on commit 7541664

Please sign in to comment.