Author: Matti Picus <[email protected]>
Branch:
Changeset: r84482:71af15e55ba3
Date: 2016-05-16 19:59 +0300
http://bitbucket.org/pypy/pypy/changeset/71af15e55ba3/
Log: fixes for c89, open on win32
diff --git a/pypy/module/cpyext/test/test_datetime.py
b/pypy/module/cpyext/test/test_datetime.py
--- a/pypy/module/cpyext/test/test_datetime.py
+++ b/pypy/module/cpyext/test/test_datetime.py
@@ -122,13 +122,15 @@
module = self.import_extension('foo', [
("test_date_macros", "METH_NOARGS",
"""
+ PyObject* obj;
+ PyDateTime_Date* d;
PyDateTime_IMPORT;
if (!PyDateTimeAPI) {
PyErr_SetString(PyExc_RuntimeError, "No PyDateTimeAPI");
return NULL;
}
- PyObject* obj = PyDate_FromDate(2000, 6, 6);
- PyDateTime_Date* d = (PyDateTime_Date*)obj;
+ obj = PyDate_FromDate(2000, 6, 6);
+ d = (PyDateTime_Date*)obj;
PyDateTime_GET_YEAR(obj);
PyDateTime_GET_YEAR(d);
diff --git a/pypy/module/cpyext/test/test_sequence.py
b/pypy/module/cpyext/test/test_sequence.py
--- a/pypy/module/cpyext/test/test_sequence.py
+++ b/pypy/module/cpyext/test/test_sequence.py
@@ -160,9 +160,10 @@
module = self.import_extension('foo', [
("test_macro_cast", "METH_NOARGS",
"""
- PyObject* o = PyList_New(0);
+ PyObject *o = PyList_New(0);
+ PyListObject* l;
PyList_Append(o, o);
- PyListObject* l = (PyListObject*)o;
+ l = (PyListObject*)o;
PySequence_Fast_GET_ITEM(o, 0);
PySequence_Fast_GET_ITEM(l, 0);
diff --git a/pypy/module/cpyext/test/test_weakref.py
b/pypy/module/cpyext/test/test_weakref.py
--- a/pypy/module/cpyext/test/test_weakref.py
+++ b/pypy/module/cpyext/test/test_weakref.py
@@ -42,10 +42,11 @@
("test_macro_cast", "METH_NOARGS",
"""
// PyExc_Warning is some weak-reffable PyObject*.
+ char* dumb_pointer;
PyObject* weakref_obj = PyWeakref_NewRef(PyExc_Warning, NULL);
if (!weakref_obj) return weakref_obj;
// No public PyWeakReference type.
- char* dumb_pointer = (char*) weakref_obj;
+ dumb_pointer = (char*) weakref_obj;
PyWeakref_GET_OBJECT(weakref_obj);
PyWeakref_GET_OBJECT(dumb_pointer);
diff --git a/pypy/module/imp/test/test_import.py
b/pypy/module/imp/test/test_import.py
--- a/pypy/module/imp/test/test_import.py
+++ b/pypy/module/imp/test/test_import.py
@@ -20,15 +20,13 @@
if pkgname:
p = p.join(*pkgname.split('.'))
p.ensure(dir=1)
- f = p.join("__init__.py").open('w')
- print >> f, "# package"
- f.close()
+ with p.join("__init__.py").open('w') as f:
+ print >> f, "# package"
for filename, content in entries.items():
filename += '.py'
- f = p.join(filename).open('w')
- print >> f, '#', filename
- print >> f, content
- f.close()
+ with p.join(filename).open('w') as f:
+ print >> f, '#', filename
+ print >> f, content
return p
def setup_directory_structure(space):
@@ -535,9 +533,8 @@
import time
time.sleep(1)
- f = open(test_reload.__file__, "w")
- f.write("def test():\n raise NotImplementedError\n")
- f.close()
+ with open(test_reload.__file__, "w") as f:
+ f.write("def test():\n raise NotImplementedError\n")
reload(test_reload)
try:
test_reload.test()
@@ -553,9 +550,8 @@
import test_reload
import time
time.sleep(1)
- f = open(test_reload.__file__, "w")
- f.write("a = 10 // 0\n")
- f.close()
+ with open(test_reload.__file__, "w") as f:
+ f.write("a = 10 // 0\n")
# A failing reload should leave the previous module in sys.modules
raises(ZeroDivisionError, reload, test_reload)
@@ -687,7 +683,8 @@
import pkg
import os
pathname = os.path.join(os.path.dirname(pkg.__file__), 'a.py')
- module = imp.load_module('a', open(pathname),
+ with open(pathname) as fid:
+ module = imp.load_module('a', fid,
'invalid_path_name', ('.py', 'r',
imp.PY_SOURCE))
assert module.__name__ == 'a'
assert module.__file__ == 'invalid_path_name'
@@ -851,8 +848,8 @@
assert ret is None
# check for empty .pyc file
- f = open(cpathname, 'wb')
- f.close()
+ with open(cpathname, 'wb') as f:
+ pass
ret = importing.check_compiled_module(space,
cpathname,
mtime)
@@ -1391,7 +1388,8 @@
assert importer is None
# an existing file
path = os.path.join(self.udir, 'test_getimporter')
- open(path, 'w').close()
+ with open(path, 'w') as f:
+ pass
importer = imp._getimporter(path)
assert isinstance(importer, imp.NullImporter)
# a non-existing path
@@ -1400,8 +1398,8 @@
assert isinstance(importer, imp.NullImporter)
# a mostly-empty zip file
path = os.path.join(self.udir, 'test_getimporter.zip')
- f = open(path, 'wb')
- f.write('PK\x03\x04\n\x00\x00\x00\x00\x00P\x9eN>\x00\x00\x00\x00\x00'
+ with open(path, 'wb') as f:
+
f.write('PK\x03\x04\n\x00\x00\x00\x00\x00P\x9eN>\x00\x00\x00\x00\x00'
'\x00\x00\x00\x00\x00\x00\x00\x05\x00\x15\x00emptyUT\t\x00'
'\x03wyYMwyYMUx\x04\x00\xf4\x01d\x00PK\x01\x02\x17\x03\n\x00'
'\x00\x00\x00\x00P\x9eN>\x00\x00\x00\x00\x00\x00\x00\x00\x00'
@@ -1409,7 +1407,6 @@
'\xa4\x81\x00\x00\x00\x00emptyUT\x05\x00\x03wyYMUx\x00\x00PK'
'\x05\x06\x00\x00\x00\x00\x01\x00\x01\x00@\x00\x00\x008\x00'
'\x00\x00\x00\x00')
- f.close()
importer = imp._getimporter(path)
import zipimport
assert isinstance(importer, zipimport.zipimporter)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit