[pypy-commit] pypy py3k: Merged py3k branch.
prestontimmons
noreply at buildbot.pypy.org
Wed Mar 14 19:34:50 CET 2012
Author: Preston Timmons <prestontimmons at gmail.com>
Branch: py3k
Changeset: r53576:578aa6ac3460
Date: 2012-03-14 18:12 +0000
http://bitbucket.org/pypy/pypy/changeset/578aa6ac3460/
Log: Merged py3k branch.
diff --git a/pypy/module/_socket/test/test_sock_app.py b/pypy/module/_socket/test/test_sock_app.py
--- a/pypy/module/_socket/test/test_sock_app.py
+++ b/pypy/module/_socket/test/test_sock_app.py
@@ -302,7 +302,7 @@
def test_ntoa_exception(self):
import _socket
- raises(_socket.error, _socket.inet_ntoa, "ab")
+ raises(_socket.error, _socket.inet_ntoa, b"ab")
def test_aton_exceptions(self):
import _socket
@@ -319,7 +319,7 @@
[(_socket.AF_INET + _socket.AF_INET6, b"", _socket.error),
(_socket.AF_INET, b"a", ValueError),
(_socket.AF_INET6, b"a", ValueError),
- (_socket.AF_INET, u"aa\u2222a", TypeError)]:
+ (_socket.AF_INET, "aa\u2222a", TypeError)]:
raises(exception, _socket.inet_ntop, family, packed)
def test_pton_exceptions(self):
@@ -380,7 +380,7 @@
# connection.
try:
s.connect(("www.python.org", 80))
- except _socket.gaierror, ex:
+ except _socket.gaierror as ex:
skip("GAIError - probably no connection: %s" % str(ex.args))
name = s.getpeername() # Will raise socket.error if not connected
assert name[1] == 80
@@ -420,7 +420,7 @@
sizes = {socket.htonl: 32, socket.ntohl: 32,
socket.htons: 16, socket.ntohs: 16}
for func, size in sizes.items():
- mask = (1L<<size) - 1
+ mask = (1<<size) - 1
for i in (0, 1, 0xffff, ~0xffff, 2, 0x01234567, 0x76543210):
assert i & mask == func(func(i&mask)) & mask
@@ -448,7 +448,7 @@
socket.htons: 16, socket.ntohs: 16}
for func, size in sizes.items():
try:
- func(1L << size)
+ func(1 << size)
except OverflowError:
pass
else:
@@ -515,12 +515,12 @@
# connection.
try:
s.connect(("www.python.org", 80))
- except _socket.gaierror, ex:
+ except _socket.gaierror as ex:
skip("GAIError - probably no connection: %s" % str(ex.args))
s.send(buffer(b''))
s.sendall(buffer(b''))
- raises(TypeError, s.send, u'')
- raises(TypeError, s.sendall, u'')
+ raises(TypeError, s.send, '')
+ raises(TypeError, s.sendall, '')
s.close()
s = _socket.socket(_socket.AF_INET, _socket.SOCK_DGRAM, 0)
s.sendto(buffer(b''), ('localhost', 9)) # Send to discard port.
diff --git a/pypy/module/exceptions/test/test_exc.py b/pypy/module/exceptions/test/test_exc.py
--- a/pypy/module/exceptions/test/test_exc.py
+++ b/pypy/module/exceptions/test/test_exc.py
@@ -83,7 +83,7 @@
assert str(ut) == "can't translate characters in position 1-4: bah"
ut.start = 4
ut.object = '012345'
- assert str(ut) == "can't translate character u'\\x34' in position 4: bah"
+ assert str(ut) == "can't translate character '\\x34' in position 4: bah"
ut.object = []
assert ut.object == []
@@ -163,7 +163,7 @@
assert ue.object == 'z9'
assert str(ue) == "'x' codec can't encode characters in position 1-4: bah"
ue.end = 2
- assert str(ue) == "'x' codec can't encode character u'\\x39' in position 1: bah"
+ assert str(ue) == "'x' codec can't encode character '\\x39' in position 1: bah"
ue.object = []
assert ue.object == []
raises(TypeError, UnicodeEncodeError, "x", b"y", 1, 5, "bah")
diff --git a/pypy/module/itertools/__init__.py b/pypy/module/itertools/__init__.py
--- a/pypy/module/itertools/__init__.py
+++ b/pypy/module/itertools/__init__.py
@@ -10,7 +10,6 @@
repeat(elem [,n]) --> elem, elem, elem, ... endlessly or up to n times
Iterators terminating on the shortest input sequence:
- izip(p, q, ...) --> (p[0], q[0]), (p[1], q[1]), ...
ifilter(pred, seq) --> elements of seq where pred(elem) is True
ifilterfalse(pred, seq) --> elements of seq where pred(elem) is False
islice(seq, [start,] stop [, step]) --> elements from
@@ -37,14 +36,13 @@
'ifilterfalse' : 'interp_itertools.W_IFilterFalse',
'imap' : 'interp_itertools.W_IMap',
'islice' : 'interp_itertools.W_ISlice',
- 'izip' : 'interp_itertools.W_IZip',
- 'izip_longest' : 'interp_itertools.W_IZipLongest',
'permutations' : 'interp_itertools.W_Permutations',
'product' : 'interp_itertools.W_Product',
'repeat' : 'interp_itertools.W_Repeat',
'starmap' : 'interp_itertools.W_StarMap',
'takewhile' : 'interp_itertools.W_TakeWhile',
'tee' : 'interp_itertools.tee',
+ 'zip_longest' : 'interp_itertools.W_ZipLongest',
}
appleveldefs = {
diff --git a/pypy/module/itertools/interp_itertools.py b/pypy/module/itertools/interp_itertools.py
--- a/pypy/module/itertools/interp_itertools.py
+++ b/pypy/module/itertools/interp_itertools.py
@@ -67,8 +67,7 @@
__doc__ = """Make an iterator that returns consecutive integers starting
with n. If not specified n defaults to zero. Does not currently
support python long integers. Often used as an argument to imap()
- to generate consecutive data points. Also, used with izip() to
- add sequence numbers.
+ to generate consecutive data points.
Equivalent to :
@@ -127,8 +126,7 @@
__doc__ = """Make an iterator that returns object over and over again.
Runs indefinitely unless the times argument is specified. Used
as argument to imap() for invariant parameters to the called
- function. Also used with izip() to create an invariant part of a
- tuple record.
+ function.
Equivalent to :
@@ -581,45 +579,8 @@
""")
-class W_IZip(W_IMap):
- _error_name = "izip"
-
- def next_w(self):
- # argh. izip(*args) is almost like imap(None, *args) except
- # that the former needs a special case for len(args)==0
- # while the latter just raises a TypeError in this situation.
- if len(self.iterators_w) == 0:
- raise OperationError(self.space.w_StopIteration, self.space.w_None)
- return W_IMap.next_w(self)
-
-def W_IZip___new__(space, w_subtype, args_w):
- r = space.allocate_instance(W_IZip, w_subtype)
- r.__init__(space, space.w_None, args_w)
- return space.wrap(r)
-
-W_IZip.typedef = TypeDef(
- 'izip',
- __module__ = 'itertools',
- __new__ = interp2app(W_IZip___new__),
- __iter__ = interp2app(W_IZip.iter_w),
- __next__ = interp2app(W_IZip.next_w),
- __doc__ = """Make an iterator that aggregates elements from each of the
- iterables. Like zip() except that it returns an iterator instead
- of a list. Used for lock-step iteration over several iterables at
- a time.
-
- Equivalent to :
-
- def izip(*iterables):
- iterables = map(iter, iterables)
- while iterables:
- result = [i.next() for i in iterables]
- yield tuple(result)
- """)
-
-
-class W_IZipLongest(W_IMap):
- _error_name = "izip_longest"
+class W_ZipLongest(W_IMap):
+ _error_name = "zip_longest"
def next_w(self):
space = self.space
@@ -648,7 +609,7 @@
objects_w[index] = w_value
return space.newtuple(objects_w)
-def W_IZipLongest___new__(space, w_subtype, __args__):
+def W_ZipLongest___new__(space, w_subtype, __args__):
arguments_w, kwds_w = __args__.unpack()
w_fillvalue = space.w_None
if kwds_w:
@@ -657,22 +618,22 @@
del kwds_w["fillvalue"]
if kwds_w:
raise OperationError(space.w_TypeError, space.wrap(
- "izip_longest() got unexpected keyword argument(s)"))
+ "zip_longest() got unexpected keyword argument(s)"))
- self = space.allocate_instance(W_IZipLongest, w_subtype)
+ self = space.allocate_instance(W_ZipLongest, w_subtype)
self.__init__(space, space.w_None, arguments_w)
self.w_fillvalue = w_fillvalue
self.active = len(self.iterators_w)
return space.wrap(self)
-W_IZipLongest.typedef = TypeDef(
- 'izip_longest',
+W_ZipLongest.typedef = TypeDef(
+ 'zip_longest',
__module__ = 'itertools',
- __new__ = interp2app(W_IZipLongest___new__),
- __iter__ = interp2app(W_IZipLongest.iter_w),
- __next__ = interp2app(W_IZipLongest.next_w),
- __doc__ = """Return an izip_longest object whose .next() method returns a tuple where
+ __new__ = interp2app(W_ZipLongest___new__),
+ __iter__ = interp2app(W_ZipLongest.iter_w),
+ __next__ = interp2app(W_ZipLongest.next_w),
+ __doc__ = """Return a zip_longest object whose .next() method returns a tuple where
the i-th element comes from the i-th iterable argument. The .next()
method continues until the longest iterable in the argument sequence
is exhausted and then it raises StopIteration. When the shorter iterables
@@ -1068,7 +1029,7 @@
def compress(data, selectors):
# compress('ABCDEF', [1,0,1,0,1,1]) --> A C E F
- return (d for d, s in izip(data, selectors) if s)
+ return (d for d, s in zip(data, selectors) if s)
""")
diff --git a/pypy/module/itertools/test/test_itertools.py b/pypy/module/itertools/test/test_itertools.py
--- a/pypy/module/itertools/test/test_itertools.py
+++ b/pypy/module/itertools/test/test_itertools.py
@@ -356,53 +356,6 @@
raises(TypeError, itertools.imap, bool)
raises(TypeError, itertools.imap, 42)
- def test_izip(self):
- import itertools
-
- it = itertools.izip()
- raises(StopIteration, next, it)
-
- obj_list = [object(), object(), object()]
- it = itertools.izip(obj_list)
- for x in obj_list:
- assert next(it) == (x, )
- raises(StopIteration, next, it)
-
- it = itertools.izip([1, 2, 3], [4], [5, 6])
- assert next(it) == (1, 4, 5)
- raises(StopIteration, next, it)
-
- it = itertools.izip([], [], [1], [])
- raises(StopIteration, next, it)
-
- # Up to one additional item may be consumed per iterable, as per python docs
- it1 = iter([1, 2, 3, 4, 5, 6])
- it2 = iter([5, 6])
- it = itertools.izip(it1, it2)
- for x in [(1, 5), (2, 6)]:
- assert next(it) == x
- raises(StopIteration, next, it)
- assert next(it1) in [3, 4]
- #---does not work in CPython 2.5
- #raises(StopIteration, it.next)
- #assert it1.next() in [4, 5]
-
- def test_izip_wrongargs(self):
- import itertools, re
-
- # Duplicate python 2.4 behaviour for invalid arguments
- raises(TypeError, itertools.izip, None, 0)
-
- # The error message should indicate which argument was dodgy
- for x in range(10):
- args = [()] * x + [None] + [()] * (9 - x)
- try:
- itertools.izip(*args)
- except TypeError as e:
- assert str(e).find("#" + str(x + 1) + " ") >= 0
- else:
- fail("TypeError expected")
-
def test_cycle(self):
import itertools
@@ -613,7 +566,6 @@
itertools.ifilterfalse(None, []),
itertools.imap(None, []),
itertools.islice([], 0),
- itertools.izip(),
itertools.repeat(None),
itertools.starmap(bool, []),
itertools.takewhile(bool, []),
@@ -641,7 +593,6 @@
itertools.ifilterfalse,
itertools.imap,
itertools.islice,
- itertools.izip,
itertools.repeat,
itertools.starmap,
itertools.takewhile,
@@ -704,8 +655,8 @@
raises(ValueError, combinations, "abc", -2)
assert list(combinations(range(4), 3)) == [(0, 1, 2), (0, 1, 3), (0, 2, 3), (1, 2, 3)]
- def test_iziplongest(self):
- from itertools import izip_longest, islice, count
+ def test_ziplongest(self):
+ from itertools import zip_longest, islice, count
for args in [
['abc', range(6)],
[range(6), 'abc'],
@@ -717,29 +668,29 @@
# this is the replacement:
target = [tuple([arg[i] if i < len(arg) else None for arg in args])
for i in range(max(map(len, args)))]
- assert list(izip_longest(*args)) == target
- assert list(izip_longest(*args, **{})) == target
+ assert list(zip_longest(*args)) == target
+ assert list(zip_longest(*args, **{})) == target
# Replace None fills with 'X'
target = [tuple((e is None and 'X' or e) for e in t) for t in target]
- assert list(izip_longest(*args, **dict(fillvalue='X'))) == target
+ assert list(zip_longest(*args, **dict(fillvalue='X'))) == target
# take 3 from infinite input
- assert (list(islice(izip_longest('abcdef', count()),3)) ==
+ assert (list(islice(zip_longest('abcdef', count()),3)) ==
zip('abcdef', range(3)))
- assert list(izip_longest()) == zip()
- assert list(izip_longest([])) == zip([])
- assert list(izip_longest('abcdef')) == zip('abcdef')
+ assert list(zip_longest()) == zip()
+ assert list(zip_longest([])) == zip([])
+ assert list(zip_longest('abcdef')) == zip('abcdef')
- assert (list(izip_longest('abc', 'defg', **{})) ==
+ assert (list(zip_longest('abc', 'defg', **{})) ==
zip(list('abc') + [None], 'defg')) # empty keyword dict
- raises(TypeError, izip_longest, 3)
- raises(TypeError, izip_longest, range(3), 3)
+ raises(TypeError, zip_longest, 3)
+ raises(TypeError, zip_longest, range(3), 3)
for stmt in [
- "izip_longest('abc', fv=1)",
- "izip_longest('abc', fillvalue=1, bogus_keyword=None)",
+ "zip_longest('abc', fv=1)",
+ "zip_longest('abc', fillvalue=1, bogus_keyword=None)",
]:
try:
eval(stmt, globals(), locals())
@@ -748,7 +699,7 @@
else:
self.fail('Did not raise Type in: ' + stmt)
- def test_izip_longest2(self):
+ def test_zip_longest2(self):
import itertools
class Repeater(object):
# this class is similar to itertools.repeat
@@ -771,7 +722,7 @@
r2 = Repeater(2, 4, StopIteration)
def run(r1, r2):
result = []
- for i, j in itertools.izip_longest(r1, r2, fillvalue=0):
+ for i, j in itertools.zip_longest(r1, r2, fillvalue=0):
result.append((i, j))
return result
assert run(r1, r2) == [(1,2), (1,2), (1,2), (0,2)]
@@ -939,7 +890,7 @@
assert list(combinations_with_replacement([], 2)) == []
assert list(combinations_with_replacement([], 0)) == [()]
- def test_izip_longest3(self):
+ def test_zip_longest3(self):
import itertools
class Repeater(object):
# this class is similar to itertools.repeat
@@ -960,7 +911,7 @@
# and StopIteration would stop as expected
r1 = Repeater(1, 3, RuntimeError)
r2 = Repeater(2, 4, StopIteration)
- it = itertools.izip_longest(r1, r2, fillvalue=0)
+ it = itertools.zip_longest(r1, r2, fillvalue=0)
assert next(it) == (1, 2)
assert next(it) == (1, 2)
assert next(it)== (1, 2)
@@ -987,9 +938,7 @@
assert type(A.from_iterable([])) is A
class A(itertools.imap): pass
assert type(A(lambda: 5, [])) is A
- class A(itertools.izip): pass
- assert type(A([], [])) is A
- class A(itertools.izip_longest): pass
+ class A(itertools.zip_longest): pass
assert type(A([], [])) is A
class A(itertools.cycle): pass
assert type(A([])) is A
diff --git a/pypy/module/math/interp_math.py b/pypy/module/math/interp_math.py
--- a/pypy/module/math/interp_math.py
+++ b/pypy/module/math/interp_math.py
@@ -381,6 +381,7 @@
def log1p(space, w_x):
"""Find log(x + 1)."""
+ x = _get_double(space, w_x)
try:
return math1(space, rfloat.log1p, w_x)
except OperationError as e:
diff --git a/pypy/module/math/test/test_math.py b/pypy/module/math/test/test_math.py
--- a/pypy/module/math/test/test_math.py
+++ b/pypy/module/math/test/test_math.py
@@ -105,6 +105,8 @@
self.ftest(math.log1p(0), 0)
self.ftest(math.log1p(math.e-1), 1)
self.ftest(math.log1p(1), math.log(2))
+ raises(ValueError, math.log1p, -1)
+ raises(ValueError, math.log1p, -100)
def test_acosh(self):
import math
@@ -207,8 +209,8 @@
fail_fmt = "{}:{}({!r}): expected {!r}, got {!r}"
failures = []
- math_testcases = os.path.join(os.path.dirname(abc.__file__), "test",
- "math_testcases.txt")
+ math_testcases = os.path.join(os.path.dirname(abc.__file__),
+ "../test/math_testcases.txt")
for id, fn, arg, expected, flags in _parse_mtestfile(math_testcases):
func = getattr(math, fn)
diff --git a/pypy/module/posix/__init__.py b/pypy/module/posix/__init__.py
--- a/pypy/module/posix/__init__.py
+++ b/pypy/module/posix/__init__.py
@@ -35,9 +35,6 @@
appleveldefs = {
'error' : 'app_posix.error',
'stat_result': 'app_posix.stat_result',
- 'tmpfile' : 'app_posix.tmpfile',
- 'tmpnam' : 'app_posix.tmpnam',
- 'tempnam' : 'app_posix.tempnam',
}
if os.name == 'nt':
appleveldefs.update({
@@ -73,7 +70,7 @@
'unlink' : 'interp_posix.unlink',
'remove' : 'interp_posix.remove',
'getcwd' : 'interp_posix.getcwd',
- 'getcwdu' : 'interp_posix.getcwdu',
+ 'getcwdb' : 'interp_posix.getcwdb',
'chdir' : 'interp_posix.chdir',
'mkdir' : 'interp_posix.mkdir',
'rmdir' : 'interp_posix.rmdir',
diff --git a/pypy/module/posix/app_posix.py b/pypy/module/posix/app_posix.py
--- a/pypy/module/posix/app_posix.py
+++ b/pypy/module/posix/app_posix.py
@@ -78,39 +78,6 @@
# XXX for the moment
return
-def tmpfile():
- """Create a temporary file.
-
- The data in the file is freed when you
- close the file, or automatically by the OS when the program ends."""
- import tempfile
- f = tempfile.TemporaryFile()
- if osname == 'nt':
- f = f.file # on NT, with the 2.4 stdlib of CPython,
- # we get a _TemporaryFileWrapper for no good reason
- return f
-
-
-def tmpnam():
- """Return an absolute pathname of a file that did not exist at the
- time the call is made."""
- from warnings import warn
- warn(RuntimeWarning("tmpnam is a potential security risk to your program"))
-
- import tempfile
- return tempfile.mktemp()
-
-def tempnam(dir=None, prefix=None):
- """Return an absolute pathname of a file that did not exist at the
- time the call is made. The directory and a prefix may be specified
- as strings; they may be omitted or None if not needed."""
- from warnings import warn
- warn(RuntimeWarning("tempnam is a potential security risk to your program"))
-
- import tempfile
- return tempfile.mktemp('', prefix or 'tmp', dir)
-
-
if osname == 'posix':
def wait():
""" wait() -> (pid, status)
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
@@ -409,29 +409,29 @@
else:
return w_fullpath
-def getcwd(space):
+def getcwdb(space):
"""Return the current working directory."""
try:
cur = os.getcwd()
except OSError, e:
raise wrap_oserror(space, e)
else:
- return space.wrap(cur)
+ return space.wrapbytes(cur)
if sys.platform == 'win32':
- def getcwdu(space):
- """Return the current working directory as a unicode string."""
+ def getcwd(space):
+ """Return the current working directory as a string."""
try:
- cur = os.getcwdu()
+ cur = os.getcwdb()
except OSError, e:
raise wrap_oserror(space, e)
else:
return space.wrap(cur)
else:
- def getcwdu(space):
- """Return the current working directory as a unicode string."""
+ def getcwd(space):
+ """Return the current working directory as a string."""
filesystemencoding = space.sys.filesystemencoding
- return space.call_method(getcwd(space), 'decode',
+ return space.call_method(getcwdb(space), 'decode',
space.wrap(filesystemencoding))
def chdir(space, w_path):
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
@@ -265,8 +265,9 @@
def test_getcwd(self):
assert isinstance(self.posix.getcwd(), str)
- assert isinstance(self.posix.getcwdu(), unicode)
- assert self.posix.getcwd() == self.posix.getcwdu()
+
+ def test_getcwdb(self):
+ assert isinstance(self.posix.getcwdb(), bytes)
def test_listdir(self):
pdir = self.pdir
@@ -461,14 +462,6 @@
{'FOOBAR': '42'})
assert ret == 42
- def test_popen(self):
- os = self.posix
- for i in range(5):
- stream = os.popen('echo 1')
- res = stream.read()
- assert res == '1\n'
- assert stream.close() is None
-
if hasattr(__import__(os.name), '_getfullpathname'):
def test__getfullpathname(self):
# nt specific
@@ -846,68 +839,6 @@
# How else could we test that getlogin is properly
# working?
- def test_tmpfile(self):
- os = self.posix
- f = os.tmpfile()
- f.write(b"xxx")
- f.flush()
- f.seek(0, 0)
- assert isinstance(f, file)
- assert f.read() == b'xxx'
-
- def test_tmpnam(self):
- import stat, os
- s1 = os.tmpnam()
- s2 = os.tmpnam()
- assert s1 != s2
- def isdir(s):
- try:
- return stat.S_ISDIR(os.stat(s).st_mode)
- except OSError:
- return -1
- assert isdir(s1) == -1
- assert isdir(s2) == -1
- assert isdir(os.path.dirname(s1)) == 1
- assert isdir(os.path.dirname(s2)) == 1
-
- def test_tempnam(self):
- import stat, os
- for dir in [None, self.udir]:
- for prefix in [None, 'foobar']:
- s1 = os.tempnam(dir, prefix)
- s2 = os.tempnam(dir, prefix)
- assert s1 != s2
- def isdir(s):
- try:
- return stat.S_ISDIR(os.stat(s).st_mode)
- except OSError:
- return -1
- assert isdir(s1) == -1
- assert isdir(s2) == -1
- assert isdir(os.path.dirname(s1)) == 1
- assert isdir(os.path.dirname(s2)) == 1
- if dir:
- assert os.path.dirname(s1) == dir
- assert os.path.dirname(s2) == dir
- assert os.path.basename(s1).startswith(prefix or 'tmp')
- assert os.path.basename(s2).startswith(prefix or 'tmp')
-
- def test_tmpnam_warning(self):
- import warnings, os
- #
- def f_tmpnam_warning(): os.tmpnam() # a single line
- #
- with warnings.catch_warnings(record=True) as w:
- warnings.simplefilter("always")
- f_tmpnam_warning()
- assert len(w) == 1
- assert issubclass(w[-1].category, RuntimeWarning)
- assert "potential security risk" in str(w[-1].message)
- # check that the warning points to the call to os.tmpnam(),
- # not to some code inside app_posix.py
- assert w[-1].lineno == f_tmpnam_warning.func_code.co_firstlineno
-
-
class AppTestEnvironment(object):
def setup_class(cls):
cls.space = space
diff --git a/pypy/module/posix/test/test_posix_libfile.py b/pypy/module/posix/test/test_posix_libfile.py
deleted file mode 100644
--- a/pypy/module/posix/test/test_posix_libfile.py
+++ /dev/null
@@ -1,67 +0,0 @@
-from pypy.conftest import gettestobjspace
-from pypy.tool.udir import udir
-import os
-
-def setup_module(mod):
- mod.space = gettestobjspace(usemodules=['posix'])
- mod.path = udir.join('posixtestfile.txt')
- mod.path.write("this is a test")
-
-class AppTestPosix:
- def setup_class(cls):
- cls.space = space
- cls.w_posix = space.appexec([], "(): import %s as m ; return m" % os.name)
- cls.w_path = space.wrap(str(path))
-
- def test_posix_is_pypy_s(self):
- assert self.posix.__file__
-
- def test_fdopen(self):
- path = self.path
- posix = self.posix
- fd = posix.open(path, posix.O_RDONLY, 0o777)
- f = posix.fdopen(fd, "r")
- result = f.read()
- assert result == "this is a test"
-
- def test_popen(self):
- import sys
- if sys.platform.startswith('win'):
- skip("unix specific")
- path2 = self.path + '2'
- posix = self.posix
-
- f = posix.popen("echo hello")
- data = f.read()
- f.close()
- assert data == 'hello\n'
-
- f = posix.popen("cat > '%s'" % (path2,), 'w')
- f.write('123\n')
- f.close()
- f = open(path2, 'r')
- data = f.read()
- f.close()
- assert data == '123\n'
-
- import time
- start_time = time.time()
- f = posix.popen("sleep 2")
- f.close() # should wait here
- end_time = time.time()
- assert end_time - start_time >= 1.9
-
- def test_popen_and_rebind_file_in___builtin__(self):
- import sys
- if sys.platform.startswith('win'):
- skip("unix specific")
- #
- import builtins
- posix = self.posix
- orig_file = file
- try:
- f = posix.popen('true')
- builtins.file = lambda x : explode
- f.close()
- finally:
- builtins.file = orig_file
More information about the pypy-commit
mailing list