Author: Ronan Lamy <[email protected]>
Branch: follow_symlinks
Changeset: r83311:8d4f69eaa804
Date: 2016-03-24 04:30 +0000
http://bitbucket.org/pypy/pypy/changeset/8d4f69eaa804/
Log: Test and fix convert_seconds()
diff --git a/pypy/module/posix/interp_posix.py
b/pypy/module/posix/interp_posix.py
--- a/pypy/module/posix/interp_posix.py
+++ b/pypy/module/posix/interp_posix.py
@@ -1250,11 +1250,11 @@
def convert_seconds(space, w_time):
if space.isinstance_w(w_time, space.w_float):
time = space.float_w(w_time)
- intpart, floatpart = modf(time)
- if floatpart < 0:
- floatpart += 1.
+ fracpart, intpart = modf(time)
+ if fracpart < 0:
+ fracpart += 1.
intpart -= 1.
- return int(intpart), int(floatpart*1e9)
+ return int(intpart), int(fracpart*1e9)
else:
time = space.int_w(w_time)
return time, 0
diff --git a/pypy/module/posix/test/test_posix2.py
b/pypy/module/posix/test/test_posix2.py
--- a/pypy/module/posix/test/test_posix2.py
+++ b/pypy/module/posix/test/test_posix2.py
@@ -2,16 +2,22 @@
# -*- coding: utf-8 -*-
from __future__ import with_statement
+import os
+import py
+import sys
+import signal
+
from pypy.objspace.std import StdObjSpace
from rpython.tool.udir import udir
from pypy.tool.pytest.objspace import gettestobjspace
from pypy.conftest import pypydir
from rpython.translator.c.test.test_extfunc import need_sparse_files
from rpython.rlib import rposix
-import os
-import py
-import sys
-import signal
+from pypy.module.posix.interp_posix import convert_seconds
+
+from hypothesis import given
+from hypothesis.strategies import integers
+
def setup_module(mod):
usemodules = ['binascii', 'posix', 'signal', 'struct', 'time']
@@ -540,6 +546,9 @@
assert os.stat(path).st_atime > t0
os.utime(path, (int(t0), int(t0)))
assert int(os.stat(path).st_atime) == int(t0)
+ t1 = time()
+ os.utime(path, (int(t1), int(t1)))
+ assert int(os.stat(path).st_atime) == int(t1)
def test_utime_raises(self):
os = self.posix
@@ -1272,3 +1281,15 @@
if os.name == 'posix':
assert os.open in os.supports_dir_fd # openat()
+def test_convert_seconds_simple(space):
+ w_time = space.wrap(123.456)
+ assert convert_seconds(space, w_time) == (123, 456000000)
+
+@given(s=integers(min_value=-2**30, max_value=2**30), ns=integers(min_value=0,
max_value=10**9))
+def test_convert_seconds_full(space, s, ns):
+ w_time = space.wrap(s + ns * 1e-9)
+ sec, nsec = convert_seconds(space, w_time)
+ assert 0 <= nsec < 1e9
+ MAX_ERR = 1e9 / 2**23 + 1 # nsec has 53 - 30 = 23 bits of precisin
+ err = (sec * 10**9 + nsec) - (s * 10**9 + ns)
+ assert -MAX_ERR < err < MAX_ERR
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit