def test_area_type_exception(): with pytest.raises(TypeError): my_class.circle_area(3+5j) my_class.circle_area(True) my_class.circle_area("radius") # Używamy coverage do sprawdzenia pokrycia kodu testami.
def test_area_type_exception( ): # ten test przejdzie tylko wtedy gdy wszystkie asercje wyrzucą wyjątek with pytest.raises(TypeError): my_class.circle_area(3 + 5j) my_class.circle_area(True) my_class.circle_area("radius")
def test_area_value_exceptions(): with pytest.raises(ValueError): my_class.circle_area(-3)
def test_circle_area(): assert pytest.approx(my_class.circle_area(1), 0.001) == math.pi assert my_class.circle_area(0) == 0 assert my_class.circle_area(2.1) == math.pi * (2.1**2)
def test_area(self): """test area when radius >=0""" self.assertAlmostEqual(my_class.circle_area(1), math.pi) self.assertAlmostEqual(my_class.circle_area(2.1), math.pi * (2.1**2))
def test_area_type_exception(): with pytest.raises(ValueError): my_class.circle_area(3 + 5j) my_class.circle_area(True) my_class.circle_area('radius')
def test_area(self): """Test area when radius >= 0""" # - docstring (można z nich tworzyć dokumentację) self.assertAlmostEqual(my_class.circle_area(1), math.pi) self.assertAlmostEquals(my_class.circle_area(2, 1), math.pi * (2.1**2))