MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_exception_messages

Method test_exception_messages

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

Source from the content-addressed store, hash-verified

2514 self.assertRaises(TypeError, math.atan2, 1.0, 2.0, 3.0)
2515
2516 def test_exception_messages(self):
2517 x = -1.1
2518 with self.assertRaisesRegex(ValueError,
2519 f"expected a nonnegative input, got {x}"):
2520 math.sqrt(x)
2521 with self.assertRaisesRegex(ValueError,
2522 f"expected a positive input, got {x}"):
2523 math.log(x)
2524 with self.assertRaisesRegex(ValueError,
2525 f"expected a positive input, got {x}"):
2526 math.log(123, x)
2527 with self.assertRaisesRegex(ValueError,
2528 f"expected a positive input, got {x}"):
2529 math.log(x, 123)
2530 with self.assertRaisesRegex(ValueError,
2531 f"expected a positive input, got {x}"):
2532 math.log2(x)
2533 with self.assertRaisesRegex(ValueError,
2534 f"expected a positive input, got {x}"):
2535 math.log10(x)
2536 x = decimal.Decimal('-1.1')
2537 with self.assertRaisesRegex(ValueError,
2538 f"expected a positive input, got {x}"):
2539 math.log(x)
2540 x = fractions.Fraction(1, 10**400)
2541 with self.assertRaisesRegex(ValueError,
2542 f"expected a positive input, got {float(x)}"):
2543 math.log(x)
2544 x = -123
2545 with self.assertRaisesRegex(ValueError,
2546 "expected a positive input$"):
2547 math.log(x)
2548 with self.assertRaisesRegex(ValueError,
2549 f"expected a noninteger or positive integer, got {x}"):
2550 math.gamma(x)
2551 x = 1.0
2552 with self.assertRaisesRegex(ValueError,
2553 f"expected a number between -1 and 1, got {x}"):
2554 math.atanh(x)
2555
2556 # Custom assertions.
2557

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