| 1 |
import py, math |
| 2 |
from rpython.rtyper.lltypesystem.module.test.math_cases import (MathTests, |
| 3 |
get_tester) |
| 4 |
from rpython.translator.c.test.test_standalone import StandaloneTests |
| 5 |
from rpython.rlib import rfloat |
| 6 |
|
| 7 |
|
| 8 |
def get_test_case((fnname, args, expected)): |
| 9 |
try: |
| 10 |
fn = getattr(math, fnname) |
| 11 |
except AttributeError: |
| 12 |
fn = getattr(rfloat, fnname) |
| 13 |
expect_valueerror = (expected == ValueError) |
| 14 |
expect_overflowerror = (expected == OverflowError) |
| 15 |
check = get_tester(expected) |
| 16 |
|
| 17 |
def testfn(): |
| 18 |
try: |
| 19 |
got = fn(*args) |
| 20 |
except ValueError: |
| 21 |
return expect_valueerror |
| 22 |
except OverflowError: |
| 23 |
return expect_overflowerror |
| 24 |
else: |
| 25 |
return check(got) |
| 26 |
|
| 27 |
testfn.__name__ = 'test_' + fnname |
| 28 |
return testfn |
| 29 |
|
| 30 |
|
| 31 |
testfnlist = [get_test_case(testcase) |
| 32 |
for testcase in MathTests.TESTCASES] |
| 33 |
reprlist = [repr(testcase) |
| 34 |
for testcase in MathTests.TESTCASES] |
| 35 |
|
| 36 |
def fn(args): |
| 37 |
err = False |
| 38 |
for i in range(len(testfnlist)): |
| 39 |
testfn = testfnlist[i] |
| 40 |
if not testfn(): |
| 41 |
print "error:", reprlist[i] |
| 42 |
err = True |
| 43 |
if not err: |
| 44 |
print "all ok" |
| 45 |
return 0 |
| 46 |
|
| 47 |
|
| 48 |
class TestMath(StandaloneTests): |
| 49 |
|
| 50 |
def test_math(self, debug=True): |
| 51 |
t, cbuilder = self.compile(fn, debug=debug) |
| 52 |
data = cbuilder.cmdexec('') |
| 53 |
if "error:" in data: |
| 54 |
py.test.fail(data.strip()) |
| 55 |
else: |
| 56 |
assert "all ok" in data |
| 57 |
|
| 58 |
def test_math_nodebug(self): |
| 59 |
self.test_math(debug=False) |