Skip to content

Commit 489c61a

Browse files
committed
Allow tests to pass after 2038
without this change, the python-apache-libcloud tests failed in the year 2039 with fp.write(struct.pack("<ll", mtime, size)) E error: 'l' format requires -2147483648 <= number <= 2147483647
1 parent 0f3d630 commit 489c61a

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

changelog/4903.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix handling of mtime to work after year 2038

src/_pytest/assertion/rewrite.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,9 +344,9 @@ def _write_pyc(state, co, source_stat, pyc):
344344
try:
345345
with atomicwrites.atomic_write(pyc, mode="wb", overwrite=True) as fp:
346346
fp.write(imp.get_magic())
347-
mtime = int(source_stat.mtime)
347+
mtime = int(source_stat.mtime) & 0xFFFFFFFF
348348
size = source_stat.size & 0xFFFFFFFF
349-
fp.write(struct.pack("<ll", mtime, size))
349+
fp.write(struct.pack("<LL", mtime, size))
350350
fp.write(marshal.dumps(co))
351351
except EnvironmentError as e:
352352
state.trace("error writing pyc file at %s: errno=%s" % (pyc, e.errno))
@@ -441,7 +441,7 @@ def _read_pyc(source, pyc, trace=lambda x: None):
441441
if (
442442
len(data) != 12
443443
or data[:4] != imp.get_magic()
444-
or struct.unpack("<ll", data[4:]) != (mtime, size)
444+
or struct.unpack("<LL", data[4:]) != (mtime & 0xFFFFFFFF, size & 0xFFFFFFFF)
445445
):
446446
trace("_read_pyc(%s): invalid or out of date pyc" % source)
447447
return None

0 commit comments

Comments
 (0)