0
私はdkfileutils
からPath.touchためのテストを書いている:time.time()とfile.getmtime()の関係は?
class Path(str):
def touch(self, mode=0o666, exist_ok=True):
"""Create this file with the given access mode, if it doesn't exist.
(based on https://github.com/python/cpython/blob/master/Lib/pathlib.py)
"""
if exist_ok:
# First try to bump modification time
# Implementation note: GNU touch uses the UTIME_NOW option of
# the utimensat()/futimens() functions.
try:
os.utime(self, None)
except OSError:
# Avoid exception chaining
pass
else:
return
flags = os.O_CREAT | os.O_WRONLY
if not exist_ok:
flags |= os.O_EXCL
fd = os.open(self, flags, mode)
os.close(fd)
私は..
def test_touch():
before = time.time()
with open('a', 'w') as fp:
fp.write('a')
after = time.time()
assert before <= after
a = Path('a')
a_before_touch = a.getmtime()
assert before <= a_before_touch <= after
a.touch()
after_touch = time.time()
a_after_touch = a.getmtime()
assert a_before_touch <= a_after_touch
assert a_after_touch >= after
assert a_after_touch <= after_touch
を以下のバリエーションを試してみましたが、それは(https://travis-ci.org/datakortet/dkfileutils/builds)失敗し続け、68を実行します。
を> assert before <= a_before_touch <= after
E assert 1489532961.064958 <= 1489532961.064464
ラン67
> assert a_after_touch > after
E assert 1489532462.412086 > 1489532462.412933
ラン66
> assert a_after_touch > after
E assert 1489532286.6042855 > 1489532286.606766
アムそのtime.time()とfile.getmtimeを想定しで私は愚かな()に関連していますか?