我们从Python开源项目中,提取了以下3个代码示例,用于说明如何使用django.utils.six.with_metaclass()。
def test_undefined_inherited_attrs(self): """Test for when a sub-class doesn't define INHERITED_ATTRS.""" with self.assertRaises(PartialInheritanceError) as exc: class C(six.with_metaclass(PartialInheritanceMeta, A)): """A class that doesn't define INHERITED_ATTRS.""" self.assertExceptionMessageEquals(exc.exception, "Class 'C' must provide 'INHERITED_ATTRS'.")
def test_undefined_not_implemented_attrs(self): """Test for when a sub-class doesn't define NOT_IMPLEMENTED_ATTRS.""" with self.assertRaises(PartialInheritanceError) as exc: class D(six.with_metaclass(PartialInheritanceMeta, A)): """A class that doesn't define NOT_IMPLEMENTED_ATTRS.""" INHERITED_ATTRS = [] self.assertExceptionMessageEquals(exc.exception, "Class 'D' must provide 'NOT_IMPLEMENTED_ATTRS'.")
def test_property_cache(self): class TestWidget(six.with_metaclass(WidgetMeta)): def values(self): return next(itertools.count()) widget = TestWidget() # self.values is a cached property for i in range(2): self.assertEqual(widget.values, 0)