From 3b97951e119f8a4ac8244a63c53c2e1cfdb01980 Mon Sep 17 00:00:00 2001 From: Robert Bradshaw Date: Tue, 30 Sep 2008 11:39:13 -0700 Subject: [PATCH] isinstance tests --- tests/run/isinstance.pyx | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tests/run/isinstance.pyx 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 + -- 2.26.2