MCPcopy Create free account
hub / github.com/Distributive-Network/PythonMonkey / test_eval_dates

Function test_eval_dates

tests/python/test_pythonmonkey_eval.py:58–70  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

56
57
58def test_eval_dates():
59 MIN_YEAR = 1 # https://docs.python.org/3/library/datetime.html#datetime.MINYEAR
60 MAX_YEAR = 2023
61 start = datetime(MIN_YEAR, 1, 1, 00, 00, 00, tzinfo=timezone.utc)
62 years = MAX_YEAR - MIN_YEAR + 1
63 end = start + timedelta(days=365 * years)
64 for _ in range(10):
65 py_date = start + (end - start) * random.random()
66 # round to milliseconds precision because the smallest unit for js Date is 1ms
67 # microsecond must be in 0..999999, but it would be rounded to 1000000 if >= 999500
68 py_date = py_date.replace(microsecond=min(round(py_date.microsecond, -3), 999000))
69 js_date = pm.eval(f'new Date("{py_date.isoformat()}")')
70 assert py_date == js_date
71
72
73def test_eval_boxed_booleans():

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected