From: Robert Bradshaw Date: Tue, 30 Sep 2008 18:39:13 +0000 (-0700) Subject: isinstance tests X-Git-Tag: 0.9.9.2.beta~76 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=3b97951e119f8a4ac8244a63c53c2e1cfdb01980;p=cython.git isinstance tests --- diff --git a/tests/run/isinstance.pyx b/tests/run/isinstance.pyx new file mode 100644 index 00000000..7c3d7334 --- /dev/null +++ b/tests/run/isinstance.pyx @@ -0,0 +1,35 @@ +__doc__ = u""" +>>> test_all() +True +""" +cdef class A: + pass + +def test_all(): + # Optimized tests. + assert isinstance(type('a',(),{}), type) + assert isinstance(bool(), bool) + assert isinstance(int(), int) + assert isinstance(long(), long) + assert isinstance(float(), float) + assert isinstance(complex(), complex) + assert isinstance(bytes(), bytes) + assert isinstance(str(), str) + assert isinstance(unicode(), unicode) + assert isinstance(tuple(), tuple) + assert isinstance(list(), list) + assert isinstance(dict(), dict) +# if py_ver > (2, 3): +# assert isinstance(set(), set) + assert isinstance(slice(0), slice) + assert isinstance(A, type) + assert isinstance(A(), A) + assert not isinstance("foo", int) + + # Non-optimized + foo = A + assert isinstance(A(), foo) + assert isinstance(0, (int, long)) + assert not isinstance("xyz", (int, long)) + return True +