[pypy-svn] r72289 - pypy/branch/ll_math/pypy/module/math/test
arigo at codespeak.net
arigo at codespeak.net
Tue Mar 16 16:44:11 CET 2010
Author: arigo
Date: Tue Mar 16 16:44:09 2010
New Revision: 72289
Added:
pypy/branch/ll_math/pypy/module/math/test/test_math.py (contents, props changed)
Modified:
pypy/branch/ll_math/pypy/module/math/test/test_direct.py
Log:
Add test_math, which tests the mixed module (or directly
the underlying host interpreter when run with -A).
Modified: pypy/branch/ll_math/pypy/module/math/test/test_direct.py
==============================================================================
--- pypy/branch/ll_math/pypy/module/math/test/test_direct.py (original)
+++ pypy/branch/ll_math/pypy/module/math/test/test_direct.py Tue Mar 16 16:44:09 2010
@@ -4,6 +4,11 @@
import py, sys, math
from pypy.rlib.rarithmetic import isinf, isnan, INFINITY, NAN
+consistent = True
+if '__pypy__' not in sys.builtin_module_names:
+ if sys.version_info < (2, 6):
+ consistent = False
+
def positiveinf(x):
return isinf(x) and x > 0.0
@@ -170,33 +175,35 @@
class TestDirect(MathTests):
pass
+def do_test(fn, fnname, args, expected):
+ repr = "%s(%s)" % (fnname, ', '.join(map(str, args)))
+ try:
+ got = fn(*args)
+ except ValueError:
+ assert expected == ValueError, "%s: got a ValueError" % (repr,)
+ except OverflowError:
+ assert expected == OverflowError, "%s: got an OverflowError" % (
+ repr,)
+ else:
+ if callable(expected):
+ ok = expected(got)
+ else:
+ assert finite(expected), "badly written test"
+ gotsign = expectedsign = 1
+ if got < 0.0: gotsign = -gotsign
+ if expected < 0.0: expectedsign = -expectedsign
+ ok = finite(got) and (got == expected and
+ gotsign == expectedsign)
+ if not ok:
+ raise AssertionError("%r: got %s" % (repr, got))
+
def make_test_case((fnname, args, expected), dict):
#
def test_func(self):
- if '__pypy__' not in sys.builtin_module_names:
- if sys.version_info < (2, 6):
- py.test.skip("inconsistent behavior before 2.6")
+ if not consistent:
+ py.test.skip("inconsistent behavior before 2.6")
fn = getattr(math, fnname)
- repr = "%s(%s)" % (fnname, ', '.join(map(str, args)))
- try:
- got = fn(*args)
- except ValueError:
- assert expected == ValueError, "%s: got a ValueError" % (repr,)
- except OverflowError:
- assert expected == OverflowError, "%s: got an OverflowError" % (
- repr,)
- else:
- if callable(expected):
- ok = expected(got)
- else:
- assert finite(expected), "badly written test"
- gotsign = expectedsign = 1
- if got < 0.0: gotsign = -gotsign
- if expected < 0.0: expectedsign = -expectedsign
- ok = finite(got) and (got == expected and
- gotsign == expectedsign)
- if not ok:
- raise AssertionError("%r: got %s" % (repr, got))
+ do_test(fn, fnname, args, expected)
#
dict[fnname] = dict.get(fnname, 0) + 1
testname = 'test_%s_%d' % (fnname, dict[fnname])
Added: pypy/branch/ll_math/pypy/module/math/test/test_math.py
==============================================================================
--- (empty file)
+++ pypy/branch/ll_math/pypy/module/math/test/test_math.py Tue Mar 16 16:44:09 2010
@@ -0,0 +1,37 @@
+import sys
+from pypy.conftest import gettestobjspace
+from pypy.module.math.test import test_direct
+
+
+class AppTestMath:
+ def setup_class(cls):
+ cls.space = gettestobjspace(usemodules=['math'])
+ cls.w_cases = cls.space.wrap(test_direct.MathTests.TESTCASES)
+ cls.w_consistent = cls.space.wrap(test_direct.consistent)
+
+ def test_all_cases(self):
+ import math
+ for fnname, args, expected in self.cases:
+ fn = getattr(math, fnname)
+ print fn, args
+ try:
+ got = fn(*args)
+ except ValueError:
+ assert expected == ValueError
+ except OverflowError:
+ if not self.consistent:
+ if expected == ValueError:
+ continue # e.g. for 'log'
+ if callable(expected):
+ continue # e.g. for 'ceil'
+ assert expected == OverflowError
+ else:
+ if callable(expected):
+ ok = expected(got)
+ else:
+ gotsign = expectedsign = 1
+ if got < 0.0: gotsign = -gotsign
+ if expected < 0.0: expectedsign = -expectedsign
+ ok = got == expected and gotsign == expectedsign
+ if not ok:
+ raise AssertionError("%r: got %s" % (repr, got))
More information about the Pypy-commit
mailing list