| 1 |
""" Try to test systematically all cases of the math module. |
| 2 |
""" |
| 3 |
|
| 4 |
import py, sys, math |
| 5 |
from rpython.rlib import rfloat |
| 6 |
from rpython.rtyper.lltypesystem.module.test.math_cases import (MathTests, |
| 7 |
get_tester) |
| 8 |
|
| 9 |
class TestDirect(MathTests): |
| 10 |
pass |
| 11 |
|
| 12 |
def do_test(fn, fnname, args, expected): |
| 13 |
repr = "%s(%s)" % (fnname, ', '.join(map(str, args))) |
| 14 |
try: |
| 15 |
got = fn(*args) |
| 16 |
except ValueError: |
| 17 |
assert expected == ValueError, "%s: got a ValueError" % (repr,) |
| 18 |
except OverflowError: |
| 19 |
assert expected == OverflowError, "%s: got an OverflowError" % ( |
| 20 |
repr,) |
| 21 |
else: |
| 22 |
if not get_tester(expected)(got): |
| 23 |
raise AssertionError("%r: got %s" % (repr, got)) |
| 24 |
|
| 25 |
def make_test_case((fnname, args, expected), dict): |
| 26 |
|
| 27 |
def test_func(self): |
| 28 |
try: |
| 29 |
fn = getattr(math, fnname) |
| 30 |
except AttributeError: |
| 31 |
fn = getattr(rfloat, fnname) |
| 32 |
do_test(fn, fnname, args, expected) |
| 33 |
|
| 34 |
dict[fnname] = dict.get(fnname, 0) + 1 |
| 35 |
testname = 'test_%s_%d' % (fnname, dict[fnname]) |
| 36 |
test_func.func_name = testname |
| 37 |
setattr(TestDirect, testname, test_func) |
| 38 |
|
| 39 |
_d = {} |
| 40 |
for testcase in TestDirect.TESTCASES: |
| 41 |
make_test_case(testcase, _d) |