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

Method test_today

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

Source from the content-addressed store, hash-verified

1458 self.theclass.fromtimestamp(None)
1459
1460 def test_today(self):
1461 import time
1462
1463 # We claim that today() is like fromtimestamp(time.time()), so
1464 # prove it.
1465 for dummy in range(3):
1466 today = self.theclass.today()
1467 ts = time.time()
1468 todayagain = self.theclass.fromtimestamp(ts)
1469 if today == todayagain:
1470 break
1471 # There are several legit reasons that could fail:
1472 # 1. It recently became midnight, between the today() and the
1473 # time() calls.
1474 # 2. The platform time() has such fine resolution that we'll
1475 # never get the same value twice.
1476 # 3. The platform time() has poor resolution, and we just
1477 # happened to call today() right before a resolution quantum
1478 # boundary.
1479 # 4. The system clock got fiddled between calls.
1480 # In any case, wait a little while and try again.
1481 time.sleep(0.1)
1482
1483 # It worked or it didn't. If it didn't, assume it's reason #2, and
1484 # let the test pass if they're within half a second of each other.
1485 if today != todayagain:
1486 self.assertAlmostEqual(todayagain, today,
1487 delta=timedelta(seconds=0.5))
1488
1489 def test_weekday(self):
1490 for i in range(7):

Callers

nothing calls this directly

Calls 6

timedeltaClass · 0.90
todayMethod · 0.80
timeMethod · 0.45
fromtimestampMethod · 0.45
sleepMethod · 0.45
assertAlmostEqualMethod · 0.45

Tested by

no test coverage detected