本文整理匯總了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)
示例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)
)
示例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()
)
示例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()
)
示例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)
示例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)
示例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)))
示例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)))
示例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))
示例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)))
示例11: setUp
# 需要導入模塊: import calendar [as 別名]
# 或者: from calendar import calendar [as 別名]
def setUp(self):
self.oldfirstweekday = calendar.firstweekday()
calendar.setfirstweekday(self.firstweekday)
示例12: tearDown
# 需要導入模塊: import calendar [as 別名]
# 或者: from calendar import calendar [as 別名]
def tearDown(self):
calendar.setfirstweekday(self.oldfirstweekday)
示例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]))
示例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))
示例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))