MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_set_class

Method test_set_class

Lib/test/test_descr.py:3327–3414  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

3325
3326 @unittest.expectedFailure # TODO: RUSTPYTHON
3327 def test_set_class(self):
3328 # Testing __class__ assignment...
3329 class C(object): pass
3330 class D(object): pass
3331 class E(object): pass
3332 class F(D, E): pass
3333 for cls in C, D, E, F:
3334 for cls2 in C, D, E, F:
3335 x = cls()
3336 x.__class__ = cls2
3337 self.assertIs(x.__class__, cls2)
3338 x.__class__ = cls
3339 self.assertIs(x.__class__, cls)
3340 def cant(x, C):
3341 try:
3342 x.__class__ = C
3343 except TypeError:
3344 pass
3345 else:
3346 self.fail("shouldn't allow %r.__class__ = %r" % (x, C))
3347 try:
3348 delattr(x, "__class__")
3349 except (TypeError, AttributeError):
3350 pass
3351 else:
3352 self.fail("shouldn't allow del %r.__class__" % x)
3353 cant(C(), list)
3354 cant(list(), C)
3355 cant(C(), 1)
3356 cant(C(), object)
3357 cant(object(), list)
3358 cant(list(), object)
3359 class Int(int): __slots__ = []
3360 cant(True, int)
3361 cant(2, bool)
3362 o = object()
3363 cant(o, int)
3364 cant(o, type(None))
3365 del o
3366 class G(object):
3367 __slots__ = ["a", "b"]
3368 class H(object):
3369 __slots__ = ["b", "a"]
3370 class I(object):
3371 __slots__ = ["a", "b"]
3372 class J(object):
3373 __slots__ = ["c", "b"]
3374 class K(object):
3375 __slots__ = ["a", "b", "d"]
3376 class L(H):
3377 __slots__ = ["e"]
3378 class M(I):
3379 __slots__ = ["e"]
3380 class N(J):
3381 __slots__ = ["__weakref__"]
3382 class P(J):
3383 __slots__ = ["__dict__"]
3384 class Q(J):

Callers

nothing calls this directly

Calls 6

listClass · 0.85
CClass · 0.70
AClass · 0.70
clsClass · 0.50
assertIsMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected