本文整理汇总了Python中isoweek.Week.fromordinal方法的典型用法代码示例。如果您正苦于以下问题:Python Week.fromordinal方法的具体用法?Python Week.fromordinal怎么用?Python Week.fromordinal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类isoweek.Week
的用法示例。
在下文中一共展示了Week.fromordinal方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_constructors
# 需要导入模块: from isoweek import Week [as 别名]
# 或者: from isoweek.Week import fromordinal [as 别名]
def test_constructors(self):
w = Week(2011,1)
self.assertTrue(w)
self.assertEqual(str(w), "2011W01")
w = Week(2011,0)
self.assertEqual(str(w), "2010W52")
w = Week(2011,-1)
self.assertEqual(str(w), "2010W51")
w = Week(2011,52)
self.assertEqual(str(w), "2011W52")
w = Week(2011,53)
self.assertEqual(str(w), "2012W01")
w = Week(2011,54)
self.assertEqual(str(w), "2012W02")
w = Week(2009,51)
self.assertEqual(str(w), "2009W51")
w = Week(2009,52)
self.assertEqual(str(w), "2009W52")
w = Week(2009,53)
self.assertEqual(str(w), "2010W01")
w = Week(2009,54)
self.assertEqual(str(w), "2010W02")
w = Week.thisweek()
self.assertTrue(w)
w = Week.fromordinal(1)
self.assertEqual(str(w), "0001W01")
w = Week.fromordinal(2)
self.assertEqual(str(w), "0001W02")
w = Week.fromordinal(521723)
self.assertEqual(str(w), "9999W52")
w = Week.fromstring("2011W01")
self.assertEqual(str(w), "2011W01")
w = Week.fromstring("2011-W01")
self.assertEqual(str(w), "2011W01")
from datetime import date
w = Week.withdate(date(2011, 5, 17))
self.assertEqual(str(w), "2011W20")
self.assertEqual(Week.last_week_of_year(2009), Week(2009, 52))
self.assertEqual(Week.last_week_of_year(2010), Week(2010, 52))
self.assertEqual(Week.last_week_of_year(2011), Week(2011, 52))
self.assertEqual(Week.last_week_of_year(9999), Week(9999, 52))
self.assertRaises(ValueError, lambda: Week(0, 0))
self.assertRaises(ValueError, lambda: Week.fromstring("0000W00"))
self.assertRaises(ValueError, lambda: Week.fromstring("foo"))
self.assertRaises(ValueError, lambda: Week.fromordinal(-1))
self.assertRaises(ValueError, lambda: Week.fromordinal(0))
self.assertRaises(ValueError, lambda: Week.fromordinal(521724))
self.assertRaises(ValueError, lambda: Week.last_week_of_year(0))
self.assertRaises(ValueError, lambda: Week.last_week_of_year(10000))