Author: Ronan Lamy <ronan.l...@gmail.com> Branch: py3.5 Changeset: r93553:c653db1b380d Date: 2017-12-22 16:26 +0100 http://bitbucket.org/pypy/pypy/changeset/c653db1b380d/
Log: hg merge default diff --git a/.hgtags b/.hgtags --- a/.hgtags +++ b/.hgtags @@ -44,3 +44,5 @@ d72f9800a42b46a8056951b1da2426d2c2d8d502 release-pypy3.5-v5.9.0 03d614975835870da65ff0481e1edad68ebbcb8d release-pypy2.7-v5.9.0 84a2f3e6a7f88f2fe698e473998755b3bd1a12e2 release-pypy2.7-v5.9.0 +0e7ea4fe15e82d5124e805e2e4a37cae1a402d4b release-pypy2.7-v5.10.0 +a91df6163fb76df245091f741dbf6a23ddc72374 release-pypy3.5-v5.10.0 diff --git a/pypy/doc/index-of-whatsnew.rst b/pypy/doc/index-of-whatsnew.rst --- a/pypy/doc/index-of-whatsnew.rst +++ b/pypy/doc/index-of-whatsnew.rst @@ -7,6 +7,7 @@ .. toctree:: whatsnew-head.rst + whatsnew-pypy2-5.10.0.rst whatsnew-pypy2-5.9.0.rst whatsnew-pypy2-5.8.0.rst whatsnew-pypy2-5.7.0.rst diff --git a/pypy/doc/release-v5.10.0.rst b/pypy/doc/release-v5.10.0.rst --- a/pypy/doc/release-v5.10.0.rst +++ b/pypy/doc/release-v5.10.0.rst @@ -19,6 +19,12 @@ several issues and bugs raised by the growing community of PyPy users. As always, we strongly recommend updating. +There are quite a few important changes that are in the pipeline that did not +make it into the 5.10 release. Most important are speed improvements to cpyext +(which will make numpy and pandas a bit faster) and utf8 branch that changes +internal representation of unicode to utf8, which should help especially the +Python 3.5 version of PyPy. + This release concludes the Mozilla Open Source `grant`_ for having a compatible PyPy 3.5 release and we're very grateful for that. Of course, we will continue to improve PyPy 3.5 and probably move to 3.6 during the course of 2018. @@ -53,7 +59,7 @@ We also welcome developers of other `dynamic languages`_ to see what RPython can do for them. -The PyPy 2.7 release supports: +The PyPy release supports: * **x86** machines on most common operating systems (Linux 32/64 bits, Mac OS X 64 bits, Windows 32 bits, OpenBSD, FreeBSD) diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst --- a/pypy/doc/whatsnew-head.rst +++ b/pypy/doc/whatsnew-head.rst @@ -2,41 +2,6 @@ What's new in PyPy2.7 5.10+ =========================== -.. this is a revision shortly after release-pypy2.7-v5.9.0 -.. startrev:d56dadcef996 +.. this is a revision shortly after release-pypy2.7-v5.10.0 +.. startrev: 6b024edd9d12 - -.. branch: cppyy-packaging - -Cleanup and improve cppyy packaging - -.. branch: docs-osx-brew-openssl - -.. branch: keep-debug-symbols - -Add a smartstrip tool, which can optionally keep the debug symbols in a -separate file, instead of just stripping them away. Use it in packaging - -.. branch: bsd-patches - -Fix failures on FreeBSD, contributed by David Naylor as patches on the issue -tracker (issues 2694, 2695, 2696, 2697) - -.. branch: run-extra-tests - -Run extra_tests/ in buildbot - -.. branch: vmprof-0.4.10 - -Upgrade the _vmprof backend to vmprof 0.4.10 - -.. branch: fix-vmprof-stacklet-switch -.. branch: fix-vmprof-stacklet-switch-2 -Fix a vmprof+continulets (i.e. greenelts, eventlet, gevent, ...) - -.. branch: win32-vcvars - -.. branch: rdict-fast-hash - -Make it possible to declare that the hash function of an r_dict is fast in RPython. - diff --git a/pypy/doc/whatsnew-pypy2-5.10.0.rst b/pypy/doc/whatsnew-pypy2-5.10.0.rst new file mode 100644 --- /dev/null +++ b/pypy/doc/whatsnew-pypy2-5.10.0.rst @@ -0,0 +1,42 @@ +========================== +What's new in PyPy2.7 5.10 +========================== + +.. this is a revision shortly after release-pypy2.7-v5.9.0 +.. startrev:d56dadcef996 + + +.. branch: cppyy-packaging + +Cleanup and improve cppyy packaging + +.. branch: docs-osx-brew-openssl + +.. branch: keep-debug-symbols + +Add a smartstrip tool, which can optionally keep the debug symbols in a +separate file, instead of just stripping them away. Use it in packaging + +.. branch: bsd-patches + +Fix failures on FreeBSD, contributed by David Naylor as patches on the issue +tracker (issues 2694, 2695, 2696, 2697) + +.. branch: run-extra-tests + +Run extra_tests/ in buildbot + +.. branch: vmprof-0.4.10 + +Upgrade the _vmprof backend to vmprof 0.4.10 + +.. branch: fix-vmprof-stacklet-switch +.. branch: fix-vmprof-stacklet-switch-2 +Fix a vmprof+continulets (i.e. greenelts, eventlet, gevent, ...) + +.. branch: win32-vcvars + +.. branch: rdict-fast-hash + +Make it possible to declare that the hash function of an r_dict is fast in RPython. + diff --git a/pypy/module/test_lib_pypy/ctypes_tests/_ctypes_test.c b/pypy/module/test_lib_pypy/ctypes_tests/_ctypes_test.c --- a/pypy/module/test_lib_pypy/ctypes_tests/_ctypes_test.c +++ b/pypy/module/test_lib_pypy/ctypes_tests/_ctypes_test.c @@ -3,9 +3,7 @@ #define MS_WIN32 #endif -#include "src/precommondefs.h" - -#define EXPORT(x) RPY_EXPORTED x +#define EXPORT(x) extern x #include <stdlib.h> #include <math.h> @@ -272,7 +270,7 @@ { double x, sum=0.0, dx=(b-a)/(double)nstep; for(x=a+0.5*dx; (b-x)*(x-a)>0.0; x+=dx) - { + { double y = f(x); printf("f(x)=%.1f\n", y); sum += f(x); @@ -287,7 +285,7 @@ static void _xxx_init(void *(*Xalloc)(int), void (*Xfree)(void *)) { void *ptr; - + printf("_xxx_init got %p %p\n", Xalloc, Xfree); printf("calling\n"); ptr = Xalloc(32); @@ -438,7 +436,7 @@ #endif /********/ - + #ifndef MS_WIN32 typedef struct { diff --git a/pypy/module/test_lib_pypy/ctypes_tests/conftest.py b/pypy/module/test_lib_pypy/ctypes_tests/conftest.py --- a/pypy/module/test_lib_pypy/ctypes_tests/conftest.py +++ b/pypy/module/test_lib_pypy/ctypes_tests/conftest.py @@ -1,14 +1,91 @@ -import py, pytest +import py +import pytest import sys +import os def pytest_ignore_collect(path): if '__pypy__' not in sys.builtin_module_names: return True +# XXX: copied from pypy/tool/cpyext/extbuild.py +if os.name != 'nt': + so_ext = 'so' +else: + so_ext = 'dll' + +def _build(cfilenames, outputfilename, compile_extra, link_extra, + include_dirs, libraries, library_dirs): + try: + # monkeypatch distutils for some versions of msvc compiler + import setuptools + except ImportError: + # XXX if this fails and is required, + # we must call pypy -mensurepip after translation + pass + from distutils.ccompiler import new_compiler + from distutils import sysconfig + + # XXX for Darwin running old versions of CPython 2.7.x + sysconfig.get_config_vars() + + compiler = new_compiler(force=1) + sysconfig.customize_compiler(compiler) # XXX + objects = [] + for cfile in cfilenames: + cfile = py.path.local(cfile) + old = cfile.dirpath().chdir() + try: + res = compiler.compile([cfile.basename], + include_dirs=include_dirs, extra_preargs=compile_extra) + assert len(res) == 1 + cobjfile = py.path.local(res[0]) + assert cobjfile.check() + objects.append(str(cobjfile)) + finally: + old.chdir() + + compiler.link_shared_object( + objects, str(outputfilename), + libraries=libraries, + extra_preargs=link_extra, + library_dirs=library_dirs) + +def c_compile(cfilenames, outputfilename, + compile_extra=None, link_extra=None, + include_dirs=None, libraries=None, library_dirs=None): + compile_extra = compile_extra or [] + link_extra = link_extra or [] + include_dirs = include_dirs or [] + libraries = libraries or [] + library_dirs = library_dirs or [] + if sys.platform == 'win32': + link_extra = link_extra + ['/DEBUG'] # generate .pdb file + if sys.platform == 'darwin': + # support Fink & Darwinports + for s in ('/sw/', '/opt/local/'): + if (s + 'include' not in include_dirs + and os.path.exists(s + 'include')): + include_dirs.append(s + 'include') + if s + 'lib' not in library_dirs and os.path.exists(s + 'lib'): + library_dirs.append(s + 'lib') + + outputfilename = py.path.local(outputfilename).new(ext=so_ext) + saved_environ = os.environ.copy() + try: + _build( + cfilenames, outputfilename, + compile_extra, link_extra, + include_dirs, libraries, library_dirs) + finally: + # workaround for a distutils bugs where some env vars can + # become longer and longer every time it is used + for key, value in saved_environ.items(): + if os.environ.get(key) != value: + os.environ[key] = value + return outputfilename +# end copy + def compile_so_file(): - from rpython.translator.platform import platform - from rpython.translator.tool.cbuild import ExternalCompilationInfo - from rpython.translator import cdir udir = pytest.ensuretemp('_ctypes_test') cfile = py.path.local(__file__).dirpath().join("_ctypes_test.c") @@ -16,11 +93,8 @@ libraries = ['oleaut32'] else: libraries = [] - eci = ExternalCompilationInfo(libraries=libraries, - include_dirs=[cdir]) - return platform.compile([cfile], eci, str(udir.join('_ctypes_test')), - standalone=False) + return c_compile([cfile], str(udir / '_ctypes_test'), libraries=libraries) # we need to run after the "tmpdir" plugin which installs pytest.ensuretemp @pytest.mark.trylast diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_anon.py b/pypy/module/test_lib_pypy/ctypes_tests/test_anon.py --- a/pypy/module/test_lib_pypy/ctypes_tests/test_anon.py +++ b/pypy/module/test_lib_pypy/ctypes_tests/test_anon.py @@ -1,3 +1,4 @@ +import pytest from ctypes import * from support import BaseCTypesTestChecker @@ -22,18 +23,15 @@ def test_anon_nonseq(self): # TypeError: _anonymous_ must be a sequence - raises(TypeError, - lambda: type(Structure)("Name", - (Structure,), - {"_fields_": [], "_anonymous_": 42})) + with pytest.raises(TypeError): + type(Structure)( + "Name", (Structure,), {"_fields_": [], "_anonymous_": 42}) def test_anon_nonmember(self): # AttributeError: type object 'Name' has no attribute 'x' - raises(AttributeError, - lambda: type(Structure)("Name", - (Structure,), - {"_fields_": [], - "_anonymous_": ["x"]})) + with pytest.raises(AttributeError): + type(Structure)( + "Name", (Structure,), {"_fields_": [], "_anonymous_": ["x"]}) def test_nested(self): class ANON_S(Structure): diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_array.py b/pypy/module/test_lib_pypy/ctypes_tests/test_array.py --- a/pypy/module/test_lib_pypy/ctypes_tests/test_array.py +++ b/pypy/module/test_lib_pypy/ctypes_tests/test_array.py @@ -1,5 +1,4 @@ - -import py +import pytest from ctypes import * from support import BaseCTypesTestChecker @@ -40,7 +39,8 @@ assert values == [0] * len(init) # Too many in itializers should be caught - py.test.raises(IndexError, int_array, *range(alen*2)) + with pytest.raises(IndexError): + int_array(*range(alen*2)) CharArray = ARRAY(c_char, 3) @@ -48,7 +48,8 @@ # Should this work? It doesn't: # CharArray("abc") - py.test.raises(TypeError, CharArray, "abc") + with pytest.raises(TypeError): + CharArray("abc") assert ca[0] == "a" assert ca[1] == "b" @@ -61,10 +62,12 @@ # slicing is now supported, but not extended slicing (3-argument)! from operator import getslice, delitem - py.test.raises(TypeError, getslice, ca, 0, 1, -1) + with pytest.raises(TypeError): + getslice(ca, 0, 1, -1) # cannot delete items - py.test.raises(TypeError, delitem, ca, 0) + with pytest.raises(TypeError): + delitem(ca, 0) def test_numeric_arrays(self): @@ -165,7 +168,8 @@ assert isinstance(Car("abcdefghi", 42.0, "12345").brand, bytes) assert Car("abcdefghi", 42.0, "12345").brand == "abcdefghi" assert Car("abcdefghio", 42.0, "12345").brand == "abcdefghio" - raises(ValueError, Car, "abcdefghiop", 42.0, "12345") + with pytest.raises(ValueError): + Car("abcdefghiop", 42.0, "12345") A = Car._fields_[2][1] TP = POINTER(A) diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_as_parameter.py b/pypy/module/test_lib_pypy/ctypes_tests/test_as_parameter.py --- a/pypy/module/test_lib_pypy/ctypes_tests/test_as_parameter.py +++ b/pypy/module/test_lib_pypy/ctypes_tests/test_as_parameter.py @@ -1,5 +1,5 @@ from ctypes import * -import py +import pytest from support import BaseCTypesTestChecker def setup_module(mod): @@ -104,7 +104,8 @@ # check that the prototype works: we call f with wrong # argument types cb = AnotherCallback(callback) - raises(ArgumentError, f, self.wrap(-10), self.wrap(cb)) + with pytest.raises(ArgumentError): + f(self.wrap(-10), self.wrap(cb)) def test_callbacks_2(self): # Can also use simple datatypes as argument type specifiers @@ -213,4 +214,4 @@ wrap = AsParamPropertyWrapper #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - + diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_bitfields.py b/pypy/module/test_lib_pypy/ctypes_tests/test_bitfields.py --- a/pypy/module/test_lib_pypy/ctypes_tests/test_bitfields.py +++ b/pypy/module/test_lib_pypy/ctypes_tests/test_bitfields.py @@ -1,4 +1,4 @@ -import py +import pytest from ctypes import * from support import BaseCTypesTestChecker import os @@ -245,7 +245,5 @@ def test_set_fields_cycle_fails(self): class A(Structure): pass - import pytest - pytest.raises(AttributeError, """ + with pytest.raises(AttributeError): A._fields_ = [("a", A)] - """) diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_callbacks.py b/pypy/module/test_lib_pypy/ctypes_tests/test_callbacks.py --- a/pypy/module/test_lib_pypy/ctypes_tests/test_callbacks.py +++ b/pypy/module/test_lib_pypy/ctypes_tests/test_callbacks.py @@ -1,5 +1,5 @@ from ctypes import * -import py +import pytest from support import BaseCTypesTestChecker class TestCallbacks(BaseCTypesTestChecker): @@ -22,7 +22,7 @@ c_uint: (int, long), c_ulong: (int, long), } - + PROTO = self.functype.im_func(typ, typ) cfunc = PROTO(self.callback) result = cfunc(arg) @@ -101,15 +101,18 @@ ## self.check_type(c_char_p, "abc") ## self.check_type(c_char_p, "def") + + @pytest.mark.xfail( + reason="we are less strict about callback return type sanity") def test_unsupported_restype_1(self): - py.test.skip("we are less strict about callback return type sanity") # Only "fundamental" result types are supported for callback # functions, the type must have a non-NULL stgdict->setfunc. # POINTER(c_double), for example, is not supported. prototype = self.functype.im_func(POINTER(c_double)) # The type is checked when the prototype is called - raises(TypeError, prototype, lambda: None) + with pytest.raises(TypeError): + prototype(lambda: None) try: WINFUNCTYPE @@ -193,9 +196,10 @@ class RECT(Structure): _fields_ = [("left", c_int), ("top", c_int), ("right", c_int), ("bottom", c_int)] - + proto = CFUNCTYPE(RECT, c_int) - raises(TypeError, proto, lambda r: 0) + with pytest.raises(TypeError): + proto(lambda r: 0) def test_qsort(self): @@ -210,7 +214,7 @@ a[i] = 5-i assert a[0] == 5 # sanity - + def comp(a, b): a = a.contents.value b = b.contents.value @@ -273,4 +277,5 @@ FUNC = CFUNCTYPE(None, c_void_p) cfunc = FUNC(callback) param = c_uint(42) - py.test.raises(ArgumentError, "cfunc(param)") + with pytest.raises(ArgumentError): + cfunc(param) diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_checkretval.py b/pypy/module/test_lib_pypy/ctypes_tests/test_checkretval.py --- a/pypy/module/test_lib_pypy/ctypes_tests/test_checkretval.py +++ b/pypy/module/test_lib_pypy/ctypes_tests/test_checkretval.py @@ -1,4 +1,4 @@ -import py +import pytest import sys from ctypes import * @@ -33,6 +33,5 @@ pass else: def test_oledll(self): - raises(WindowsError, - oledll.oleaut32.CreateTypeLib2, - 0, 0, 0) + with pytest.raises(WindowsError): + oledll.oleaut32.CreateTypeLib2(0, 0, 0) diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_commethods.py b/pypy/module/test_lib_pypy/ctypes_tests/test_commethods.py --- a/pypy/module/test_lib_pypy/ctypes_tests/test_commethods.py +++ b/pypy/module/test_lib_pypy/ctypes_tests/test_commethods.py @@ -2,10 +2,10 @@ # Can't resist from implementing some kind of mini-comtypes # theller ;-) -import py +import pytest import sys if sys.platform != "win32": - py.test.skip('windows only test') + pytest.importorskip('skip_the_whole_module') # hack! import ctypes, new, unittest from ctypes.wintypes import HRESULT @@ -27,7 +27,7 @@ if instance is None: return self return new.instancemethod(self.func, instance, owner) - + def commethod(index, restype, *argtypes): """A decorator that generates COM methods. The decorated function itself is not used except for it's name.""" @@ -72,7 +72,8 @@ assert 4 == punk.AddRef() punk.SetName("TypeLib_ByPYPY") - py.test.raises(COMError, lambda: punk.SetName(None)) + with pytest.raises(COMError): + punk.SetName(None) # This would save the typelib to disk. ## punk.SaveAllChanges() diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_funcptr.py b/pypy/module/test_lib_pypy/ctypes_tests/test_funcptr.py --- a/pypy/module/test_lib_pypy/ctypes_tests/test_funcptr.py +++ b/pypy/module/test_lib_pypy/ctypes_tests/test_funcptr.py @@ -1,4 +1,4 @@ -import py +import pytest import sys, os, unittest from ctypes import * @@ -27,6 +27,8 @@ assert sizeof(x) == sizeof(c_voidp) assert sizeof(X) == sizeof(c_voidp) + @pytest.mark.xfail( + reason="cdecl funcptrs ignoring extra args is not implemented") def test_first(self): StdCallback = WINFUNCTYPE(c_int, c_int, c_int) CdeclCallback = CFUNCTYPE(c_int, c_int, c_int) @@ -42,14 +44,13 @@ # The following no longer raises a TypeError - it is now # possible, as in C, to call cdecl functions with more parameters. #self.assertRaises(TypeError, c, 1, 2, 3) - py.test.skip("cdecl funcptrs ignoring extra args is not implemented") assert c(1, 2, 3, 4, 5, 6) == 3 if not WINFUNCTYPE is CFUNCTYPE and os.name != "ce": - raises(TypeError, s, 1, 2, 3) + with pytest.raises(TypeError): + s(1, 2, 3) + @pytest.mark.skipif("sys.platform != 'win32'") def test_structures(self): - if sys.platform != 'win32': - py.test.skip("win32 related") WNDPROC = WINFUNCTYPE(c_long, c_int, c_int, c_int, c_int) def wndproc(hwnd, msg, wParam, lParam): @@ -130,9 +131,10 @@ assert strtok(None, "\n") == "c" assert strtok(None, "\n") == None + @pytest.mark.xfail( + reason="This test needs mmap to make sure the code is executable, " + "please rewrite me") def test_from_address(self): - py.test.skip("This test needs mmap to make sure the" - " code is executable, please rewrite me") def make_function(): proto = CFUNCTYPE(c_int) a=create_string_buffer( diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_functions.py b/pypy/module/test_lib_pypy/ctypes_tests/test_functions.py --- a/pypy/module/test_lib_pypy/ctypes_tests/test_functions.py +++ b/pypy/module/test_lib_pypy/ctypes_tests/test_functions.py @@ -8,7 +8,7 @@ from __future__ import with_statement from ctypes import * import sys -import py +import pytest from support import BaseCTypesTestChecker try: @@ -90,7 +90,7 @@ f.argtypes = [c_byte, c_short, c_int, c_long, c_float, c_double] f.restype = c_wchar result = f(0, 0, 0, 0, 0, 0) - assert result == '\x00' + assert result == u'\x00' def test_char_result(self): f = dll._testfunc_i_bhilfd @@ -140,7 +140,8 @@ assert type(result) == int # You cannot assing character format codes as restype any longer - raises(TypeError, setattr, f, "restype", "i") + with pytest.raises(TypeError): + setattr(f, "restype", "i") def test_unicode_function_name(self): f = dll[u'_testfunc_i_bhilfd'] @@ -237,7 +238,8 @@ result = f(arg) assert not result.contents == v.value - raises(ArgumentError, f, byref(c_short(22))) + with pytest.raises(ArgumentError): + f(byref(c_short(22))) # It is dangerous, however, because you don't control the lifetime # of the pointer: @@ -262,7 +264,8 @@ class X(Structure): _fields_ = [("y", c_int)] - raises(ArgumentError, f, X()) #cannot convert parameter + with pytest.raises(ArgumentError): + f(X()) #cannot convert parameter ################################################################ def test_shorts(self): @@ -310,7 +313,8 @@ # check that the prototype works: we call f with wrong # argument types cb = AnotherCallback(callback) - raises(ArgumentError, f, -10, cb) + with pytest.raises(ArgumentError): + f(-10, cb) def test_callbacks_2(self): @@ -351,8 +355,10 @@ assert 13577625587 == f(1000000000000, cb) def test_errors_2(self): - raises(AttributeError, getattr, dll, "_xxx_yyy") - raises(ValueError, c_int.in_dll, dll, "_xxx_yyy") + with pytest.raises(AttributeError): + getattr(dll, "_xxx_yyy") + with pytest.raises(ValueError): + c_int.in_dll(dll, "_xxx_yyy") def test_byval(self): # without prototype @@ -466,16 +472,16 @@ result = f("abcd", ord("b"), 42) assert result == "bcd" + @pytest.mark.xfail(reason="we are less strict in checking callback parameters") def test_sf1651235(self): - py.test.skip("we are less strict in checking callback parameters") # see http://www.python.org/sf/1651235 - proto = CFUNCTYPE(c_int, RECT, POINT) def callback(*args): return 0 callback = proto(callback) - raises(ArgumentError, lambda: callback((1, 2, 3, 4), POINT())) + with pytest.raises(ArgumentError): + callback((1, 2, 3, 4), POINT()) def test_argument_conversion_and_checks(self): #This test is designed to check for segfaults if the wrong type of argument is passed as parameter @@ -485,8 +491,10 @@ assert strlen("eggs", ord("g")) == "ggs" # Should raise ArgumentError, not segfault - py.test.raises(ArgumentError, strlen, 0, 0) - py.test.raises(ArgumentError, strlen, False, 0) + with pytest.raises(ArgumentError): + strlen(0, 0) + with pytest.raises(ArgumentError): + strlen(False, 0) def test_union_as_passed_value(self): class UN(Union): @@ -524,8 +532,8 @@ assert tf_b("yadda") == -42 assert seen == ["yadda"] + @pytest.mark.xfail(reason="warnings are disabled") def test_warnings(self): - py.test.skip("warnings are disabled") import warnings warnings.simplefilter("always") with warnings.catch_warnings(record=True) as w: @@ -534,8 +542,8 @@ assert issubclass(w[0].category, RuntimeWarning) assert "C function without declared arguments called" in str(w[0]) + @pytest.mark.xfail def test_errcheck(self): - py.test.skip('fixme') def errcheck(result, func, args): assert result == -42 assert type(result) is int @@ -556,12 +564,12 @@ assert len(w) == 1 assert issubclass(w[0].category, RuntimeWarning) assert "C function without declared return type called" in str(w[0]) - + with warnings.catch_warnings(record=True) as w: dll.get_an_integer.restype = None dll.get_an_integer() assert len(w) == 0 - + warnings.resetwarnings() @@ -597,7 +605,7 @@ get_data.errcheck = ret_list_p(1) assert get_data('testing!') == [-1, -2, -3, -4] - def test_issue2533(self): + def test_issue2533(self, tmpdir): import cffi ffi = cffi.FFI() ffi.cdef("int **fetchme(void);") @@ -609,11 +617,10 @@ return &pa; } """) - from rpython.tool.udir import udir - ffi.compile(verbose=True, tmpdir=str(udir)) + ffi.compile(verbose=True, tmpdir=str(tmpdir)) import sys - sys.path.insert(0, str(udir)) + sys.path.insert(0, str(tmpdir)) try: from _x_cffi import ffi, lib finally: diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_init.py b/pypy/module/test_lib_pypy/ctypes_tests/test_init.py --- a/pypy/module/test_lib_pypy/ctypes_tests/test_init.py +++ b/pypy/module/test_lib_pypy/ctypes_tests/test_init.py @@ -1,7 +1,6 @@ -import py +import pytest from ctypes import * -py.test.skip("subclassing semantics and implementation details not implemented") class X(Structure): _fields_ = [("a", c_int), @@ -21,19 +20,20 @@ _fields_ = [("x", X)] -class TestInit: - def test_get(self): - # make sure the only accessing a nested structure - # doesn't call the structure's __new__ and __init__ - y = Y() - assert (y.x.a, y.x.b) == (0, 0) - assert y.x.new_was_called == False +@pytest.mark.xfail( + reason="subclassing semantics and implementation details not implemented") +def test_get(): + # make sure the only accessing a nested structure + # doesn't call the structure's __new__ and __init__ + y = Y() + assert (y.x.a, y.x.b) == (0, 0) + assert y.x.new_was_called == False - # But explicitely creating an X structure calls __new__ and __init__, of course. - x = X() - assert (x.a, x.b) == (9, 12) - assert x.new_was_called == True + # But explicitely creating an X structure calls __new__ and __init__, of course. + x = X() + assert (x.a, x.b) == (9, 12) + assert x.new_was_called == True - y.x = x - assert (y.x.a, y.x.b) == (9, 12) - assert y.x.new_was_called == False + y.x = x + assert (y.x.a, y.x.b) == (9, 12) + assert y.x.new_was_called == False diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_loading.py b/pypy/module/test_lib_pypy/ctypes_tests/test_loading.py --- a/pypy/module/test_lib_pypy/ctypes_tests/test_loading.py +++ b/pypy/module/test_lib_pypy/ctypes_tests/test_loading.py @@ -1,4 +1,4 @@ -import py +import pytest from ctypes import * import sys import os @@ -27,14 +27,17 @@ def test_load(self): CDLL(libc_name) CDLL(os.path.basename(libc_name)) - raises(OSError, CDLL, self.unknowndll) + with pytest.raises(OSError): + CDLL(self.unknowndll) if libc_name is not None and os.path.basename(libc_name) == "libc.so.6": def test_load_version(self): cdll.LoadLibrary("libc.so.6") # linux uses version, libc 9 should not exist - raises(OSError, cdll.LoadLibrary, "libc.so.9") - raises(OSError, cdll.LoadLibrary, self.unknowndll) + with pytest.raises(OSError): + cdll.LoadLibrary("libc.so.9") + with pytest.raises(OSError): + cdll.LoadLibrary(self.unknowndll) def test_find(self): for name in ("c", "m"): @@ -80,7 +83,5 @@ f_name_addr = c_void_p.from_address(a_name).value assert hex(f_ord_addr) == hex(f_name_addr) - raises(AttributeError, dll.__getitem__, 1234) - -if __name__ == "__main__": - unittest.main() + with pytest.raises(AttributeError): + dll[1234] diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_numbers.py b/pypy/module/test_lib_pypy/ctypes_tests/test_numbers.py --- a/pypy/module/test_lib_pypy/ctypes_tests/test_numbers.py +++ b/pypy/module/test_lib_pypy/ctypes_tests/test_numbers.py @@ -1,4 +1,4 @@ -import py +import pytest from ctypes import * from support import BaseCTypesTestChecker import sys, struct @@ -65,8 +65,10 @@ # Only numbers are allowed in the contructor, # otherwise TypeError is raised for t in signed_types + unsigned_types + float_types: - raises(TypeError, t, "") - raises(TypeError, t, None) + with pytest.raises(TypeError): + t("") + with pytest.raises(TypeError): + t(None) ## def test_valid_ranges(self): ## # invalid values of the correct type @@ -75,16 +77,16 @@ ## self.assertRaises(ValueError, t, l-1) ## self.assertRaises(ValueError, t, h+1) + @pytest.mark.xfail(reason="testing implementation internals") def test_from_param(self): # the from_param class method attribute always # returns PyCArgObject instances - py.test.skip("testing implementation internals") for t in signed_types + unsigned_types + float_types: assert ArgType == type(t.from_param(0)) + @pytest.mark.xfail(reason="testing implementation internals") def test_byref(self): # calling byref returns also a PyCArgObject instance - py.test.skip("testing implementation internals") for t in signed_types + unsigned_types + float_types: parm = byref(t()) assert ArgType == type(parm) @@ -107,7 +109,8 @@ def test_integers(self): # integers cannot be constructed from floats for t in signed_types + unsigned_types: - raises(TypeError, t, 3.14) + with pytest.raises(TypeError): + t(3.14) def test_sizes(self): for t in signed_types + unsigned_types + float_types: @@ -184,7 +187,8 @@ # c_int() can be initialized from Python's int, and c_int. # Not from c_long or so, which seems strange, abd should # probably be changed: - raises(TypeError, c_int, c_long(42)) + with pytest.raises(TypeError): + c_int(c_long(42)) def test_subclass(self): class enum(c_int): @@ -194,14 +198,13 @@ _fields_ = [('t', enum)] assert isinstance(S().t, enum) + #@pytest.mark.xfail("'__pypy__' not in sys.builtin_module_names") + @pytest.mark.xfail def test_no_missing_shape_to_ffi_type(self): # whitebox test - import sys - if '__pypy__' not in sys.builtin_module_names: - skip("only for pypy's ctypes") - skip("re-enable after adding 'g' to _shape_to_ffi_type.typemap, " - "which I think needs fighting all the way up from " - "rpython.rlib.libffi") + "re-enable after adding 'g' to _shape_to_ffi_type.typemap, " + "which I think needs fighting all the way up from " + "rpython.rlib.libffi" from _ctypes.basics import _shape_to_ffi_type from _rawffi import Array for i in range(1, 256): @@ -212,7 +215,7 @@ else: assert chr(i) in _shape_to_ffi_type.typemap - @py.test.mark.xfail + @pytest.mark.xfail def test_pointer_to_long_double(self): import ctypes ctypes.POINTER(ctypes.c_longdouble) diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_parameters.py b/pypy/module/test_lib_pypy/ctypes_tests/test_parameters.py --- a/pypy/module/test_lib_pypy/ctypes_tests/test_parameters.py +++ b/pypy/module/test_lib_pypy/ctypes_tests/test_parameters.py @@ -1,4 +1,4 @@ -import py +import pytest import sys class TestSimpleTypes: @@ -60,10 +60,10 @@ o = My_void_pp() assert Void_pp.from_param(o) is o - + # XXX Replace by c_char_p tests + @pytest.mark.xfail(reason="testing implementation internals") def test_cstrings(self): - py.test.skip("testing implementation internals") from ctypes import c_char_p, byref # c_char_p.from_param on a Python String packs the string @@ -72,18 +72,20 @@ assert c_char_p.from_param(s)._obj is s # new in 0.9.1: convert (encode) unicode to ascii - assert c_char_p.from_param("123")._obj == b"123" - raises(UnicodeEncodeError, c_char_p.from_param, "123\377") + assert c_char_p.from_param(u"123")._obj == b"123" + with pytest.raises(UnicodeEncodeError): + c_char_p.from_param(u"123\377") - raises(TypeError, c_char_p.from_param, 42) + with pytest.raises(TypeError): + c_char_p.from_param(42) # calling c_char_p.from_param with a c_char_p instance # returns the argument itself: a = c_char_p("123") assert c_char_p.from_param(a) is a + @pytest.mark.xfail(reason="testing implementation internals") def test_cw_strings(self): - py.test.skip("testing implementation internals") from ctypes import byref try: from ctypes import c_wchar_p @@ -93,11 +95,13 @@ s = "123" if sys.platform == "win32": assert c_wchar_p.from_param(s)._obj is s - raises(TypeError, c_wchar_p.from_param, 42) + with pytest.raises(TypeError): + c_wchar_p.from_param(42) # new in 0.9.1: convert (decode) ascii to unicode - assert c_wchar_p.from_param(b"123")._obj == "123" - raises(UnicodeDecodeError, c_wchar_p.from_param, b"123\377") + assert c_wchar_p.from_param(b"123")._obj == u"123" + with pytest.raises(UnicodeDecodeError): + c_wchar_p.from_param(b"123\377") pa = c_wchar_p.from_param(c_wchar_p("123")) assert type(pa) == c_wchar_p @@ -115,9 +119,12 @@ assert not LPINT.from_param(None) if c_int != c_long: - raises(TypeError, LPINT.from_param, pointer(c_long(42))) - raises(TypeError, LPINT.from_param, pointer(c_uint(42))) - raises(TypeError, LPINT.from_param, pointer(c_short(42))) + with pytest.raises(TypeError): + LPINT.from_param(pointer(c_long(42))) + with pytest.raises(TypeError): + LPINT.from_param(pointer(c_uint(42))) + with pytest.raises(TypeError): + LPINT.from_param(pointer(c_short(42))) def test_byref_pointer(self): # The from_param class method of POINTER(typ) classes accepts what is @@ -127,10 +134,13 @@ LPINT.from_param(byref(c_int(42))) - raises(TypeError, LPINT.from_param, byref(c_short(22))) + with pytest.raises(TypeError): + LPINT.from_param(byref(c_short(22))) if c_int != c_long: - raises(TypeError, LPINT.from_param, byref(c_long(22))) - raises(TypeError, LPINT.from_param, byref(c_uint(22))) + with pytest.raises(TypeError): + LPINT.from_param(byref(c_long(22))) + with pytest.raises(TypeError): + LPINT.from_param(byref(c_uint(22))) def test_byref_pointerpointer(self): # See above @@ -139,10 +149,13 @@ LPLPINT = POINTER(POINTER(c_int)) LPLPINT.from_param(byref(pointer(c_int(42)))) - raises(TypeError, LPLPINT.from_param, byref(pointer(c_short(22)))) + with pytest.raises(TypeError): + LPLPINT.from_param(byref(pointer(c_short(22)))) if c_int != c_long: - raises(TypeError, LPLPINT.from_param, byref(pointer(c_long(22)))) - raises(TypeError, LPLPINT.from_param, byref(pointer(c_uint(22)))) + with pytest.raises(TypeError): + LPLPINT.from_param(byref(pointer(c_long(22)))) + with pytest.raises(TypeError): + LPLPINT.from_param(byref(pointer(c_uint(22)))) def test_array_pointers(self): from ctypes import c_short, c_uint, c_int, c_long, POINTER @@ -155,15 +168,18 @@ # the same type! LPINT = POINTER(c_int) LPINT.from_param((c_int*3)()) - raises(TypeError, LPINT.from_param, c_short*3) - raises(TypeError, LPINT.from_param, c_long*3) - raises(TypeError, LPINT.from_param, c_uint*3) + with pytest.raises(TypeError): + LPINT.from_param(c_short*3) + with pytest.raises(TypeError): + LPINT.from_param(c_long*3) + with pytest.raises(TypeError): + LPINT.from_param(c_uint*3) ## def test_performance(self): ## check_perf() + @pytest.mark.xfail(reason="testing implementation internals") def test_noctypes_argtype(self): - py.test.skip("we implement details differently") from ctypes import CDLL, c_void_p, ArgumentError import conftest dll = CDLL(str(conftest.sofile)) @@ -171,7 +187,8 @@ func = dll._testfunc_p_p func.restype = c_void_p # TypeError: has no from_param method - raises(TypeError, setattr, func, "argtypes", (object,)) + with pytest.raises(TypeError): + setattr(func, "argtypes", (object,)) class Adapter(object): def from_param(cls, obj): @@ -187,7 +204,8 @@ func.argtypes = (Adapter(),) # don't know how to convert parameter 1 - raises(ArgumentError, func, object()) + with pytest.raises(ArgumentError): + func(object()) assert func(c_void_p(42)) == 42 class Adapter(object): @@ -196,7 +214,8 @@ func.argtypes = (Adapter(),) # ArgumentError: argument 1: ValueError: 99 - raises(ArgumentError, func, 99) + with pytest.raises(ArgumentError): + func(99) def test_multiple_signature(self): # when .argtypes is not set, calling a function with a certain @@ -212,4 +231,4 @@ # This one is normal assert func(None) == 0 - + diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_prototypes.py b/pypy/module/test_lib_pypy/ctypes_tests/test_prototypes.py --- a/pypy/module/test_lib_pypy/ctypes_tests/test_prototypes.py +++ b/pypy/module/test_lib_pypy/ctypes_tests/test_prototypes.py @@ -1,4 +1,4 @@ -import py +import pytest from ctypes import * from support import BaseCTypesTestChecker @@ -31,21 +31,27 @@ def test_restype_setattr(self): func = testdll._testfunc_p_p - raises(TypeError, setattr, func, 'restype', 20) + with pytest.raises(TypeError): + setattr(func, 'restype', 20) def test_argtypes_setattr(self): func = testdll._testfunc_p_p - raises(TypeError, setattr, func, 'argtypes', 20) - raises(TypeError, setattr, func, 'argtypes', [20]) + with pytest.raises(TypeError): + setattr(func, 'argtypes', 20) + with pytest.raises(TypeError): + setattr(func, 'argtypes', [20]) func = CFUNCTYPE(c_long, c_void_p, c_long)(lambda: None) assert func.argtypes == (c_void_p, c_long) def test_paramflags_setattr(self): func = CFUNCTYPE(c_long, c_void_p, c_long)(lambda: None) - raises(TypeError, setattr, func, 'paramflags', 'spam') - raises(ValueError, setattr, func, 'paramflags', (1, 2, 3, 4)) - raises(TypeError, setattr, func, 'paramflags', ((1,), ('a',))) + with pytest.raises(TypeError): + setattr(func, 'paramflags', 'spam') + with pytest.raises(ValueError): + setattr(func, 'paramflags', (1, 2, 3, 4)) + with pytest.raises(TypeError): + setattr(func, 'paramflags', ((1,), ('a',))) func.paramflags = (1,), (1|4,) def test_kwargs(self): @@ -107,13 +113,16 @@ positive_address(func(byref(ci)))) func.argtypes = c_char_p, - raises(ArgumentError, func, byref(ci)) + with pytest.raises(ArgumentError): + func(byref(ci)) func.argtypes = POINTER(c_short), - raises(ArgumentError, func, byref(ci)) + with pytest.raises(ArgumentError): + func(byref(ci)) func.argtypes = POINTER(c_double), - raises(ArgumentError, func, byref(ci)) + with pytest.raises(ArgumentError): + func(byref(ci)) def test_POINTER_c_char_arg(self): func = testdll._testfunc_p_p @@ -252,7 +261,8 @@ func.restype = POINTER(c_int) func.argtypes = [c_int * 8] array = ARRAY(1, 2, 3, 4, 5, 6, 7, 8) - py.test.raises(ArgumentError, "func(array)") + with pytest.raises(ArgumentError): + func(array) ################################################################ diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_returnfuncptrs.py b/pypy/module/test_lib_pypy/ctypes_tests/test_returnfuncptrs.py --- a/pypy/module/test_lib_pypy/ctypes_tests/test_returnfuncptrs.py +++ b/pypy/module/test_lib_pypy/ctypes_tests/test_returnfuncptrs.py @@ -1,4 +1,4 @@ -import py +import pytest from ctypes import * @@ -16,8 +16,10 @@ strchr = get_strchr() assert strchr("abcdef", "b") == "bcdef" assert strchr("abcdef", "x") == None - raises(ArgumentError, strchr, "abcdef", 3) - raises(TypeError, strchr, "abcdef") + with pytest.raises(ArgumentError): + strchr("abcdef", 3) + with pytest.raises(TypeError): + strchr("abcdef") def test_without_prototype(self): get_strchr = dll.get_strchr @@ -29,5 +31,7 @@ strchr = CFUNCTYPE(c_char_p, c_char_p, c_char)(addr) assert strchr("abcdef", "b"), "bcdef" assert strchr("abcdef", "x") == None - raises(ArgumentError, strchr, "abcdef", 3) - raises(TypeError, strchr, "abcdef") + with pytest.raises(ArgumentError): + strchr("abcdef", 3) + with pytest.raises(TypeError): + strchr("abcdef") diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_slicing.py b/pypy/module/test_lib_pypy/ctypes_tests/test_slicing.py --- a/pypy/module/test_lib_pypy/ctypes_tests/test_slicing.py +++ b/pypy/module/test_lib_pypy/ctypes_tests/test_slicing.py @@ -1,4 +1,4 @@ -import py +import pytest from support import BaseCTypesTestChecker from ctypes import * @@ -30,13 +30,17 @@ from operator import setslice # TypeError: int expected instead of str instance - raises(TypeError, setslice, a, 0, 5, b"abcde") + with pytest.raises(TypeError): + setslice(a, 0, 5, b"abcde") # TypeError: int expected instead of str instance - raises(TypeError, setslice, a, 0, 5, [b"a", b"b", b"c", b"d", b"e"]) + with pytest.raises(TypeError): + setslice(a, 0, 5, [b"a", b"b", b"c", b"d", b"e"]) # TypeError: int expected instead of float instance - raises(TypeError, setslice, a, 0, 5, [1, 2, 3, 4, 3.14]) + with pytest.raises(TypeError): + setslice(a, 0, 5, [1, 2, 3, 4, 3.14]) # ValueError: Can only assign sequence of same size - raises(ValueError, setslice, a, 0, 5, range(32)) + with pytest.raises(ValueError): + setslice(a, 0, 5, range(32)) def test_char_ptr(self): s = "abcdefghijklmnopqrstuvwxyz" @@ -47,8 +51,8 @@ assert res[:len(s)] == s import operator - raises(TypeError, operator.setslice, - res, 0, 5, "abcde") + with pytest.raises(TypeError): + operator.setslice(res, 0, 5, u"abcde") dll.my_free(res) dll.my_strdup.restype = POINTER(c_byte) @@ -99,8 +103,8 @@ assert res[:len(s)] == s import operator - raises(TypeError, operator.setslice, - res, 0, 5, "abcde") + with pytest.raises(TypeError): + operator.setslice(res, 0, 5, u"abcde") dll.my_free(res) if sizeof(c_wchar) == sizeof(c_short): diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_stringptr.py b/pypy/module/test_lib_pypy/ctypes_tests/test_stringptr.py --- a/pypy/module/test_lib_pypy/ctypes_tests/test_stringptr.py +++ b/pypy/module/test_lib_pypy/ctypes_tests/test_stringptr.py @@ -1,4 +1,4 @@ -import py +import pytest from support import BaseCTypesTestChecker from ctypes import * @@ -16,7 +16,8 @@ x = X() # NULL pointer access - raises(ValueError, getattr, x.str, "contents") + with pytest.raises(ValueError): + x.str.contents b = c_buffer("Hello, World") #from sys import getrefcount as grc #assert grc(b) == 2 @@ -31,7 +32,6 @@ # XXX pypy modified: #raises(TypeError, setattr, x, "str", "Hello, World") x = b = None - py.test.skip("test passes! but modified to avoid getrefcount and detail issues") def test__c_char_p(self): class X(Structure): @@ -47,7 +47,6 @@ #b = c_buffer("Hello, World") #raises(TypeError, setattr, x, "str", b) x = None - py.test.skip("test passes! but modified to avoid detail issues") def test_functions(self): diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_struct_fields.py b/pypy/module/test_lib_pypy/ctypes_tests/test_struct_fields.py --- a/pypy/module/test_lib_pypy/ctypes_tests/test_struct_fields.py +++ b/pypy/module/test_lib_pypy/ctypes_tests/test_struct_fields.py @@ -1,4 +1,4 @@ -import py +import pytest from support import BaseCTypesTestChecker from ctypes import * @@ -18,31 +18,37 @@ pass assert sizeof(X) == 0 # not finalized X._fields_ = [] # finalized - raises(AttributeError, setattr, X, "_fields_", []) + with pytest.raises(AttributeError): + X._fields_ = [] def test_1_B(self): class X(Structure): _fields_ = [] # finalized - raises(AttributeError, setattr, X, "_fields_", []) + with pytest.raises(AttributeError): + X._fields_ = [] def test_2(self): class X(Structure): pass X() - raises(AttributeError, setattr, X, "_fields_", []) + with pytest.raises(AttributeError): + X._fields_ = [] def test_3(self): class X(Structure): pass class Y(Structure): _fields_ = [("x", X)] # finalizes X - raises(AttributeError, setattr, X, "_fields_", []) + with pytest.raises(AttributeError): + X._fields_ = [] def test_4(self): class X(Structure): pass class Y(X): pass - raises(AttributeError, setattr, X, "_fields_", []) + with pytest.raises(AttributeError): + X._fields_ = [] Y._fields_ = [] - raises(AttributeError, setattr, X, "_fields_", []) + with pytest.raises(AttributeError): + X._fields_ = [] diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_structures.py b/pypy/module/test_lib_pypy/ctypes_tests/test_structures.py --- a/pypy/module/test_lib_pypy/ctypes_tests/test_structures.py +++ b/pypy/module/test_lib_pypy/ctypes_tests/test_structures.py @@ -2,7 +2,7 @@ from struct import calcsize from support import BaseCTypesTestChecker -import py +import pytest class TestSubclasses(BaseCTypesTestChecker): @@ -143,8 +143,10 @@ assert X.y.size == sizeof(c_char) # readonly - raises((TypeError, AttributeError), setattr, X.x, "offset", 92) - raises((TypeError, AttributeError), setattr, X.x, "size", 92) + with pytest.raises((TypeError, AttributeError)): + X.x.offset = 92 + with pytest.raises((TypeError, AttributeError)): + X.x.size = 92 class X(Union): _fields_ = [("x", c_int), @@ -157,8 +159,10 @@ assert X.y.size == sizeof(c_char) # readonly - raises((TypeError, AttributeError), setattr, X.x, "offset", 92) - raises((TypeError, AttributeError), setattr, X.x, "size", 92) + with pytest.raises((TypeError, AttributeError)): + X.x.offset = 92 + with pytest.raises((TypeError, AttributeError)): + X.x.size = 92 # XXX Should we check nested data types also? # offset is always relative to the class... @@ -202,23 +206,28 @@ d = {"_fields_": [("a", "b"), ("b", "q")], "_pack_": -1} - raises(ValueError, type(Structure), "X", (Structure,), d) + with pytest.raises(ValueError): + type(Structure)("X", (Structure,), d) def test_initializers(self): class Person(Structure): _fields_ = [("name", c_char*6), ("age", c_int)] - raises(TypeError, Person, 42) - raises(ValueError, Person, "asldkjaslkdjaslkdj") - raises(TypeError, Person, "Name", "HI") + with pytest.raises(TypeError): + Person(42) + with pytest.raises(ValueError): + Person("asldkjaslkdjaslkdj") + with pytest.raises(TypeError): + Person("Name", "HI") # short enough assert Person("12345", 5).name == "12345" # exact fit assert Person("123456", 5).name == "123456" # too long - raises(ValueError, Person, "1234567", 5) + with pytest.raises(ValueError): + Person("1234567", 5) def test_keyword_initializers(self): @@ -246,7 +255,8 @@ def test_invalid_field_types(self): class POINT(Structure): pass - raises(TypeError, setattr, POINT, "_fields_", [("x", 1), ("y", 2)]) + with pytest.raises(TypeError): + POINT._fields_ = [("x", 1), ("y", 2)] def test_intarray_fields(self): class SomeInts(Structure): @@ -257,7 +267,8 @@ assert SomeInts((1, 2, 3, 4)).a[:] == [1, 2, 3, 4] # too long # XXX Should raise ValueError?, not RuntimeError - raises(RuntimeError, SomeInts, (1, 2, 3, 4, 5)) + with pytest.raises(RuntimeError): + SomeInts((1, 2, 3, 4, 5)) def test_nested_initializers(self): # test initializing nested structures @@ -278,7 +289,7 @@ assert p.age == 5 def test_structures_with_wchar(self): - py.test.skip("need unicode support on _rawffi level") + pytest.skip("need unicode support on _rawffi level") try: c_wchar except NameError: @@ -288,18 +299,19 @@ _fields_ = [("name", c_wchar * 12), ("age", c_int)] - p = PersonW("Someone") + p = PersonW(u"Someone") assert p.name == "Someone" - assert PersonW("1234567890").name == "1234567890" - assert PersonW("12345678901").name == "12345678901" + assert PersonW(u"1234567890").name == u"1234567890" + assert PersonW(u"12345678901").name == u"12345678901" # exact fit - assert PersonW("123456789012").name == "123456789012" + assert PersonW(u"123456789012").name == u"123456789012" #too long - raises(ValueError, PersonW, "1234567890123") + with pytest.raises(ValueError): + PersonW(u"1234567890123") def test_init_errors(self): - py.test.skip("not implemented error details") + pytest.skip("not implemented error details") class Phone(Structure): _fields_ = [("areacode", c_char*6), ("number", c_char*12)] @@ -347,7 +359,7 @@ ## (AttributeError, "class must define a '_fields_' attribute")) def test_abstract_class(self): - py.test.skip("_abstract_ semantics not implemented") + pytest.skip("_abstract_ semantics not implemented") class X(Structure): _abstract_ = "something" # try 'X()' @@ -373,7 +385,7 @@ assert p.age == 6 def test_subclassing_field_is_a_tuple(self): - py.test.skip("subclassing semantics not implemented") + pytest.skip("subclassing semantics not implemented") class Person(Structure): _fields_ = (("name", c_char*6), ("age", c_int)) @@ -542,7 +554,7 @@ raise AssertionError("Structure or union cannot contain itself") def test_vice_versa(self): - py.test.skip("mutually dependent lazily defined structures error semantics") + pytest.skip("mutually dependent lazily defined structures error semantics") class First(Structure): pass class Second(Structure): @@ -563,18 +575,21 @@ pass assert sizeof(X) == 0 X._fields_ = [("a", c_int),] - raises(AttributeError, setattr, X, "_fields_", []) + with pytest.raises(AttributeError): + X._fields_ = [] class X(Structure): pass X() - raises(AttributeError, setattr, X, "_fields_", []) + with pytest.raises(AttributeError): + X._fields_ = [] class X(Structure): pass class Y(X): pass - raises(AttributeError, setattr, X, "_fields_", []) + with pytest.raises(AttributeError): + X._fields_ = [] Y.__fields__ = [] diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_unicode.py b/pypy/module/test_lib_pypy/ctypes_tests/test_unicode.py --- a/pypy/module/test_lib_pypy/ctypes_tests/test_unicode.py +++ b/pypy/module/test_lib_pypy/ctypes_tests/test_unicode.py @@ -1,6 +1,6 @@ # coding: latin-1 import ctypes -import py +import pytest from support import BaseCTypesTestChecker try: @@ -29,11 +29,11 @@ def test_ascii_strict(self): ctypes.set_conversion_mode("ascii", "strict") # no conversions take place with unicode arguments - assert wcslen("abc") == 3 - assert wcslen("ab\u2070") == 3 - # string args are converted + assert wcslen(u"abc") == 3 + assert wcslen(u"ab\u2070") == 3 + # bytes args are converted assert wcslen(b"abc") == 3 - py.test.raises(ctypes.ArgumentError, wcslen, b"aba") + pytest.raises(ctypes.ArgumentError, wcslen, "ab�") def test_ascii_replace(self): ctypes.set_conversion_mode("ascii", "replace") @@ -69,7 +69,7 @@ ctypes.set_conversion_mode("ascii", "ignore") buf = ctypes.create_unicode_buffer(b"ab���") # is that correct? not sure. But with 'ignore', you get what you pay for.. - assert buf[:] == "ab\0\0\0\0" + assert buf[:] == u"ab\0\0\0\0" class TestString(TestUnicode): def setup_method(self, method): @@ -85,32 +85,33 @@ def test_ascii_replace(self): ctypes.set_conversion_mode("ascii", "strict") assert func(b"abc") == "abc" - assert func("abc") == "abc" - raises(ctypes.ArgumentError, func, "ab�") + assert func(u"abc") == "abc" + with pytest.raises(ctypes.ArgumentError): + func(u"ab�") def test_ascii_ignore(self): ctypes.set_conversion_mode("ascii", "ignore") assert func("abc") == "abc" - assert func("abc") == "abc" - assert func("����") == "" + assert func(u"abc") == "abc" + assert func(u"����") == "" def test_ascii_replace_2(self): ctypes.set_conversion_mode("ascii", "replace") assert func("abc") == "abc" - assert func("abc") == "abc" - assert func("����") == "????" + assert func(u"abc") == "abc" + assert func(u"����") == "????" def test_buffers(self): ctypes.set_conversion_mode("ascii", "strict") - buf = ctypes.create_string_buffer("abc") + buf = ctypes.create_string_buffer(u"abc") assert len(buf) == 3+1 ctypes.set_conversion_mode("ascii", "replace") - buf = ctypes.create_string_buffer("ab���") + buf = ctypes.create_string_buffer(u"ab���") assert buf[:] == "ab???\0" ctypes.set_conversion_mode("ascii", "ignore") - buf = ctypes.create_string_buffer("ab���") + buf = ctypes.create_string_buffer(u"ab���") # is that correct? not sure. But with 'ignore', you get what you pay for.. assert buf[:] == "ab\0\0\0\0" diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_values.py b/pypy/module/test_lib_pypy/ctypes_tests/test_values.py --- a/pypy/module/test_lib_pypy/ctypes_tests/test_values.py +++ b/pypy/module/test_lib_pypy/ctypes_tests/test_values.py @@ -2,7 +2,7 @@ A testcase which accesses *values* in a dll. """ -import py +import pytest from ctypes import * from support import BaseCTypesTestChecker @@ -27,12 +27,13 @@ assert ctdll.get_a_string_char(15) == ord('$') def test_undefined(self): - raises(ValueError, c_int.in_dll, ctdll, "Undefined_Symbol") + with pytest.raises(ValueError): + c_int.in_dll(ctdll, "Undefined_Symbol") class TestWin_Values(BaseCTypesTestChecker): """This test only works when python itself is a dll/shared library""" def setup_class(cls): - py.test.skip("tests expect and access cpython dll") + pytest.skip("tests expect and access cpython dll") def test_optimizeflag(self): # This test accesses the Py_OptimizeFlag intger, which is @@ -86,7 +87,8 @@ del _pointer_type_cache[struct_frozen] def test_undefined(self): - raises(ValueError, c_int.in_dll, pydll, "Undefined_Symbol") + with pytest.raises(ValueError): + c_int.in_dll(pydll, "Undefined_Symbol") if __name__ == '__main__': unittest.main() diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_varsize_struct.py b/pypy/module/test_lib_pypy/ctypes_tests/test_varsize_struct.py --- a/pypy/module/test_lib_pypy/ctypes_tests/test_varsize_struct.py +++ b/pypy/module/test_lib_pypy/ctypes_tests/test_varsize_struct.py @@ -1,10 +1,10 @@ -import py +import pytest from support import BaseCTypesTestChecker from ctypes import * class TestVarSize(BaseCTypesTestChecker): def test_resize(self): - py.test.skip("resizing not implemented") + pytest.skip("resizing not implemented") class X(Structure): _fields_ = [("item", c_int), ("array", c_int * 1)] @@ -35,15 +35,23 @@ def test_array_invalid_length(self): # cannot create arrays with non-positive size - raises(ValueError, lambda: c_int * -1) - raises(ValueError, lambda: c_int * -3) + with pytest.raises(ValueError): + c_int * -1 + with pytest.raises(ValueError): + c_int * -3 def test_zerosized_array(self): array = (c_int * 0)() # accessing elements of zero-sized arrays raise IndexError - raises(IndexError, array.__setitem__, 0, None) - raises(IndexError, array.__getitem__, 0) - raises(IndexError, array.__setitem__, 1, None) - raises(IndexError, array.__getitem__, 1) - raises(IndexError, array.__setitem__, -1, None) - raises(IndexError, array.__getitem__, -1) + with pytest.raises(IndexError): + array.__setitem__(0, None) + with pytest.raises(IndexError): + array.__getitem__(0) + with pytest.raises(IndexError): + array.__setitem__(1, None) + with pytest.raises(IndexError): + array.__getitem__(1) + with pytest.raises(IndexError): + array.__setitem__(-1, None) + with pytest.raises(IndexError): + array.__getitem__(-1) diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_win32.py b/pypy/module/test_lib_pypy/ctypes_tests/test_win32.py --- a/pypy/module/test_lib_pypy/ctypes_tests/test_win32.py +++ b/pypy/module/test_lib_pypy/ctypes_tests/test_win32.py @@ -4,11 +4,11 @@ from ctypes.test import is_resource_enabled from support import BaseCTypesTestChecker -import py +import pytest import sys if sys.platform != "win32": - py.test.skip("win32-only tests") + pytest.importorskip('skip_the_whole_module') # hack! class TestWindows(BaseCTypesTestChecker): def test_callconv_1(self): @@ -16,13 +16,15 @@ IsWindow = windll.user32.IsWindow # ValueError: Procedure probably called with not enough arguments (4 bytes missing) - py.test.raises(ValueError, IsWindow) + with pytest.raises(ValueError): + IsWindow() # This one should succeeed... assert IsWindow(0) == 0 # ValueError: Procedure probably called with too many arguments (8 bytes in excess) - py.test.raises(ValueError, IsWindow, 0, 0, 0) + with pytest.raises(ValueError): + IsWindow(0, 0, 0) def test_callconv_2(self): # Calling stdcall function as cdecl @@ -31,13 +33,15 @@ # ValueError: Procedure called with not enough arguments (4 bytes missing) # or wrong calling convention - py.test.raises(ValueError, IsWindow, None) + with pytest.raises(ValueError): + IsWindow(None) if is_resource_enabled("SEH"): def test_SEH(self): # Call functions with invalid arguments, and make sure that access violations # are trapped and raise an exception. - py.test.raises(WindowsError, windll.kernel32.GetModuleHandleA, 32) + with pytest.raises(WindowsError): + windll.kernel32.GetModuleHandleA(32) class TestWintypes(BaseCTypesTestChecker): diff --git a/pypy/tool/cpyext/extbuild.py b/pypy/tool/cpyext/extbuild.py --- a/pypy/tool/cpyext/extbuild.py +++ b/pypy/tool/cpyext/extbuild.py @@ -201,7 +201,7 @@ # monkeypatch distutils for some versions of msvc compiler import setuptools except ImportError: - # XXX if this fails and is required, + # XXX if this fails and is required, # we must call pypy -mensurepip after translation pass from distutils.ccompiler import new_compiler _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit