summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_decimal.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2004-08-17 05:42:09 (GMT)
committerRaymond Hettinger <python@rcn.com>2004-08-17 05:42:09 (GMT)
commitf63ba43733aca984272540040d43ddf0c3fbdae9 (patch)
treea4cc1d8d97dc5f4a7ef1bb5766adba6c7e301d56 /Lib/test/test_decimal.py
parent8de636e2ae8743a92a587b7c65837df40737bf78 (diff)
downloadcpython-f63ba43733aca984272540040d43ddf0c3fbdae9.zip
cpython-f63ba43733aca984272540040d43ddf0c3fbdae9.tar.gz
cpython-f63ba43733aca984272540040d43ddf0c3fbdae9.tar.bz2
* Dynamically build a list of files to be tested (necessary because
version 2.39 of dectest.zip adds some new test files and because some existing test files were getting skipped). * Remove two docstrings which cluttered unittest's output. * Simplify a for-loop with a list comprehension.
Diffstat (limited to 'Lib/test/test_decimal.py')
-rw-r--r--Lib/test/test_decimal.py95
1 files changed, 14 insertions, 81 deletions
diff --git a/Lib/test/test_decimal.py b/Lib/test/test_decimal.py
index a32caed..6c8dc6b 100644
--- a/Lib/test/test_decimal.py
+++ b/Lib/test/test_decimal.py
@@ -279,11 +279,7 @@ class DecimalTest(unittest.TestCase):
return
def getexceptions(self):
- L = []
- for exception in Signals:
- if self.context.flags[exception]:
- L.append(exception)
- return L
+ return [e for e in Signals if self.context.flags[e]]
def change_precision(self, prec):
self.context.prec = prec
@@ -296,85 +292,24 @@ class DecimalTest(unittest.TestCase):
def change_clamp(self, clamp):
self.context._clamp = clamp
- def test_abs(self):
- self.eval_file(dir + 'abs' + '.decTest')
-
- def test_add(self):
- self.eval_file(dir + 'add' + '.decTest')
-
- def test_base(self):
- self.eval_file(dir + 'base' + '.decTest')
-
- def test_clamp(self):
- self.eval_file(dir + 'clamp' + '.decTest')
-
- def test_compare(self):
- self.eval_file(dir + 'compare' + '.decTest')
-
- def test_divide(self):
- self.eval_file(dir + 'divide' + '.decTest')
-
- def test_divideint(self):
- self.eval_file(dir + 'divideint' + '.decTest')
-
- def test_inexact(self):
- self.eval_file(dir + 'inexact' + '.decTest')
-
- def test_max(self):
- self.eval_file(dir + 'max' + '.decTest')
-
- def test_min(self):
- self.eval_file(dir + 'min' + '.decTest')
-
- def test_minus(self):
- self.eval_file(dir + 'minus' + '.decTest')
-
- def test_multiply(self):
- self.eval_file(dir+'multiply'+'.decTest')
-
- def test_normalize(self):
- self.eval_file(dir + 'normalize' + '.decTest')
+# Dynamically build custom test definition for each file in the test
+# directory and add the definitions to the DecimalTest class. This
+# procedure insures that new files do not get skipped.
+for filename in os.listdir(dir):
+ if '.decTest' not in filename:
+ continue
+ ## XXX buildout to include integer and trim
+ if 'integer' in filename or 'trim' in filename:
+ continue
+ head, tail = filename.split('.')
+ tester = lambda self, f=filename: self.eval_file(dir + f)
+ setattr(DecimalTest, 'test_' + head, tester)
+ del filename, head, tail, tester
- def test_plus(self):
- self.eval_file(dir + 'plus' + '.decTest')
-
- def test_power(self):
- self.eval_file(dir + 'power' + '.decTest')
-
- def test_quantize(self):
- self.eval_file(dir + 'quantize' + '.decTest')
-
- def test_randomBound32(self):
- self.eval_file(dir + 'randomBound32' + '.decTest')
-
- def test_randoms(self):
- self.eval_file(dir + 'randoms' + '.decTest')
-
- def test_remainder(self):
- self.eval_file(dir + 'remainder' + '.decTest')
-
- def test_remainderNear(self):
- self.eval_file(dir + 'remainderNear' + '.decTest')
-
- def test_rounding(self):
- self.eval_file(dir + 'rounding' + '.decTest')
-
- def test_samequantum(self):
- self.eval_file(dir + 'samequantum' + '.decTest')
-
- def test_squareroot(self):
- self.eval_file(dir + 'squareroot' + '.decTest')
-
- def test_subtract(self):
- self.eval_file(dir + 'subtract' + '.decTest')
-
- def test_tointegral(self):
- self.eval_file(dir + 'tointegral' + '.decTest')
# The following classes test the behaviour of Decimal according to PEP 327
-
class DecimalExplicitConstructionTest(unittest.TestCase):
'''Unit tests for Explicit Construction cases of Decimal.'''
@@ -403,7 +338,6 @@ class DecimalExplicitConstructionTest(unittest.TestCase):
self.assertEqual(str(d), '0')
def test_explicit_from_string(self):
- '''Explicit construction with string.'''
#empty
self.assertEqual(str(Decimal('')), 'NaN')
@@ -815,7 +749,6 @@ class DecimalUsabilityTest(unittest.TestCase):
'''Unit tests for Usability cases of Decimal.'''
def test_comparison_operators(self):
- '''Testing ==, !=, <, >, <=, >=, cmp.'''
da = Decimal('23.42')
db = Decimal('23.42')