Skip to content

Commit bd70f5c

Browse files
committed
Add test for mtime issue in #4903
1 parent 7441652 commit bd70f5c

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

testing/test_assertrewrite.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,6 +1197,29 @@ def test_simple_failure():
11971197
result.stdout.fnmatch_lines("*E*assert (1 + 1) == 3")
11981198

11991199

1200+
@pytest.mark.parametrize("offset", [-1, +1])
1201+
def test_source_mtime_long_long(testdir, offset):
1202+
"""Support modification dates after 2038 in rewritten files (#4903).
1203+
1204+
pytest would crash with:
1205+
1206+
fp.write(struct.pack("<ll", mtime, size))
1207+
E struct.error: argument out of range
1208+
"""
1209+
p = testdir.makepyfile(
1210+
"""
1211+
def test(): pass
1212+
"""
1213+
)
1214+
# use unsigned long timestamp which overflows signed long,
1215+
# which was the cause of the bug
1216+
# +1 offset also tests masking of 0xFFFFFFFF
1217+
timestamp = 2 ** 32 + offset
1218+
os.utime(str(p), (timestamp, timestamp))
1219+
result = testdir.runpytest()
1220+
assert result.ret == 0
1221+
1222+
12001223
def test_rewrite_infinite_recursion(testdir, pytestconfig, monkeypatch):
12011224
"""Fix infinite recursion when writing pyc files: if an import happens to be triggered when writing the pyc
12021225
file, this would cause another call to the hook, which would trigger another pyc writing, which could

0 commit comments

Comments
 (0)