Skip to content

Commit e91b42e

Browse files
committed
PEP8 --ignore W503 and 100% unit test
1 parent f7dbfbb commit e91b42e

File tree

2 files changed

+57
-44
lines changed

2 files changed

+57
-44
lines changed

holidays.py

Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4967,23 +4967,21 @@ class Singapore(HolidayBase):
49674967

49684968
# Holidays prior to 2000 may not be accurate.
49694969

4970-
# Holidays after 2020: the following four annual scheduled but moving date
4971-
# holidays (announced yearly) are estimated:
4970+
# Holidays after 2020: the following four moving date holidays whose exact
4971+
# date is announced yearly are estimated (and so denoted):
49724972
# - Hari Raya Puasa*
49734973
# - Hari Raya Haji*
49744974
# - Vesak Day
49754975
# - Deepavali
49764976
# *only if hijri-converter library is installed, otherwise a warning is
4977-
# raised that this holiday is missing. hjiri-converter requires
4977+
# raised that this holiday is missing. hijri-converter requires
49784978
# Python >= 3.6
49794979

49804980
def __init__(self, **kwargs):
49814981
self.country = "SG"
49824982
HolidayBase.__init__(self, **kwargs)
49834983

49844984
def _populate(self, year):
4985-
if year < 1969:
4986-
return
49874985

