def test_foo1_unusual_type_specific_msg(self): """ test for incorrect type and specific error message :return: """ with self.assertRaises(TypeError) as err: foo_lib.foo1("hello") self.assertEqual("Cannot square root a non-number.", str(err.exception))
def test_foo1_unusual_negative_specific_msg(self): with self.assertRaises(ValueError) as err: foo_lib.foo1(-16) self.assertEqual("cannot square a negative number", str(err.exception))
def test_foo1_general2(self): self.assertEqual(4, foo_lib.foo1(16))
def test_foo1_general1(self): self.assertEqual(3, foo_lib.foo1(9)) # expected value, actual value
def test_foo1_unusual_negative_specific_msg(self): with self.assertRaises(ValueError) as err: # 'err' stores info about the error that is generated from code foo_lib.foo1(-16) self.assertEqual("Cannot square root a negative number", str(err.exception)) # test for equivalent of the error
def test_foo1_general1(self): self.assertEqual(3, foo_lib.foo1(9))