Author: Armin Rigo <[email protected]>
Branch:
Changeset: r69814:3c269e621202
Date: 2014-03-09 08:28 +0100
http://bitbucket.org/pypy/pypy/changeset/3c269e621202/
Log: merge heads
diff --git a/lib-python/2.7/test/test_zipfile.py
b/lib-python/2.7/test/test_zipfile.py
--- a/lib-python/2.7/test/test_zipfile.py
+++ b/lib-python/2.7/test/test_zipfile.py
@@ -19,7 +19,7 @@
from unittest import skipUnless
from test.test_support import TESTFN, TESTFN_UNICODE, TESTFN_ENCODING, \
- run_unittest, findfile, unlink
+ run_unittest, findfile, unlink, rmtree
try:
TESTFN_UNICODE.encode(TESTFN_ENCODING)
except (UnicodeError, TypeError):
@@ -365,7 +365,8 @@
produces the expected result."""
with zipfile.ZipFile(TESTFN2, "w") as zipfp:
zipfp.write(TESTFN)
- self.assertEqual(zipfp.read(TESTFN), open(TESTFN).read())
+ with open(TESTFN,'r') as fid:
+ self.assertEqual(zipfp.read(TESTFN), fid.read())
@skipUnless(zlib, "requires zlib")
def test_per_file_compression(self):
@@ -404,11 +405,12 @@
self.assertEqual(writtenfile, correctfile)
# make sure correct data is in correct file
- self.assertEqual(fdata, open(writtenfile, "rb").read())
+ with open(writtenfile, "rb") as fid:
+ self.assertEqual(fdata, fid.read())
os.remove(writtenfile)
# remove the test file subdirectories
- shutil.rmtree(os.path.join(os.getcwd(), 'ziptest2dir'))
+ rmtree(os.path.join(os.getcwd(), 'ziptest2dir'))
def test_extract_all(self):
with zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_STORED) as zipfp:
@@ -419,12 +421,13 @@
zipfp.extractall()
for fpath, fdata in SMALL_TEST_DATA:
outfile = os.path.join(os.getcwd(), fpath)
-
- self.assertEqual(fdata, open(outfile, "rb").read())
+
+ with open(outfile, "rb") as fid:
+ self.assertEqual(fdata, fid.read())
os.remove(outfile)
# remove the test file subdirectories
- shutil.rmtree(os.path.join(os.getcwd(), 'ziptest2dir'))
+ rmtree(os.path.join(os.getcwd(), 'ziptest2dir'))
def check_file(self, filename, content):
self.assertTrue(os.path.isfile(filename))
@@ -509,12 +512,12 @@
self.assertEqual(writtenfile, correctfile,
msg="extract %r" % arcname)
self.check_file(correctfile, content)
- shutil.rmtree('target')
+ rmtree('target')
with zipfile.ZipFile(TESTFN2, 'r') as zipfp:
zipfp.extractall(targetpath)
self.check_file(correctfile, content)
- shutil.rmtree('target')
+ rmtree('target')
correctfile = os.path.join(os.getcwd(), *fixedname.split('/'))
@@ -523,12 +526,12 @@
self.assertEqual(writtenfile, correctfile,
msg="extract %r" % arcname)
self.check_file(correctfile, content)
- shutil.rmtree(fixedname.split('/')[0])
+ rmtree(fixedname.split('/')[0])
with zipfile.ZipFile(TESTFN2, 'r') as zipfp:
zipfp.extractall()
self.check_file(correctfile, content)
- shutil.rmtree(fixedname.split('/')[0])
+ rmtree(fixedname.split('/')[0])
os.remove(TESTFN2)
@@ -593,6 +596,8 @@
def tearDown(self):
unlink(TESTFN)
unlink(TESTFN2)
+ if os.path.exists(TESTFN):
+ os.remove(TESTFN)
class TestZip64InSmallFiles(unittest.TestCase):
@@ -712,6 +717,12 @@
class PyZipFileTests(unittest.TestCase):
+ def teardown(self):
+ if os.path.exists(TESTFN):
+ os.remove(TESTFN)
+ if os.path.exists(TESTFN2):
+ os.remove(TESTFN2)
+
def test_write_pyfile(self):
with zipfile.PyZipFile(TemporaryFile(), "w") as zipfp:
fn = __file__
@@ -773,11 +784,14 @@
self.assertNotIn('mod2.txt', names)
finally:
- shutil.rmtree(TESTFN2)
+ rmtree(TESTFN2)
def test_write_non_pyfile(self):
+ if os.path.exists(TESTFN):
+ os.remove(TESTFN)
with zipfile.PyZipFile(TemporaryFile(), "w") as zipfp:
- open(TESTFN, 'w').write('most definitely not a python file')
+ with open(TESTFN, 'w') as fid:
+ fid.write('most definitely not a python file')
self.assertRaises(RuntimeError, zipfp.writepy, TESTFN)
os.remove(TESTFN)
@@ -940,8 +954,9 @@
self.assertRaises(RuntimeError, zipf.open, "foo.txt")
self.assertRaises(RuntimeError, zipf.testzip)
self.assertRaises(RuntimeError, zipf.writestr, "bogus.txt", "bogus")
- open(TESTFN, 'w').write('zipfile test data')
- self.assertRaises(RuntimeError, zipf.write, TESTFN)
+ with open(TESTFN, 'w') as fid:
+ fid.write('zipfile test data')
+ self.assertRaises(RuntimeError, zipf.write, TESTFN)
def test_bad_constructor_mode(self):
"""Check that bad modes passed to ZipFile constructor are caught."""
@@ -1126,6 +1141,7 @@
pass
try:
zipf = zipfile.ZipFile(TESTFN, mode="r")
+ zipf.close()
except zipfile.BadZipfile:
self.fail("Unable to create empty ZIP file in 'w' mode")
@@ -1133,6 +1149,7 @@
pass
try:
zipf = zipfile.ZipFile(TESTFN, mode="r")
+ zipf.close()
except:
self.fail("Unable to create empty ZIP file in 'a' mode")
@@ -1151,6 +1168,8 @@
def tearDown(self):
unlink(TESTFN)
unlink(TESTFN2)
+ if os.path.exists(TESTFN):
+ os.remove(TESTFN)
class DecryptionTests(unittest.TestCase):
@@ -1201,16 +1220,28 @@
def test_bad_password(self):
self.zip.setpassword("perl")
- self.assertRaises(RuntimeError, self.zip.read, "test.txt")
+ try:
+ self.assertRaises(RuntimeError, self.zip.read, "test.txt")
+ finally:
+ self.zip.close()
self.zip2.setpassword("perl")
- self.assertRaises(RuntimeError, self.zip2.read, "zero")
+ try:
+ self.assertRaises(RuntimeError, self.zip2.read, "zero")
+ finally:
+ self.zip2.close()
@skipUnless(zlib, "requires zlib")
def test_good_password(self):
self.zip.setpassword("python")
- self.assertEqual(self.zip.read("test.txt"), self.plain)
+ try:
+ self.assertEqual(self.zip.read("test.txt"), self.plain)
+ finally:
+ self.zip.close()
self.zip2.setpassword("12345")
- self.assertEqual(self.zip2.read("zero"), self.plain2)
+ try:
+ self.assertEqual(self.zip2.read("zero"), self.plain2)
+ finally:
+ self.zip2.close()
class TestsWithRandomBinaryFiles(unittest.TestCase):
@@ -1224,8 +1255,10 @@
fp.write(self.data)
def tearDown(self):
- unlink(TESTFN)
- unlink(TESTFN2)
+ if os.path.exists(TESTFN):
+ os.remove(TESTFN)
+ if os.path.exists(TESTFN2):
+ os.remove(TESTFN2)
def make_test_archive(self, f, compression):
# Create the ZIP archive
@@ -1329,12 +1362,11 @@
# Verify that (when the ZipFile is in control of creating file objects)
# multiple open() calls can be made without interfering with each
other.
with zipfile.ZipFile(TESTFN2, mode="r") as zipf:
- zopen1 = zipf.open('ones')
- zopen2 = zipf.open('ones')
- data1 = zopen1.read(500)
- data2 = zopen2.read(500)
- data1 += zopen1.read(500)
- data2 += zopen2.read(500)
+ with zipf.open('ones') as zopen1, zipf.open('ones') as zopen2:
+ data1 = zopen1.read(500)
+ data2 = zopen2.read(500)
+ data1 += zopen1.read(500)
+ data2 += zopen2.read(500)
self.assertEqual(data1, data2)
def test_different_file(self):
@@ -1394,14 +1426,14 @@
def test_store_dir(self):
os.mkdir(os.path.join(TESTFN2, "x"))
- zipf = zipfile.ZipFile(TESTFN, "w")
- zipf.write(os.path.join(TESTFN2, "x"), "x")
- self.assertTrue(zipf.filelist[0].filename.endswith("x/"))
+ with zipfile.ZipFile(TESTFN, "w") as zipf:
+ zipf.write(os.path.join(TESTFN2, "x"), "x")
+ self.assertTrue(zipf.filelist[0].filename.endswith("x/"))
def tearDown(self):
- shutil.rmtree(TESTFN2)
+ rmtree(TESTFN2)
if os.path.exists(TESTFN):
- unlink(TESTFN)
+ os.remove(TESTFN)
class UniversalNewlineTests(unittest.TestCase):
@@ -1413,7 +1445,8 @@
for n, s in enumerate(self.seps):
self.arcdata[s] = s.join(self.line_gen) + s
self.arcfiles[s] = '%s-%d' % (TESTFN, n)
- open(self.arcfiles[s], "wb").write(self.arcdata[s])
+ with open(self.arcfiles[s], "wb") as fid:
+ fid.write(self.arcdata[s])
def make_test_archive(self, f, compression):
# Create the ZIP archive
@@ -1482,8 +1515,9 @@
# Read the ZIP archive
with zipfile.ZipFile(f, "r") as zipfp:
for sep, fn in self.arcfiles.items():
- for line, zipline in zip(self.line_gen, zipfp.open(fn, "rU")):
- self.assertEqual(zipline, line + '\n')
+ with zipfp.open(fn, "rU") as fid:
+ for line, zipline in zip(self.line_gen, fid):
+ self.assertEqual(zipline, line + '\n')
def test_read_stored(self):
for f in (TESTFN2, TemporaryFile(), StringIO()):
diff --git a/lib_pypy/_ctypes/function.py b/lib_pypy/_ctypes/function.py
--- a/lib_pypy/_ctypes/function.py
+++ b/lib_pypy/_ctypes/function.py
@@ -328,17 +328,16 @@
raise ValueError(
"native COM method call without 'this' parameter"
)
- thisvalue = args.pop(0)
+ thisvalue = args[0]
thisarg = cast(thisvalue, POINTER(POINTER(c_void_p)))
keepalives, newargs, argtypes, outargs, errcheckargs = (
- self._convert_args(argtypes, args, kwargs))
- args.insert(0, thisvalue)
+ self._convert_args(argtypes, args[1:], kwargs))
newargs.insert(0, thisvalue.value)
argtypes.insert(0, c_void_p)
else:
thisarg = None
keepalives, newargs, argtypes, outargs, errcheckargs = (
- self._convert_args(argtypes, args, kwargs))
+ self._convert_args(argtypes, args, kwargs))
funcptr = self._getfuncptr(argtypes, self._restype_, thisarg)
result = self._call_funcptr(funcptr, *newargs)
diff --git a/pypy/module/test_lib_pypy/cffi_tests/test_function.py
b/pypy/module/test_lib_pypy/cffi_tests/test_function.py
--- a/pypy/module/test_lib_pypy/cffi_tests/test_function.py
+++ b/pypy/module/test_lib_pypy/cffi_tests/test_function.py
@@ -36,11 +36,13 @@
return self._value
lib_m = 'm'
+has_sinf = True
if sys.platform == 'win32':
#there is a small chance this fails on Mingw via environ $CC
import distutils.ccompiler
if distutils.ccompiler.get_default_compiler() == 'msvc':
lib_m = 'msvcrt'
+ has_sinf = False
class TestFunction(object):
Backend = CTypesBackend
@@ -55,6 +57,8 @@
assert x == math.sin(1.23)
def test_sinf(self):
+ if not has_sinf:
+ py.test.skip("sinf not available")
ffi = FFI(backend=self.Backend())
ffi.cdef("""
float sinf(float x);
diff --git a/pypy/module/test_lib_pypy/test_sqlite3.py
b/pypy/module/test_lib_pypy/test_sqlite3.py
--- a/pypy/module/test_lib_pypy/test_sqlite3.py
+++ b/pypy/module/test_lib_pypy/test_sqlite3.py
@@ -236,8 +236,14 @@
return 42
con.set_authorizer(authorizer_cb)
with pytest.raises(_sqlite3.OperationalError) as e:
- con.execute('select 42')
- assert str(e.value) == 'authorizer malfunction'
+ con.execute('select 123')
+ major, minor, micro = _sqlite3.sqlite_version.split('.')[:3]
+ if (int(major), int(minor), int(micro)) >= (3, 6, 14):
+ assert str(e.value) == 'authorizer malfunction'
+ else:
+ assert str(e.value) == \
+ ("illegal return value (1) from the authorization function - "
+ "should be SQLITE_OK, SQLITE_IGNORE, or SQLITE_DENY")
def test_issue1573(con):
diff --git a/rpython/rlib/rsocket.py b/rpython/rlib/rsocket.py
--- a/rpython/rlib/rsocket.py
+++ b/rpython/rlib/rsocket.py
@@ -1148,6 +1148,9 @@
address_to_fill=None):
# port_or_service is a string, not an int (but try str(port_number)).
assert port_or_service is None or isinstance(port_or_service, str)
+ if _c._MACOSX:
+ if port_or_service is None or port_or_service == '0':
+ port_or_service = '00'
hints = lltype.malloc(_c.addrinfo, flavor='raw', zero=True)
rffi.setintfield(hints, 'c_ai_family', family)
rffi.setintfield(hints, 'c_ai_socktype', socktype)
diff --git a/rpython/rlib/test/test_rsocket.py
b/rpython/rlib/test/test_rsocket.py
--- a/rpython/rlib/test/test_rsocket.py
+++ b/rpython/rlib/test/test_rsocket.py
@@ -328,6 +328,11 @@
found = True
assert found, lst
+def test_getaddrinfo_osx_crash():
+ # see CPython issue17269
+ for port in [None, '0', '00']:
+ getaddrinfo('localhost', port, 0, 0, 0, AI_NUMERICSERV)
+
def test_connect_ex():
s = RSocket()
err = s.connect_ex(INETAddress('0.0.0.0', 0)) # should not work
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit