mirror of
https://github.com/python/cpython.git
synced 2025-11-02 11:08:57 +00:00
Issue #13964: Skip os.*utime*() tests if os.stat() doesn't support timestamp
with a subsecond resolution
This commit is contained in:
parent
a2f7c00638
commit
1aa54a417d
2 changed files with 11 additions and 1 deletions
|
|
@ -27,6 +27,14 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
threading = None
|
threading = None
|
||||||
|
|
||||||
|
os.stat_float_times(True)
|
||||||
|
st = os.stat(__file__)
|
||||||
|
stat_supports_subsecond = (
|
||||||
|
# check if float and int timestamps are different
|
||||||
|
(st.st_atime != st[7])
|
||||||
|
or (st.st_mtime != st[8])
|
||||||
|
or (st.st_ctime != st[9]))
|
||||||
|
|
||||||
# Detect whether we're on a Linux system that uses the (now outdated
|
# Detect whether we're on a Linux system that uses the (now outdated
|
||||||
# and unmaintained) linuxthreads threading library. There's an issue
|
# and unmaintained) linuxthreads threading library. There's an issue
|
||||||
# when combining linuxthreads with a failed execv call: see
|
# when combining linuxthreads with a failed execv call: see
|
||||||
|
|
@ -300,6 +308,8 @@ class StatAttributeTests(unittest.TestCase):
|
||||||
st2 = os.stat(support.TESTFN)
|
st2 = os.stat(support.TESTFN)
|
||||||
self.assertAlmostEqual(st1.st_mtime, st2.st_mtime, delta=10)
|
self.assertAlmostEqual(st1.st_mtime, st2.st_mtime, delta=10)
|
||||||
|
|
||||||
|
@unittest.skipUnless(stat_supports_subsecond,
|
||||||
|
"os.stat() doesn't has a subsecond resolution")
|
||||||
def _test_utime_subsecond(self, set_time_func):
|
def _test_utime_subsecond(self, set_time_func):
|
||||||
asec, amsec = 1, 901
|
asec, amsec = 1, 901
|
||||||
atime = asec + amsec * 1e-3
|
atime = asec + amsec * 1e-3
|
||||||
|
|
@ -308,6 +318,7 @@ class StatAttributeTests(unittest.TestCase):
|
||||||
filename = self.fname
|
filename = self.fname
|
||||||
os.utime(filename, (0, 0))
|
os.utime(filename, (0, 0))
|
||||||
set_time_func(filename, atime, mtime)
|
set_time_func(filename, atime, mtime)
|
||||||
|
os.stat_float_times(True)
|
||||||
st = os.stat(filename)
|
st = os.stat(filename)
|
||||||
self.assertAlmostEqual(st.st_atime, atime, places=3)
|
self.assertAlmostEqual(st.st_atime, atime, places=3)
|
||||||
self.assertAlmostEqual(st.st_mtime, mtime, places=3)
|
self.assertAlmostEqual(st.st_mtime, mtime, places=3)
|
||||||
|
|
|
||||||
|
|
@ -3539,7 +3539,6 @@ extract_time(PyObject *t, time_t* sec, long* nsec)
|
||||||
mod = fmod(d, 1.0);
|
mod = fmod(d, 1.0);
|
||||||
mod *= 1e9;
|
mod *= 1e9;
|
||||||
*nsec = (long)mod;
|
*nsec = (long)mod;
|
||||||
printf("%g => (%u, %li)\n", d, *sec, *nsec);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#if SIZEOF_TIME_T > SIZEOF_LONG
|
#if SIZEOF_TIME_T > SIZEOF_LONG
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue