MCPcopy Index your code
hub / github.com/python/cpython / test_exception_messages

Method test_exception_messages

Lib/test/test_math.py:2423–2461  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

2421 self.assertRaises(TypeError, math.atan2, 1.0, 2.0, 3.0)
2422
2423 def test_exception_messages(self):
2424 x = -1.1
2425 with self.assertRaisesRegex(ValueError,
2426 f"expected a nonnegative input, got {x}"):
2427 math.sqrt(x)
2428 with self.assertRaisesRegex(ValueError,
2429 f"expected a positive input, got {x}"):
2430 math.log(x)
2431 with self.assertRaisesRegex(ValueError,
2432 f"expected a positive input, got {x}"):
2433 math.log(123, x)
2434 with self.assertRaisesRegex(ValueError,
2435 f"expected a positive input, got {x}"):
2436 math.log(x, 123)
2437 with self.assertRaisesRegex(ValueError,
2438 f"expected a positive input, got {x}"):
2439 math.log2(x)
2440 with self.assertRaisesRegex(ValueError,
2441 f"expected a positive input, got {x}"):
2442 math.log10(x)
2443 x = decimal.Decimal('-1.1')
2444 with self.assertRaisesRegex(ValueError,
2445 f"expected a positive input, got {x}"):
2446 math.log(x)
2447 x = fractions.Fraction(1, 10**400)
2448 with self.assertRaisesRegex(ValueError,
2449 f"expected a positive input, got {float(x)}"):
2450 math.log(x)
2451 x = -123
2452 with self.assertRaisesRegex(ValueError,
2453 "expected a positive input$"):
2454 math.log(x)
2455 with self.assertRaisesRegex(ValueError,
2456 f"expected a noninteger or positive integer, got {x}"):
2457 math.gamma(x)
2458 x = 1.0
2459 with self.assertRaisesRegex(ValueError,
2460 f"expected a number between -1 and 1, got {x}"):
2461 math.atanh(x)
2462
2463 # Custom assertions.
2464

Callers

nothing calls this directly

Calls 4

assertRaisesRegexMethod · 0.80
sqrtMethod · 0.45
logMethod · 0.45
log10Method · 0.45

Tested by

no test coverage detected