Work through several open todos:
* Added test for pickling contexts
* Renamed ExceptionList to Signals (to match wording in the spec)
* Simplified Context constructor by allowing flags=None to automatically
generate a zeroed-out flags dictionary.
* inlined _convertString() which was used only once
* _rounding_decision is private, so excluded its contants from __all__.
* added an XXX comment with concerns about subclassing signals results in
a deviation from the spec (maybe important, maybe not).
* Taught the test_suite to determine its own directory (modeled after code
in regrtest.py). Enables it to be run when the current directory is not
the test directory.
* Added a clear_flags() method to the Context API to make it easier to do
a common operation with flags.
* Fixed the trap_enablers defaults in BasicDefaultContext to match the spec.
diff --git a/Lib/test/test_decimal.py b/Lib/test/test_decimal.py
index b3fb0ad..6da658f 100644
--- a/Lib/test/test_decimal.py
+++ b/Lib/test/test_decimal.py
@@ -35,7 +35,12 @@
import threading
TESTDATADIR = 'decimaltestdata'
-dir = os.curdir + os.sep + TESTDATADIR + os.sep
+if __name__ == '__main__':
+ file = sys.argv[0]
+else:
+ file = __file__
+testdir = os.path.dirname(file) or os.curdir
+dir = testdir + os.sep + TESTDATADIR + os.sep
skip_expected = not os.path.isdir(dir)
@@ -190,7 +195,7 @@
quote = 0
theirexceptions = [ErrorNames[x.lower()] for x in exceptions]
- for exception in ExceptionList:
+ for exception in Signals:
self.context.trap_enablers[exception] = 1 #Catch these bugs...
for exception in theirexceptions:
self.context.trap_enablers[exception] = 0
@@ -212,7 +217,7 @@
funct(self.context.create_decimal(v))
except error:
pass
- except ExceptionList, e:
+ except Signals, e:
self.fail("Raised %s in %s when %s disabled" % \
(e, s, error))
else:
@@ -232,7 +237,7 @@
funct(*vals)
except error:
pass
- except ExceptionList, e:
+ except Signals, e:
self.fail("Raised %s in %s when %s disabled" % \
(e, s, error))
else:
@@ -242,7 +247,7 @@
result = str(funct(*vals))
if fname == 'same_quantum':
result = str(int(eval(result))) # 'True', 'False' -> '1', '0'
- except ExceptionList, error:
+ except Signals, error:
self.fail("Raised %s in %s" % (error, s))
except: #Catch any error long enough to state the test case.
print "ERROR:", s
@@ -263,13 +268,13 @@
def getexceptions(self):
L = []
- for exception in ExceptionList:
+ for exception in Signals:
if self.context.flags[exception]:
L.append(exception)
return L
def resetflags(self):
- for exception in ExceptionList:
+ for exception in Signals:
self.context.flags[exception] = 0
def change_precision(self, prec):
@@ -1046,6 +1051,16 @@
e = pickle.loads(p)
self.assertEqual(d, e)
+class ContextAPItests(unittest.TestCase):
+
+ def test_pickle(self):
+ c = Context()
+ e = pickle.loads(pickle.dumps(c))
+ for k in vars(c):
+ v1 = vars(c)[k]
+ v2 = vars(e)[k]
+ self.assertEqual(v1, v2)
+
def test_main(arith=False, verbose=None):
""" Execute the tests.
@@ -1059,6 +1074,7 @@
DecimalUseOfContextTest,
DecimalUsabilityTest,
DecimalPythonAPItests,
+ ContextAPItests,
]
if arith or is_resource_enabled('decimal'):