[pypy-commit] pypy issue2343: Some similar tests for issubclass()

arigo pypy.commits at gmail.com
Wed Jul 13 13:12:04 EDT 2016


Author: Armin Rigo <arigo at tunes.org>
Branch: issue2343
Changeset: r85681:50c243508a5c
Date: 2016-07-13 19:13 +0200
http://bitbucket.org/pypy/pypy/changeset/50c243508a5c/

Log:	Some similar tests for issubclass()

diff --git a/pypy/module/__builtin__/test/test_abstractinst.py b/pypy/module/__builtin__/test/test_abstractinst.py
--- a/pypy/module/__builtin__/test/test_abstractinst.py
+++ b/pypy/module/__builtin__/test/test_abstractinst.py
@@ -224,3 +224,18 @@
 
         e = raises(TypeError, isinstance, 42, M())
         assert str(e.value) == "foobar"
+
+    def test_issubclass_exception_not_eaten(self):
+        class M(object):
+            def __subclasscheck__(self, subcls):
+                raise TypeError("foobar")
+
+        e = raises(TypeError, issubclass, 42, M())
+        assert str(e.value) == "foobar"
+
+    def test_issubclass_no_fallback(self):
+        class M(object):
+            def __subclasscheck__(self, subcls):
+                return False
+
+        assert issubclass(42, ()) is False
diff --git a/pypy/objspace/std/test/test_typeobject.py b/pypy/objspace/std/test/test_typeobject.py
--- a/pypy/objspace/std/test/test_typeobject.py
+++ b/pypy/objspace/std/test/test_typeobject.py
@@ -1101,6 +1101,19 @@
             __class__ = int
         assert int.__instancecheck__(Bar()) is True
 
+    def test_subclasscheck(self):
+        assert int.__subclasscheck__(bool) is True
+        assert int.__subclasscheck__(float) is False
+        class Foo:
+            __class__ = int
+        assert int.__subclasscheck__(Foo) is False
+        class Bar(object):
+            __class__ = int
+        assert int.__subclasscheck__(Bar) is False
+        class AbstractClass(object):
+            __bases__ = (int,)
+        assert int.__subclasscheck__(AbstractClass()) is True
+
 
 class AppTestWithMethodCacheCounter:
     spaceconfig = {"objspace.std.withmethodcachecounter": True}


More information about the pypy-commit mailing list