MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_ordinal_conversions

Method test_ordinal_conversions

Lib/test/datetimetester.py:1252–1297  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1250 self.assertEqual(repr(td), "SubclassDate(2010, 10, 10)")
1251
1252 def test_ordinal_conversions(self):
1253 # Check some fixed values.
1254 for y, m, d, n in [(1, 1, 1, 1), # calendar origin
1255 (1, 12, 31, 365),
1256 (2, 1, 1, 366),
1257 # first example from "Calendrical Calculations"
1258 (1945, 11, 12, 710347)]:
1259 d = self.theclass(y, m, d)
1260 self.assertEqual(n, d.toordinal())
1261 fromord = self.theclass.fromordinal(n)
1262 self.assertEqual(d, fromord)
1263 if hasattr(fromord, "hour"):
1264 # if we're checking something fancier than a date, verify
1265 # the extra fields have been zeroed out
1266 self.assertEqual(fromord.hour, 0)
1267 self.assertEqual(fromord.minute, 0)
1268 self.assertEqual(fromord.second, 0)
1269 self.assertEqual(fromord.microsecond, 0)
1270
1271 # Check first and last days of year spottily across the whole
1272 # range of years supported.
1273 for year in range(MINYEAR, MAXYEAR+1, 7):
1274 # Verify (year, 1, 1) -> ordinal -> y, m, d is identity.
1275 d = self.theclass(year, 1, 1)
1276 n = d.toordinal()
1277 d2 = self.theclass.fromordinal(n)
1278 self.assertEqual(d, d2)
1279 # Verify that moving back a day gets to the end of year-1.
1280 if year > 1:
1281 d = self.theclass.fromordinal(n-1)
1282 d2 = self.theclass(year-1, 12, 31)
1283 self.assertEqual(d, d2)
1284 self.assertEqual(d2.toordinal(), n-1)
1285
1286 # Test every day in a leap-year and a non-leap year.
1287 dim = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
1288 for year, isleap in (2000, True), (2002, False):
1289 n = self.theclass(year, 1, 1).toordinal()
1290 for month, maxday in zip(range(1, 13), dim):
1291 if month == 2 and isleap:
1292 maxday += 1
1293 for day in range(1, maxday+1):
1294 d = self.theclass(year, month, day)
1295 self.assertEqual(d.toordinal(), n)
1296 self.assertEqual(d, self.theclass.fromordinal(n))
1297 n += 1
1298
1299 def test_extreme_ordinals(self):
1300 a = self.theclass.min

Callers

nothing calls this directly

Calls 4

hasattrFunction · 0.85
toordinalMethod · 0.80
fromordinalMethod · 0.80
assertEqualMethod · 0.45

Tested by

no test coverage detected