mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
Merged revisions 80753 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r80753 | mark.dickinson | 2010-05-04 15:25:50 +0100 (Tue, 04 May 2010) | 10 lines Issue #8567: Fix incorrect precedence of signals in Decimal module. When a Decimal operation raises multiple signals and more than one of those signals is trapped, the specification determines the order in which the signals should be handled. In many cases this order wasn't being followed, leading to the wrong Python exception being raised. This commit fixes those cases, and adds extra tests. The tests are only enabled when EXTENDEDERRORTESTS is True, since they involve rerunning each Decimal testcase several times. ........
This commit is contained in:
parent
a714257a66
commit
c69160e808
3 changed files with 115 additions and 44 deletions
|
@ -41,6 +41,12 @@ except ImportError:
|
|||
# Useful Test Constant
|
||||
Signals = tuple(getcontext().flags.keys())
|
||||
|
||||
# Signals ordered with respect to precedence: when an operation
|
||||
# produces multiple signals, signals occurring later in the list
|
||||
# should be handled before those occurring earlier in the list.
|
||||
OrderedSignals = (Clamped, Rounded, Inexact, Subnormal,
|
||||
Underflow, Overflow, DivisionByZero, InvalidOperation)
|
||||
|
||||
# Tests are built around these assumed context defaults.
|
||||
# test_main() restores the original context.
|
||||
def init():
|
||||
|
@ -351,6 +357,25 @@ class DecimalTest(unittest.TestCase):
|
|||
else:
|
||||
self.fail("Did not raise %s in %s" % (error, s))
|
||||
self.context.traps[error] = 0
|
||||
|
||||
# as above, but add traps cumulatively, to check precedence
|
||||
ordered_errors = [e for e in OrderedSignals if e in theirexceptions]
|
||||
for error in ordered_errors:
|
||||
self.context.traps[error] = 1
|
||||
try:
|
||||
funct(*vals)
|
||||
except error:
|
||||
pass
|
||||
except Signals as e:
|
||||
self.fail("Raised %s in %s; expected %s" %
|
||||
(type(e), s, error))
|
||||
else:
|
||||
self.fail("Did not raise %s in %s" % (error, s))
|
||||
# reset traps
|
||||
for error in ordered_errors:
|
||||
self.context.traps[error] = 0
|
||||
|
||||
|
||||
if DEBUG:
|
||||
print("--", self.context)
|
||||
try:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue