Author: Armin Rigo <ar...@tunes.org> Branch: ffi-backend Changeset: r56621:919262f4cd5f Date: 2012-08-07 10:24 +0200 http://bitbucket.org/pypy/pypy/changeset/919262f4cd5f/
Log: Import test_c from cffi diff --git a/pypy/module/_cffi_backend/test/_backend_test_c.py b/pypy/module/_cffi_backend/test/_backend_test_c.py --- a/pypy/module/_cffi_backend/test/_backend_test_c.py +++ b/pypy/module/_cffi_backend/test/_backend_test_c.py @@ -82,6 +82,7 @@ def test_no_float_on_int_types(): p = new_primitive_type('long') py.test.raises(TypeError, float, cast(p, 42)) + py.test.raises(TypeError, complex, cast(p, 42)) def test_float_types(): INF = 1E200 * 1E200 @@ -112,6 +113,39 @@ assert float(cast(p, True)) == 1.0 py.test.raises(TypeError, cast, p, None) +def test_complex_types(): + py.test.skip("later") + INF = 1E200 * 1E200 + for name in ["float", "double"]: + p = new_primitive_type("_Complex " + name) + assert bool(cast(p, 0)) + assert bool(cast(p, INF)) + assert bool(cast(p, -INF)) + assert bool(cast(p, 0j)) + assert bool(cast(p, INF*1j)) + assert bool(cast(p, -INF*1j)) + py.test.raises(TypeError, int, cast(p, -150)) + py.test.raises(TypeError, long, cast(p, -150)) + py.test.raises(TypeError, float, cast(p, -150)) + assert complex(cast(p, 1.25)) == 1.25 + assert complex(cast(p, 1.25j)) == 1.25j + assert float(cast(p, INF*1j)) == INF*1j + assert float(cast(p, -INF)) == -INF + if name == "float": + assert complex(cast(p, 1.1j)) != 1.1j # rounding error + assert complex(cast(p, 1E200+3j)) == INF+3j # limited range + assert complex(cast(p, 3+1E200j)) == 3+INF*1j # limited range + + assert cast(p, -1.1j) != cast(p, -1.1j) + assert repr(complex(cast(p, -0.0)).real) == '-0.0' + assert repr(complex(cast(p, -0j))) == '-0j' + assert complex(cast(p, '\x09')) == 9.0 + assert complex(cast(p, True)) == 1.0 + py.test.raises(TypeError, cast, p, None) + # + py.test.raises(cast, new_primitive_type(name), 1+2j) + py.test.raises(cast, new_primitive_type("int"), 1+2j) + def test_character_type(): p = new_primitive_type("char") assert bool(cast(p, '\x00')) @@ -1256,6 +1290,7 @@ BArray = new_array_type(new_pointer_type(BByte), None) a = newp(BArray, [65, 66, 67]) assert type(string(a)) is str and string(a) == 'ABC' + assert string(a, 8).startswith('ABC') # may contain additional garbage def test_string_wchar(): BWChar = new_primitive_type("wchar_t") @@ -1265,7 +1300,7 @@ BArray = new_array_type(new_pointer_type(BWChar), None) a = newp(BArray, [u'A', u'B', u'C']) assert type(string(a)) is unicode and string(a) == u'ABC' - assert string(a, 10) == u'ABC' + assert string(a, 8).startswith(u'ABC') # may contain additional garbage def test_string_typeerror(): BShort = new_primitive_type("short") _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit