def test_circle_initialization_str_repr_and_properties(self):
        s1 = Sphere(10)
        s2 = Sphere.from_diameter(40)
        assert type(s2) == Sphere
        self.assertEqual(s1.radius, 10.0)
        self.assertEqual(s1.diameter, 20.0)
        self.assertEqual(s2.radius, 20.0)
        self.assertEqual(s2.diameter, 40.0)
        s1.radius = 30
        self.assertEqual(s1.diameter, 60.0)
        s2.diameter = 30
        self.assertEqual(s2.radius, 15.0)

        self.assertEqual(str(s1), "Sphere with radius: 30.000")
        self.assertEqual(repr(s1), "Sphere(30.0)")
        self.assertEqual(round(s1.area), 11310)
        with pytest.raises(AttributeError) as error:
            s1.area = 50
            assert "AttributeError: can't set attribute" in error

        self.assertEqual(round(s1.volume), 113097)
        with pytest.raises(AttributeError) as error:
            s1.volume = 50
            assert "AttributeError: can't set attribute" in error
示例#2
0
def test_area():
    s = Sphere(10)
    assert s.area() == 1256.6370614359173
示例#3
0
def test_unhappy_set_area():
    c = Sphere(1)
    with pytest.raises(AttributeError) as e:
        c.area = 1