mirror of
https://github.com/python/cpython.git
synced 2025-07-29 06:05:00 +00:00
Fixed some test structures. Thanks Mark Dickinson.
This commit is contained in:
parent
7c5c8e6823
commit
ee340e501d
2 changed files with 10 additions and 21 deletions
|
@ -477,11 +477,7 @@ def localcontext(ctx=None):
|
||||||
# General Decimal Arithmetic Specification
|
# General Decimal Arithmetic Specification
|
||||||
return +s # Convert result to normal context
|
return +s # Convert result to normal context
|
||||||
|
|
||||||
"""
|
>>> setcontext(DefaultContext)
|
||||||
# The string below can't be included in the docstring until Python 2.6
|
|
||||||
# as the doctest module doesn't understand __future__ statements
|
|
||||||
"""
|
|
||||||
>>> from __future__ import with_statement
|
|
||||||
>>> print getcontext().prec
|
>>> print getcontext().prec
|
||||||
28
|
28
|
||||||
>>> with localcontext():
|
>>> with localcontext():
|
||||||
|
|
|
@ -46,10 +46,12 @@ Signals = getcontext().flags.keys()
|
||||||
def init():
|
def init():
|
||||||
global ORIGINAL_CONTEXT
|
global ORIGINAL_CONTEXT
|
||||||
ORIGINAL_CONTEXT = getcontext().copy()
|
ORIGINAL_CONTEXT = getcontext().copy()
|
||||||
DefaultContext.prec = 9
|
DefaultTestContext = Context(
|
||||||
DefaultContext.rounding = ROUND_HALF_EVEN
|
prec = 9,
|
||||||
DefaultContext.traps = dict.fromkeys(Signals, 0)
|
rounding = ROUND_HALF_EVEN,
|
||||||
setcontext(DefaultContext)
|
traps = dict.fromkeys(Signals, 0)
|
||||||
|
)
|
||||||
|
setcontext(DefaultTestContext)
|
||||||
|
|
||||||
TESTDATADIR = 'decimaltestdata'
|
TESTDATADIR = 'decimaltestdata'
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -179,8 +181,6 @@ class DecimalTest(unittest.TestCase):
|
||||||
"""
|
"""
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.context = Context()
|
self.context = Context()
|
||||||
for key in DefaultContext.traps.keys():
|
|
||||||
DefaultContext.traps[key] = 1
|
|
||||||
self.ignore_list = ['#']
|
self.ignore_list = ['#']
|
||||||
# Basically, a # means return NaN InvalidOperation.
|
# Basically, a # means return NaN InvalidOperation.
|
||||||
# Different from a sNaN in trim
|
# Different from a sNaN in trim
|
||||||
|
@ -191,13 +191,6 @@ class DecimalTest(unittest.TestCase):
|
||||||
'minexponent' : self.change_min_exponent,
|
'minexponent' : self.change_min_exponent,
|
||||||
'clamp' : self.change_clamp}
|
'clamp' : self.change_clamp}
|
||||||
|
|
||||||
def tearDown(self):
|
|
||||||
"""Cleaning up enviroment."""
|
|
||||||
# leaving context in original state
|
|
||||||
for key in DefaultContext.traps.keys():
|
|
||||||
DefaultContext.traps[key] = 0
|
|
||||||
return
|
|
||||||
|
|
||||||
def eval_file(self, file):
|
def eval_file(self, file):
|
||||||
global skip_expected
|
global skip_expected
|
||||||
if skip_expected:
|
if skip_expected:
|
||||||
|
@ -959,8 +952,8 @@ def thfunc1(cls):
|
||||||
test2 = d1/d3
|
test2 = d1/d3
|
||||||
cls.finish1.set()
|
cls.finish1.set()
|
||||||
|
|
||||||
cls.assertEqual(test1, Decimal('0.333333333'))
|
cls.assertEqual(test1, Decimal('0.3333333333333333333333333333'))
|
||||||
cls.assertEqual(test2, Decimal('0.333333333'))
|
cls.assertEqual(test2, Decimal('0.3333333333333333333333333333'))
|
||||||
return
|
return
|
||||||
|
|
||||||
def thfunc2(cls):
|
def thfunc2(cls):
|
||||||
|
@ -973,7 +966,7 @@ def thfunc2(cls):
|
||||||
cls.synchro.set()
|
cls.synchro.set()
|
||||||
cls.finish2.set()
|
cls.finish2.set()
|
||||||
|
|
||||||
cls.assertEqual(test1, Decimal('0.333333333'))
|
cls.assertEqual(test1, Decimal('0.3333333333333333333333333333'))
|
||||||
cls.assertEqual(test2, Decimal('0.333333333333333333'))
|
cls.assertEqual(test2, Decimal('0.333333333333333333'))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue