68 lines
2.2 KiB
Python
68 lines
2.2 KiB
Python
from datetime import date
|
|
from workalendar.tests import GenericCalendarTest
|
|
from workalendar.core import Calendar, MON, TUE, THU
|
|
|
|
|
|
class CalendarTest(GenericCalendarTest):
|
|
|
|
def test_private_variables(self):
|
|
self.assertTrue(hasattr(self.cal, '_holidays'))
|
|
private_holidays = self.cal._holidays
|
|
self.assertTrue(isinstance(private_holidays, dict))
|
|
self.cal.holidays(2011)
|
|
self.cal.holidays(2012)
|
|
private_holidays = self.cal._holidays
|
|
self.assertTrue(isinstance(private_holidays, dict))
|
|
self.assertIn(2011, self.cal._holidays)
|
|
self.assertIn(2012, self.cal._holidays)
|
|
|
|
def test_year(self):
|
|
holidays = self.cal.holidays()
|
|
self.assertTrue(isinstance(holidays, set))
|
|
self.assertEquals(self.cal._holidays[self.year], holidays)
|
|
|
|
def test_another_year(self):
|
|
holidays = self.cal.holidays(2011)
|
|
self.assertTrue(isinstance(holidays, set))
|
|
self.assertEquals(self.cal._holidays[2011], holidays)
|
|
|
|
def test_is_workday(self):
|
|
self.assertRaises(
|
|
NotImplementedError,
|
|
self.cal.is_workday, date(2012, 1, 1))
|
|
|
|
def test_nth_weekday(self):
|
|
# first monday in january 2013
|
|
self.assertEquals(
|
|
Calendar.get_nth_weekday_in_month(2013, 1, MON),
|
|
date(2013, 1, 7)
|
|
)
|
|
# second monday in january 2013
|
|
self.assertEquals(
|
|
Calendar.get_nth_weekday_in_month(2013, 1, MON, 2),
|
|
date(2013, 1, 14)
|
|
)
|
|
# let's test the limits
|
|
# Jan 1st is a TUE
|
|
self.assertEquals(
|
|
Calendar.get_nth_weekday_in_month(2013, 1, TUE),
|
|
date(2013, 1, 1)
|
|
)
|
|
# There's no 6th MONday
|
|
self.assertEquals(
|
|
Calendar.get_nth_weekday_in_month(2013, 1, MON, 6),
|
|
None
|
|
)
|
|
|
|
def test_last_weekday(self):
|
|
# last monday in january 2013
|
|
self.assertEquals(
|
|
Calendar.get_last_weekday_in_month(2013, 1, MON),
|
|
date(2013, 1, 28)
|
|
)
|
|
# last thursday
|
|
self.assertEquals(
|
|
Calendar.get_last_weekday_in_month(2013, 1, THU),
|
|
date(2013, 1, 31)
|
|
)
|