Skip to content

Commit 5d10e7c

Browse files
committed
added some set __bases__ tests
1 parent 4b10897 commit 5d10e7c

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

graalpython/com.oracle.graal.python.test/src/tests/test_genericclass.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2018, 2019, Oracle and/or its affiliates.
1+
# Copyright (c) 2018, 2020, Oracle and/or its affiliates.
22
# Copyright (C) 1996-2017 Python Software Foundation
33
#
44
# Licensed under the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
@@ -249,3 +249,23 @@ class C(metaclass=Meta):
249249
def __class_getitem__(cls, item):
250250
return 'from __class_getitem__'
251251
self.assertEqual(C[int], 'from metaclass')
252+
253+
class TestClassSetBases(unittest.TestCase):
254+
def test_class_set_bases(self):
255+
256+
def assert_bases(cls, bases, err, msg):
257+
raised = False
258+
try:
259+
cls.__bases__ = bases
260+
except err as e:
261+
raised = True
262+
assert msg == str(e), "invalid error message:\n expected:" + msg + "\n was:" + str(e)
263+
assert raised
264+
265+
class A(): pass
266+
class B(): pass
267+
268+
assert_bases(A, 'a', TypeError, "can only assign tuple to A.__bases__, not str")
269+
assert_bases(A, (B, 'a'), TypeError, "A.__bases__ must be tuple of classes, not 'str'")
270+
assert_bases(dict, (B,), TypeError, "can't set attributes of built-in/extension type 'dict'")
271+

0 commit comments

Comments
 (0)