当前位置: 首页>>代码示例>>Python>>正文


Python calendar.calendar方法代码示例

本文整理汇总了Python中calendar.calendar方法的典型用法代码示例。如果您正苦于以下问题:Python calendar.calendar方法的具体用法?Python calendar.calendar怎么用?Python calendar.calendar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在calendar的用法示例。


在下文中一共展示了calendar.calendar方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_localecalendars

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import calendar [as 别名]
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) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:26,代码来源:test_calendar.py

示例2: test_output

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import calendar [as 别名]
def test_output(self):
        self.assertEqual(
            self.normalize_calendar(calendar.calendar(2004)),
            self.normalize_calendar(result_2004_text)
        ) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:7,代码来源:test_calendar.py

示例3: test_output_textcalendar

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import calendar [as 别名]
def test_output_textcalendar(self):
        self.assertEqual(
            calendar.TextCalendar().formatyear(2004).strip(),
            result_2004_text.strip()
        ) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:7,代码来源:test_calendar.py

示例4: test_output_htmlcalendar

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import calendar [as 别名]
def test_output_htmlcalendar(self):
        self.assertEqual(
            calendar.HTMLCalendar().formatyearpage(2004).strip(),
            result_2004_html.strip()
        ) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:7,代码来源:test_calendar.py

示例5: test_isleap

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import calendar [as 别名]
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) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:11,代码来源:test_calendar.py

示例6: test_setfirstweekday

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import calendar [as 别名]
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) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:12,代码来源:test_calendar.py

示例7: test_days

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import calendar [as 别名]
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))) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:11,代码来源:test_calendar.py

示例8: test_months

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import calendar [as 别名]
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))) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:12,代码来源:test_calendar.py

示例9: test_itermonthdates

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import calendar [as 别名]
def test_itermonthdates(self):
        # ensure itermonthdates doesn't overflow after datetime.MAXYEAR
        # see #15421
        list(calendar.Calendar().itermonthdates(datetime.MAXYEAR, 12)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:6,代码来源:test_calendar.py

示例10: test_itermonthdays

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import calendar [as 别名]
def test_itermonthdays(self):
        for firstweekday in range(7):
            cal = calendar.Calendar(firstweekday)
            # Test the extremes, see #28253 and #26650
            for y, m in [(1, 1), (9999, 12)]:
                days = list(cal.itermonthdays(y, m))
                self.assertIn(len(days), (35, 42))
        # Test a short month
        cal = calendar.Calendar(firstweekday=3)
        days = list(cal.itermonthdays(2001, 2))
        self.assertEqual(days, list(range(1, 29))) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:13,代码来源:test_calendar.py

示例11: setUp

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import calendar [as 别名]
def setUp(self):
        self.oldfirstweekday = calendar.firstweekday()
        calendar.setfirstweekday(self.firstweekday) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:5,代码来源:test_calendar.py

示例12: tearDown

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import calendar [as 别名]
def tearDown(self):
        calendar.setfirstweekday(self.oldfirstweekday) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:4,代码来源:test_calendar.py

示例13: check_weeks

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import calendar [as 别名]
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])) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:7,代码来源:test_calendar.py

示例14: test_january

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import calendar [as 别名]
def test_january(self):
        # Tests valid lower boundary case.
        self.assertEqual(calendar.monthrange(2004,1), (3,31)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:5,代码来源:test_calendar.py

示例15: test_february_leap

# 需要导入模块: import calendar [as 别名]
# 或者: from calendar import calendar [as 别名]
def test_february_leap(self):
        # Tests February during leap year.
        self.assertEqual(calendar.monthrange(2004,2), (6,29)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:5,代码来源:test_calendar.py


注:本文中的calendar.calendar方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。