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

Method test_exceptions

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

Source from the content-addressed store, hash-verified

2009 # tested.
2010 @unittest.skipUnless(verbose, 'requires verbose mode')
2011 def test_exceptions(self):
2012 try:
2013 x = math.exp(-1000000000)
2014 except:
2015 # mathmodule.c is failing to weed out underflows from libm, or
2016 # we've got an fp format with huge dynamic range
2017 self.fail("underflowing exp() should not have raised "
2018 "an exception")
2019 if x != 0:
2020 self.fail("underflowing exp() should have returned 0")
2021
2022 # If this fails, probably using a strict IEEE-754 conforming libm, and x
2023 # is +Inf afterwards. But Python wants overflows detected by default.
2024 try:
2025 x = math.exp(1000000000)
2026 except OverflowError:
2027 pass
2028 else:
2029 self.fail("overflowing exp() didn't trigger OverflowError")
2030
2031 # If this fails, it could be a puzzle. One odd possibility is that
2032 # mathmodule.c's macros are getting confused while comparing
2033 # Inf (HUGE_VAL) to a NaN, and artificially setting errno to ERANGE
2034 # as a result (and so raising OverflowError instead).
2035 try:
2036 x = math.sqrt(-1.0)
2037 except ValueError:
2038 pass
2039 else:
2040 self.fail("sqrt(-1) didn't raise ValueError")
2041
2042 @requires_IEEE_754
2043 def test_testfile(self):

Callers

nothing calls this directly

Calls 3

expMethod · 0.45
failMethod · 0.45
sqrtMethod · 0.45

Tested by

no test coverage detected