Python calendar.calendar() Examples

The following are 30 code examples of calendar.calendar(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module calendar , or try the search function .
Example #1
Source File: test_calendar.py    From Fluid-Designer with GNU General Public License v3.0 6 votes vote down vote up
def test_setfirstweekday(self):
        self.assertRaises(TypeError, calendar.setfirstweekday, 'flabber')
        self.assertRaises(ValueError, calendar.setfirstweekday, -1)
        self.assertRaises(ValueError, calendar.setfirstweekday, 200)
        orig = calendar.firstweekday()
        calendar.setfirstweekday(calendar.SUNDAY)
        self.assertEqual(calendar.firstweekday(), calendar.SUNDAY)
        calendar.setfirstweekday(calendar.MONDAY)
        self.assertEqual(calendar.firstweekday(), calendar.MONDAY)
        calendar.setfirstweekday(orig) 
Example #2
Source File: test_calendar.py    From oss-ftp with MIT License 6 votes vote down vote up
def test_localecalendars(self):
        # ensure that Locale{Text,HTML}Calendar resets the locale properly
        # (it is still not thread-safe though)
        old_october = calendar.TextCalendar().formatmonthname(2010, 10, 10)
        try:
            cal = calendar.LocaleTextCalendar(locale='')
            local_weekday = cal.formatweekday(1, 10)
            local_month = cal.formatmonthname(2010, 10, 10)
        except locale.Error:
            # cannot set the system default locale -- skip rest of test
            raise unittest.SkipTest('cannot set the system default locale')
        # should be encodable
        local_weekday.encode('utf-8')
        local_month.encode('utf-8')
        self.assertEqual(len(local_weekday), 10)
        self.assertGreaterEqual(len(local_month), 10)
        cal = calendar.LocaleHTMLCalendar(locale='')
        local_weekday = cal.formatweekday(1)
        local_month = cal.formatmonthname(2010, 10)
        # should be encodable
        local_weekday.encode('utf-8')
        local_month.encode('utf-8')
        new_october = calendar.TextCalendar().formatmonthname(2010, 10, 10)
        self.assertEqual(old_october, new_october) 
Example #3
Source File: test_calendar.py    From ironpython2 with Apache License 2.0 6 votes vote down vote up
def test_localecalendars(self):
        # ensure that Locale{Text,HTML}Calendar resets the locale properly
        # (it is still not thread-safe though)
        old_october = calendar.TextCalendar().formatmonthname(2010, 10, 10)
        try:
            cal = calendar.LocaleTextCalendar(locale='')
            local_weekday = cal.formatweekday(1, 10)
            local_month = cal.formatmonthname(2010, 10, 10)
        except locale.Error:
            # cannot set the system default locale -- skip rest of test
            raise unittest.SkipTest('cannot set the system default locale')
        # should be encodable
        local_weekday.encode('utf-8')
        local_month.encode('utf-8')
        self.assertEqual(len(local_weekday), 10)
        self.assertGreaterEqual(len(local_month), 10)
        cal = calendar.LocaleHTMLCalendar(locale='')
        local_weekday = cal.formatweekday(1)
        local_month = cal.formatmonthname(2010, 10)
        # should be encodable
        local_weekday.encode('utf-8')
        local_month.encode('utf-8')
        new_october = calendar.TextCalendar().formatmonthname(2010, 10, 10)
        self.assertEqual(old_october, new_october) 
Example #4
Source File: test_calendar.py    From BinderFilter with MIT License 6 votes vote down vote up
def test_localecalendars(self):
        # ensure that Locale{Text,HTML}Calendar resets the locale properly
        # (it is still not thread-safe though)
        old_october = calendar.TextCalendar().formatmonthname(2010, 10, 10)
        try:
            cal = calendar.LocaleTextCalendar(locale='')
            local_weekday = cal.formatweekday(1, 10)
            local_month = cal.formatmonthname(2010, 10, 10)
        except locale.Error:
            # cannot set the system default locale -- skip rest of test
            raise unittest.SkipTest('cannot set the system default locale')
        # should be encodable
        local_weekday.encode('utf-8')
        local_month.encode('utf-8')
        self.assertEqual(len(local_weekday), 10)
        self.assertGreaterEqual(len(local_month), 10)
        cal = calendar.LocaleHTMLCalendar(locale='')
        local_weekday = cal.formatweekday(1)
        local_month = cal.formatmonthname(2010, 10)
        # should be encodable
        local_weekday.encode('utf-8')
        local_month.encode('utf-8')
        new_october = calendar.TextCalendar().formatmonthname(2010, 10, 10)
        self.assertEqual(old_october, new_october) 
Example #5
Source File: test_calendar.py    From oss-ftp with MIT License 6 votes vote down vote up
def test_setfirstweekday(self):
        self.assertRaises(ValueError, calendar.setfirstweekday, 'flabber')
        self.assertRaises(ValueError, calendar.setfirstweekday, -1)
        self.assertRaises(ValueError, calendar.setfirstweekday, 200)
        orig = calendar.firstweekday()
        calendar.setfirstweekday(calendar.SUNDAY)
        self.assertEqual(calendar.firstweekday(), calendar.SUNDAY)
        calendar.setfirstweekday(calendar.MONDAY)
        self.assertEqual(calendar.firstweekday(), calendar.MONDAY)
        calendar.setfirstweekday(orig) 
Example #6
Source File: test_calendar.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def test_formatweekheader_long(self):
        self.assertEqual(
            calendar.TextCalendar().formatweekheader(9),
            '  Monday   Tuesday  Wednesday  Thursday '
            '  Friday   Saturday   Sunday '
        ) 
Example #7
Source File: test_calendar.py    From oss-ftp with MIT License 5 votes vote down vote up
def test_january(self):
        # Tests valid lower boundary case.
        self.assertEqual(calendar.monthrange(2004,1), (3,31)) 
Example #8
Source File: test_calendar.py    From oss-ftp with MIT License 5 votes vote down vote up
def test_february_leap(self):
        # Tests February during leap year.
        self.assertEqual(calendar.monthrange(2004,2), (6,29)) 
Example #9
Source File: test_calendar.py    From oss-ftp with MIT License 5 votes vote down vote up
def test_february_nonleap(self):
        # Tests February in non-leap year.
        self.assertEqual(calendar.monthrange(2010,2), (0,28)) 
Example #10
Source File: test_calendar.py    From oss-ftp with MIT License 5 votes vote down vote up
def test_december(self):
        # Tests valid upper boundary case.
        self.assertEqual(calendar.monthrange(2004,12), (2,31)) 
Example #11
Source File: test_calendar.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def test_prweek(self):
        with support.captured_stdout() as out:
            week = [(1,0), (2,1), (3,2), (4,3), (5,4), (6,5), (7,6)]
            calendar.TextCalendar().prweek(week, 1)
            self.assertEqual(out.getvalue().strip(), "1  2  3  4  5  6  7") 
Example #12
Source File: test_calendar.py    From oss-ftp with MIT License 5 votes vote down vote up
def test_itermonthdates(self):
        # ensure itermonthdates doesn't overflow after datetime.MAXYEAR
        # see #15421
        list(calendar.Calendar().itermonthdates(datetime.MAXYEAR, 12)) 
Example #13
Source File: test_calendar.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def test_formatmonth(self):
        self.assertEqual(
            calendar.TextCalendar().formatmonth(2004, 1),
            result_2004_01_text
        ) 
Example #14
Source File: test_calendar.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def test_formatmonthname_with_year(self):
        self.assertEqual(
            calendar.HTMLCalendar().formatmonthname(2004, 1, withyear=True),
            '<tr><th colspan="7" class="month">January 2004</th></tr>'
        ) 
Example #15
Source File: test_calendar.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def test_formatmonthname_without_year(self):
        self.assertEqual(
            calendar.HTMLCalendar().formatmonthname(2004, 1, withyear=False),
            '<tr><th colspan="7" class="month">January</th></tr>'
        ) 
Example #16
Source File: test_calendar.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def test_format(self):
        with support.captured_stdout() as out:
            calendar.format(["1", "2", "3"], colwidth=3, spacing=1)
            self.assertEqual(out.getvalue().strip(), "1   2   3") 
Example #17
Source File: test_calendar.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def test_illegal_weekday_reported(self):
        with self.assertRaisesRegex(calendar.IllegalWeekdayError, '123'):
            calendar.setfirstweekday(123) 
Example #18
Source File: test_calendar.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def test_isleap(self):
        # Make sure that the return is right for a few years, and
        # ensure that the return values are 1 or 0, not just true or
        # false (see SF bug #485794).  Specific additional tests may
        # be appropriate; this tests a single "cycle".
        self.assertEqual(calendar.isleap(2000), 1)
        self.assertEqual(calendar.isleap(2001), 0)
        self.assertEqual(calendar.isleap(2002), 0)
        self.assertEqual(calendar.isleap(2003), 0) 
Example #19
Source File: test_calendar.py    From oss-ftp with MIT License 5 votes vote down vote up
def check_weeks(self, year, month, weeks):
        cal = calendar.monthcalendar(year, month)
        self.assertEqual(len(cal), len(weeks))
        for i in xrange(len(weeks)):
            self.assertEqual(weeks[i], sum(day != 0 for day in cal[i])) 
Example #20
Source File: test_calendar.py    From oss-ftp with MIT License 5 votes vote down vote up
def setUp(self):
        self.oldfirstweekday = calendar.firstweekday()
        calendar.setfirstweekday(self.firstweekday) 
Example #21
Source File: test_calendar.py    From oss-ftp with MIT License 5 votes vote down vote up
def test_no_range(self):
        # test when no range i.e. two identical years as args
        self.assertEqual(calendar.leapdays(2010,2010), 0) 
Example #22
Source File: test_calendar.py    From oss-ftp with MIT License 5 votes vote down vote up
def test_months(self):
        for attr in "month_name", "month_abbr":
            value = getattr(calendar, attr)
            self.assertEqual(len(value), 13)
            self.assertEqual(len(value[:]), 13)
            self.assertEqual(value[0], "")
            # ensure they're all unique
            self.assertEqual(len(set(value)), 13)
            # verify it "acts like a sequence" in two forms of iteration
            self.assertEqual(value[::-1], list(reversed(value))) 
Example #23
Source File: test_calendar.py    From oss-ftp with MIT License 5 votes vote down vote up
def test_days(self):
        for attr in "day_name", "day_abbr":
            value = getattr(calendar, attr)
            self.assertEqual(len(value), 7)
            self.assertEqual(len(value[:]), 7)
            # ensure they're all unique
            self.assertEqual(len(set(value)), 7)
            # verify it "acts like a sequence" in two forms of iteration
            self.assertEqual(value[::-1], list(reversed(value))) 
Example #24
Source File: test_calendar.py    From oss-ftp with MIT License 5 votes vote down vote up
def test_isleap(self):
        # Make sure that the return is right for a few years, and
        # ensure that the return values are 1 or 0, not just true or
        # false (see SF bug #485794).  Specific additional tests may
        # be appropriate; this tests a single "cycle".
        self.assertEqual(calendar.isleap(2000), 1)
        self.assertEqual(calendar.isleap(2001), 0)
        self.assertEqual(calendar.isleap(2002), 0)
        self.assertEqual(calendar.isleap(2003), 0) 
Example #25
Source File: test_calendar.py    From oss-ftp with MIT License 5 votes vote down vote up
def test_output_htmlcalendar(self):
        self.assertEqual(
            calendar.HTMLCalendar().formatyearpage(2004).strip(),
            result_2004_html.strip()
        ) 
Example #26
Source File: test_calendar.py    From oss-ftp with MIT License 5 votes vote down vote up
def test_output_textcalendar(self):
        self.assertEqual(
            calendar.TextCalendar().formatyear(2004).strip(),
            result_2004_text.strip()
        ) 
Example #27
Source File: test_calendar.py    From oss-ftp with MIT License 5 votes vote down vote up
def test_output(self):
        self.assertEqual(
            self.normalize_calendar(calendar.calendar(2004)),
            self.normalize_calendar(result_2004_text)
        ) 
Example #28
Source File: test_calendar.py    From BinderFilter with MIT License 5 votes vote down vote up
def test_one_leapday_lower_boundary(self):
        # test when one leap year in range, lower boundary is leap year
        self.assertEqual(calendar.leapdays(2012,2013), 1) 
Example #29
Source File: test_calendar.py    From BinderFilter with MIT License 5 votes vote down vote up
def test_no_leapdays_upper_boundary(self):
        # test no leap years in range, when upper boundary is a leap year
        self.assertEqual(calendar.leapdays(2010,2012), 0) 
Example #30
Source File: test_calendar.py    From BinderFilter with MIT License 5 votes vote down vote up
def test_no_leapdays(self):
        # test when no leap years in range
        self.assertEqual(calendar.leapdays(2010,2011), 0)