test_decorators.py 文件源码

python
阅读 36 收藏 0 点赞 0 评论 0

项目:oanda-api-v20 作者: hootnot 项目源码 文件源码
def test__abstractclass(self):

        @six.add_metaclass(ABCMeta)
        class Something(object):

            @abstractmethod
            def __init__(self, x=10):
                self.x = x

        @abstractclass
        class SomethingElse(Something):
            # derived classes from this class make use
            # of this class __init__
            # since this __init__ overrides the parent's
            # @abstractmethod instances could be created,
            # by making the class abstract with @abstractclass
            # this can't be done, derived classes can
            # ... that is the goal

            def __init__(self, x=10, y=20):
                super(SomethingElse, self).__init__(x)
                self.y = y

        class ABCDerived(SomethingElse):
            pass

        with self.assertRaises(TypeError):
            Something(x=20)
        with self.assertRaises(TypeError):
            SomethingElse(x=20, y=30)

        x = 20
        y = 30
        abcDerived = ABCDerived(x, y)
        self.assertEqual(abcDerived.x + abcDerived.y, x+y)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号