2009
2009
class TestFSetMtime(tests.TestCaseInTempDir):
2011
def test__utime_fset_mtime(self):
2011
def _check_fset_mtime(self, func):
2012
2012
f = open('test', 'wb')
2014
2014
mtime = os.fstat(f.fileno()).st_mtime
2015
2015
new_mtime = mtime - 20
2016
osutils._utime_fset_mtime(f, new_mtime)
2019
self.assertEqual(int(new_mtime), int(os.lstat('test').st_mtime))
2021
def test_fset_mtime(self):
2022
f = open('test', 'wb')
2023
new_mtime = time.time()-20.0
2025
mtime = os.fstat(f.fileno()).st_mtime
2026
osutils.fset_mtime(f, new_mtime)
2029
2019
self.assertNotEqual(mtime, new_mtime)
2030
# We don't guarantee any better than 1s resolution, though we try to
2020
set_mtime = os.lstat('test').st_mtime
2021
# We don't guarantee any better than 2s resolution, due to timestamp
2022
# precision limitations on older filesystems such as FAT, but try to
2031
2023
# use functions that have at least microsecond resolution (1us on
2032
2024
# POSIX, 100ns on Windows)
2033
self.assertEqual(int(new_mtime), int(os.lstat('test').st_mtime))
2025
self.assertFalse(int((new_mtime - set_mtime) / 2),
2026
"%r != %r within two seconds" % (new_mtime, set_mtime))
2028
def test_fset_mtime(self):
2029
self._check_fset_mtime(osutils.fset_mtime)
2030
if osutils.fset_mtime is not osutils._utime_fset_mtime:
2031
self._check_fset_mtime(osutils._utime_fset_mtime)