Python django.utils.six 模块,with_metaclass() 实例源码

我们从Python开源项目中,提取了以下3个代码示例,用于说明如何使用django.utils.six.with_metaclass()

项目:django-querysetsequence    作者:percipient    | 项目源码 | 文件源码
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'.")
项目:django-querysetsequence    作者:percipient    | 项目源码 | 文件源码
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'.")
项目:django-controlcenter    作者:byashimov    | 项目源码 | 文件源码
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)