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

Method test_errors

Lib/test/test_subclassinit.py:214–247  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

212 self.assertCountEqual(notified, ['a', 'b', 'c', 'd', 'e'])
213
214 def test_errors(self):
215 class MyMeta(type):
216 pass
217
218 with self.assertRaises(TypeError):
219 class MyClass(metaclass=MyMeta, otherarg=1):
220 pass
221
222 with self.assertRaises(TypeError):
223 types.new_class("MyClass", (object,),
224 dict(metaclass=MyMeta, otherarg=1))
225 types.prepare_class("MyClass", (object,),
226 dict(metaclass=MyMeta, otherarg=1))
227
228 class MyMeta(type):
229 def __init__(self, name, bases, namespace, otherarg):
230 super().__init__(name, bases, namespace)
231
232 with self.assertRaises(TypeError):
233 class MyClass2(metaclass=MyMeta, otherarg=1):
234 pass
235
236 class MyMeta(type):
237 def __new__(cls, name, bases, namespace, otherarg):
238 return super().__new__(cls, name, bases, namespace)
239
240 def __init__(self, name, bases, namespace, otherarg):
241 super().__init__(name, bases, namespace)
242 self.otherarg = otherarg
243
244 class MyClass3(metaclass=MyMeta, otherarg=1):
245 pass
246
247 self.assertEqual(MyClass3.otherarg, 1)
248
249 def test_errors_changed_pep487(self):
250 # These tests failed before Python 3.6, PEP 487

Callers

nothing calls this directly

Calls 3

new_classMethod · 0.80
assertRaisesMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected