summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_math.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_math.py')
-rw-r--r--Lib/test/test_math.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/Lib/test/test_math.py b/Lib/test/test_math.py
index 6976a5d..2c57d28 100644
--- a/Lib/test/test_math.py
+++ b/Lib/test/test_math.py
@@ -2503,6 +2503,46 @@ class MathTests(unittest.TestCase):
self.assertRaises(TypeError, math.atan2, 1.0)
self.assertRaises(TypeError, math.atan2, 1.0, 2.0, 3.0)
+ def test_exception_messages(self):
+ x = -1.1
+ with self.assertRaisesRegex(ValueError,
+ f"expected a nonnegative input, got {x}"):
+ math.sqrt(x)
+ with self.assertRaisesRegex(ValueError,
+ f"expected a positive input, got {x}"):
+ math.log(x)
+ with self.assertRaisesRegex(ValueError,
+ f"expected a positive input, got {x}"):
+ math.log(123, x)
+ with self.assertRaisesRegex(ValueError,
+ f"expected a positive input, got {x}"):
+ math.log(x, 123)
+ with self.assertRaisesRegex(ValueError,
+ f"expected a positive input, got {x}"):
+ math.log2(x)
+ with self.assertRaisesRegex(ValueError,
+ f"expected a positive input, got {x}"):
+ math.log10(x)
+ x = decimal.Decimal('-1.1')
+ with self.assertRaisesRegex(ValueError,
+ f"expected a positive input, got {x}"):
+ math.log(x)
+ x = fractions.Fraction(1, 10**400)
+ with self.assertRaisesRegex(ValueError,
+ f"expected a positive input, got {float(x)}"):
+ math.log(x)
+ x = -123
+ with self.assertRaisesRegex(ValueError,
+ f"expected a positive input, got {x}"):
+ math.log(x)
+ with self.assertRaisesRegex(ValueError,
+ f"expected a float or nonnegative integer, got {x}"):
+ math.gamma(x)
+ x = 1.0
+ with self.assertRaisesRegex(ValueError,
+ f"expected a number between -1 and 1, got {x}"):
+ math.atanh(x)
+
# Custom assertions.
def assertIsNaN(self, value):