Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bb6694d

Browse files
committed
Try to fix issue #19715 (timestamp rounding inconsistencies under Windows?)
1 parent 74193af commit bb6694d

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

Lib/test/test_pathlib.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,11 +1388,15 @@ def test_touch_common(self):
13881388
# Rewind the mtime sufficiently far in the past to work around
13891389
# filesystem-specific timestamp granularity.
13901390
os.utime(str(p), (old_mtime - 10, old_mtime - 10))
1391-
# The file mtime is refreshed by calling touch() again
1391+
# The file mtime should be refreshed by calling touch() again
13921392
p.touch()
13931393
st = p.stat()
1394-
self.assertGreaterEqual(st.st_mtime_ns, old_mtime_ns)
1395-
self.assertGreaterEqual(st.st_mtime, old_mtime)
1394+
# Issue #19715: there can be an inconsistency under Windows between
1395+
# the timestamp rounding when creating a file, and the timestamp
1396+
# rounding done when calling utime(). `delta` makes up for this.
1397+
delta = 1e-6 if os.name == 'nt' else 0
1398+
self.assertGreaterEqual(st.st_mtime, old_mtime - delta)
1399+
# Now with exist_ok=False
13961400
p = P / 'newfileB'
13971401
self.assertFalse(p.exists())
13981402
p.touch(mode=0o700, exist_ok=False)

0 commit comments

Comments
 (0)