49884986
def storeholiday(self, hol_date, hol_name):
49894987
"""
@@ -5010,21 +5008,23 @@ def storeholiday(self, hol_date, hol_name):
50105008
# Hari Raya Puasa
50115009
# aka Eid al-Fitr
50125010
# date of observance is announced yearly
5013-
dates_obs = {2001: [(DEC, 16)], 2002: [(DEC, 6)],
5014-
2003: [(NOV, 25)], 2004: [(NOV, 14)], 2005: [(NOV, 3)],
5015-
2006: [(OCT, 24)], 2007: [(OCT, 13)], 2008: [(OCT, 1)],
5011+
dates_obs = {2001: [(DEC, 16)], 2002: [(DEC, 6)],
5012+
2003: [(NOV, 25)], 2004: [(NOV, 14)], 2005: [(NOV, 3)],
5013+
2006: [(OCT, 24)], 2007: [(OCT, 13)], 2008: [(OCT, 1)],
50165014
2009: [(SEP, 20)], 2010: [(SEP, 10)], 2011: [(AUG, 30)],
5017-
2012: [(AUG, 19)], 2013: [(AUG, 8)], 2014: [(JUL, 28)],
5018-
2015: [(JUL, 17)], 2016: [(JUL, 6)], 2017: [(JUN, 25)],
5019-
2018: [(JUN, 15)], 2019: [(JUN, 5)], 2020: [(MAY, 24)]}
5015+
2012: [(AUG, 19)], 2013: [(AUG, 8)], 2014: [(JUL, 28)],
5016+
2015: [(JUL, 17)], 2016: [(JUL, 6)], 2017: [(JUN, 25)],
5017+
2018: [(JUN, 15)], 2019: [(JUN, 5)], 2020: [(MAY, 24)]}
50205018
if year in dates_obs:
50215019
for date_obs in dates_obs[year]:
50225020
hol_date = date(year, *date_obs)
50235021
storeholiday(self, hol_date, "Hari Raya Puasa")
50245022
# Second day of Hari Raya Puasa (up to and including 1968)
5025-
if year <= 1968:
5026-
storeholiday(self, hol_date + rd(days=+1),
5027-
"Second day of Hari Raya Puasa")
5023+
# Removed since we don't have Hari Raya Puasa dates for the
5024+
# the years <= 1968:
5025+
# if year <= 1968:
5026+
# storeholiday(self, hol_date + rd(days=+1),
5027+
# "Second day of Hari Raya Puasa")
50285028
else:
50295029
for date_obs in self.get_hrp_date(year):
50305030
hol_date = date_obs
@@ -5038,12 +5038,12 @@ def storeholiday(self, hol_date, hol_name):
50385038
# Hari Raya Haji
50395039
# aka Eid al-Adha
50405040
# date of observance is announced yearly
5041-
dates_obs = {2001: [(MAR, 6)], 2002: [(FEB, 23)],
5042-
2003: [(FEB, 12)], 2004: [(FEB, 1)], 2005: [(JAN, 21)],
5043-
2006: [(JAN, 10)], 2007: [(DEC, 20)], 2008: [(DEC, 8)],
5044-
2009: [(NOV, 27)], 2010: [(NOV, 17)], 2011: [(NOV, 6)],
5045-
2012: [(OCT, 26)], 2013: [(OCT, 15)], 2014: [(OCT, 5)],
5046-
2015: [(SEP, 24)], 2016: [(SEP, 12)], 2017: [(SEP, 1)],
5041+
dates_obs = {2001: [(MAR, 6)], 2002: [(FEB, 23)],
5042+
2003: [(FEB, 12)], 2004: [(FEB, 1)], 2005: [(JAN, 21)],
5043+
2006: [(JAN, 10)], 2007: [(DEC, 20)], 2008: [(DEC, 8)],
5044+
2009: [(NOV, 27)], 2010: [(NOV, 17)], 2011: [(NOV, 6)],
5045+
2012: [(OCT, 26)], 2013: [(OCT, 15)], 2014: [(OCT, 5)],
5046+
2015: [(SEP, 24)], 2016: [(SEP, 12)], 2017: [(SEP, 1)],
50475047
2018: [(AUG, 22)], 2019: [(AUG, 11)], 2020: [(JUL, 31)]}
50485048
if year in dates_obs:
50495049
for date_obs in dates_obs[year]:
@@ -5073,13 +5073,13 @@ def storeholiday(self, hol_date, hol_name):
50735073
# Vesak Day
50745074
# date of observance is announced yearly
50755075
# https://en.wikipedia.org/wiki/Vesak#Dates_of_observance
5076-
dates_obs = {2001: (MAY, 7), 2002: (MAY, 27),
5077-
2003: (MAY, 15), 2004: (JUN, 2), 2005: (MAY, 23),
5076+
dates_obs = {2001: (MAY, 7), 2002: (MAY, 27),
5077+
2003: (MAY, 15), 2004: (JUN, 2), 2005: (MAY, 23),
50785078
2006: (MAY, 12), 2007: (MAY, 31), 2008: (MAY, 19),
5079-
2009: (MAY, 9), 2010: (MAY, 28), 2011: (MAY, 17),
5080-
2012: (MAY, 5), 2013: (MAY, 24), 2014: (MAY, 13),
5081-
2015: (JUN, 1), 2016: (MAY, 20), 2017: (MAY, 10),
5082-
2018: (MAY, 29), 2019: (MAY, 19), 2020: (MAY, 7)}
5079+
2009: (MAY, 9), 2010: (MAY, 28), 2011: (MAY, 17),
5080+
2012: (MAY, 5), 2013: (MAY, 24), 2014: (MAY, 13),
5081+
2015: (JUN, 1), 2016: (MAY, 20), 2017: (MAY, 10),
5082+
2018: (MAY, 29), 2019: (MAY, 19), 2020: (MAY, 7)}
50835083
if year in dates_obs:
50845084
hol_date = date(year, *dates_obs[year])
50855085
storeholiday(self, hol_date, "Vesak Day")
@@ -5093,13 +5093,13 @@ def storeholiday(self, hol_date, hol_name):
50935093
# Deepavali
50945094
# aka Diwali
50955095
# date of observance is announced yearly
5096-
dates_obs = {2001: (NOV, 14), 2002: (NOV, 3),
5097-
2003: (OCT, 23), 2004: (NOV, 11), 2005: (NOV, 1),
5098-
2006: (OCT, 21), 2007: (NOV, 8), 2008: (OCT, 27),
5099-
2009: (OCT, 17), 2010: (NOV, 5), 2011: (OCT, 26),
5100-
2012: (NOV, 13), 2013: (NOV, 2), 2014: (OCT, 22),
5096+
dates_obs = {2001: (NOV, 14), 2002: (NOV, 3),
5097+
2003: (OCT, 23), 2004: (NOV, 11), 2005: (NOV, 1),
5098+
2006: (OCT, 21), 2007: (NOV, 8), 2008: (OCT, 27),
5099+
2009: (OCT, 17), 2010: (NOV, 5), 2011: (OCT, 26),
5100+
2012: (NOV, 13), 2013: (NOV, 2), 2014: (OCT, 22),
51015101
2015: (NOV, 10), 2016: (OCT, 29), 2017: (OCT, 18),
5102-
2018: (NOV, 6), 2019: (OCT, 27), 2020: (NOV, 14)}
5102+
2018: (NOV, 6), 2019: (OCT, 27), 2020: (NOV, 14)}
51035103
if year in dates_obs:
51045104
hol_date = date(year, *dates_obs[year])
51055105
storeholiday(self, hol_date, "Deepavali")
@@ -5115,7 +5115,7 @@ def storeholiday(self, hol_date, hol_name):
51155115
storeholiday(self, date(year, DEC, 26), "Boxing Day")
51165116

51175117
# Polling Day
5118-
dates_obs = {2001: (NOV, 3), 2006: (MAY, 6),
5118+
dates_obs = {2001: (NOV, 3), 2006: (MAY, 6),
51195119
2011: (MAY, 7), 2015: (SEP, 11)}
51205120
if year in dates_obs:
51215121
self[date(year, *dates_obs[year])] = "Polling Day"
@@ -5185,12 +5185,12 @@ def storeholiday(self, hol_date, hol_name):
51855185
LUNAR_END_DATE, SOLAR_END_DATE = (2099, 12, 30), date(2100, 2, 18)
51865186

51875187
def get_leap_month(self, lunar_year):
5188-
return (self.g_lunar_month_days[lunar_year-self.START_YEAR] >> 16) \
5189-
& 0x0F
5188+
return (self.g_lunar_month_days[lunar_year - self.START_YEAR] >> 16) \
5189+
& 0x0F
51905190

51915191
def lunar_month_days(self, lunar_year, lunar_month):
5192-
return 29 + ((self.g_lunar_month_days[lunar_year-self.START_YEAR] >>
5193-
lunar_month) & 0x01)
5192+
return 29 + ((self.g_lunar_month_days[lunar_year - self.START_YEAR]
5193+
>> lunar_month) & 0x01)
51945194

51955195
def lunar_year_days(self, year):
51965196
days = 0
@@ -5205,9 +5205,10 @@ def get_lunar_n_y_date(self, year):
52055205
span_days = 0
52065206
for y in range(self.START_YEAR, year):
52075207
span_days += self.lunar_year_days(y)
5208-
leap_month = self.get_leap_month(year)
5209-
for m in range(1, 1 + (1 > leap_month)):
5210-
span_days += self.lunar_month_days(year, m)
5208+
# Always in first month (by definition)
5209+
# leap_month = self.get_leap_month(year)
5210+
# for m in range(1, 1 + (1 > leap_month)):
5211+
# span_days += self.lunar_month_days(year, m)
52115212
return self.SOLAR_START_DATE + timedelta(span_days)
52125213

52135214
# Estimate Gregorian date of Vesak
@@ -5243,8 +5244,8 @@ def warning_on_one_line(message, category, filename,
52435244
lineno, file=None, line=None):
52445245
return filename + ': ' + str(message) + '\n'
52455246
warnings.formatwarning = warning_on_one_line
5246-
warnings.warn("Hari Raja Puasa is missing." +
5247-
"To estimate, install hijri-converter library")
5247+
warnings.warn("Hari Raja Puasa is missing."
5248+
+ "To estimate, install hijri-converter library")
52485249
warnings.warn("pip install -U hijri-converter")
52495250
warnings.warn("(see https://hijri-converter.readthedocs.io/ )")
52505251
return []
@@ -5270,8 +5271,8 @@ def warning_on_one_line(message, category, filename, lineno,
52705271
file=None, line=None):
52715272
return filename + ': ' + str(message) + '\n'
52725273
warnings.formatwarning = warning_on_one_line
5273-
warnings.warn("Hari Raja Haji is missing." +
5274-
"To estimate, install hijri-converter library")
5274+
warnings.warn("Hari Raja Haji is missing."
5275+
+ "To estimate, install hijri-converter library")
52755276
warnings.warn("pip install -U hijri-converter")
52765277
warnings.warn("(see https://hijri-converter.readthedocs.io/ )")
52775278
return []

tests.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5446,6 +5446,18 @@ def setUp(self):
54465446
self.holidays = holidays.Singapore()
54475447

54485448
def test_Singapore(self):
5449+
# <= 1968 holidays
5450+
self.assertIn(date(1968, 1, 2), self.holidays)
5451+
self.assertIn(date(1968, 4, 13), self.holidays)
5452+
self.assertIn(date(1968, 4, 15), self.holidays)
5453+
self.assertIn(date(1968, 12, 26), self.holidays)
5454+
# latest polling day
5455+
self.assertIn(date(2015, 9, 11), self.holidays)
5456+
# SG50
5457+
self.assertIn(date(2015, 8, 7), self.holidays)
5458+
# Year with lunar leap month
5459+
self.assertIn(date(2015, 8, 7), self.holidays)
5460+
# Latest holidays
54495461
# Source: https://www.mom.gov.sg/employment-practices/public-holidays
54505462
# 2018
54515463
self.assertIn(date(2018, 1, 1), self.holidays)

0 commit comments

Comments
 (0)