测试子类初始化方法的清晰度

问题描述 投票:0回答:1

我是面向对象的新手。我正在尝试测试RightPyramid初始化方法,不确定是否有办法像我一样RightPyramid init没有任何参数。

from typing import List
from abc import ABCMeta, abstractmethod

class Triangle(metaclass=ABCMeta):
    def __init__(self, base: int, height: int) -> None:
        assert base >= 0, "base must be greater or equal to 0"
        assert height >= 0, "height must be greater or equal to 0"
        self.base = base
        self.height = height

    @abstractmethod
    def area(self) -> int:   
        pass


class RightPyramid(Triangle):
    def __init__(self):
        Triangle.__init__(self, 3, 2)

    def area(self):
        return 0.5 * self.base + self.height
python unit-testing inheritance abstract-class init
1个回答
0
投票

执行以下代码:

rp = RightPyramid()

将实际调用RightPyramid .__ init __()方法,将self替换为实例并在rp变量中返回。

© www.soinside.com 2019 - 2024. All rights reserved.