示例#1
0
def test_format(method, prec, exp_range, restricted_range, itr, stat):
    """Iterate the __format__ method through many test cases."""
    for op in all_unary(prec, exp_range, itr):
        fmt1 = rand_format(chr(random.randrange(0, 128)), "EeGgn")
        fmt2 = rand_locale()
        for fmt in (fmt1, fmt2):
            fmtop = (op[0], fmt)
            t = TestSet(method, fmtop)
            try:
                if not convert(t, convstr=False):
                    continue
                callfuncs(t)
                verify(t, stat)
            except VerifyError as err:
                log(err)
    for op in all_unary(prec, 9999, itr):
        fmt1 = rand_format(chr(random.randrange(0, 128)), "Ff%")
        fmt2 = rand_locale()
        for fmt in (fmt1, fmt2):
            fmtop = (op[0], fmt)
            t = TestSet(method, fmtop)
            try:
                if not convert(t, convstr=False):
                    continue
                callfuncs(t)
                verify(t, stat)
            except VerifyError as err:
                log(err)
示例#2
0
def test_format(method, prec, exp_range, restricted_range, itr, stat):
    """Iterate the __format__ method through many test cases."""
    for op in all_unary(prec, exp_range, itr):
        fmt1 = rand_format(chr(random.randrange(0, 128)), 'EeGgn')
        fmt2 = rand_locale()
        for fmt in (fmt1, fmt2):
            fmtop = (op[0], fmt)
            t = TestSet(method, fmtop)
            try:
                if not convert(t, convstr=False):
                    continue
                callfuncs(t)
                verify(t, stat)
            except VerifyError as err:
                log(err)
    for op in all_unary(prec, 9999, itr):
        fmt1 = rand_format(chr(random.randrange(0, 128)), 'Ff%')
        fmt2 = rand_locale()
        for fmt in (fmt1, fmt2):
            fmtop = (op[0], fmt)
            t = TestSet(method, fmtop)
            try:
                if not convert(t, convstr=False):
                    continue
                callfuncs(t)
                verify(t, stat)
            except VerifyError as err:
                log(err)
示例#3
0
#
# Test formatting using random format strings. This must be run
# in a UFT-8 terminal.
#
# Usage:  python3.2 genrandformat.py | ../runtest -
#


import random
from formathelper import rand_format, rand_fillchar, integers, printit
from randdec import un_incr_digits
print("rounding: half_even")


testno = 0
for x in range(1000):
    for sign in ('', '-'):
        intpart = fracpart = ''
        while (not intpart) and (not fracpart):
            intpart = random.choice(integers)
            fracpart = random.choice(integers)
        s = ''.join((sign, intpart, '.', fracpart))
        fmt = rand_format(rand_fillchar())
        testno += 1
        printit(testno, s, fmt, 'utf-8')
    for s in un_incr_digits(15, 384, 30):
        fmt = rand_format(rand_fillchar())
        testno += 1
        printit(testno, s, fmt, 'utf-8')
示例#4
0
#


import sys, locale, random
from formathelper import locale_list, rand_format, integers, printit
from randdec import un_incr_digits
print("rounding: half_even")


testno = 0
for loc in locale_list:
    try:
        locale.setlocale(locale.LC_ALL, loc)
    except locale.Error as err:
        sys.stderr.write("%s: %s\n" % (loc, err))
        continue
    print("locale: %s" % loc)
    for sign in ('', '-'):
        intpart = fracpart = ''
        while (not intpart) and (not fracpart):
            intpart = random.choice(integers)
            fracpart = random.choice(integers)
        s = ''.join((sign, intpart, '.', fracpart))
        fmt = rand_format('x')
        testno += 1
        printit(testno, s, fmt)
    for s in un_incr_digits(15, 384, 30):
        fmt = rand_format('x')
        testno += 1
        printit(testno, s, fmt)
# SUCH DAMAGE.
#

#
# Test formatting using random format strings. This must be run
# in a UFT-8 terminal.
#
# Usage:  python3.2 genrandformat.py | ../runtest -
#

import random
from formathelper import rand_format, rand_fillchar, integers, printit
from randdec import un_incr_digits
print("rounding: half_even")

testno = 0
for x in range(1000):
    for sign in ('', '-'):
        intpart = fracpart = ''
        while (not intpart) and (not fracpart):
            intpart = random.choice(integers)
            fracpart = random.choice(integers)
        s = ''.join((sign, intpart, '.', fracpart))
        fmt = rand_format(rand_fillchar())
        testno += 1
        printit(testno, s, fmt, 'utf-8')
    for s in un_incr_digits(15, 384, 30):
        fmt = rand_format(rand_fillchar())
        testno += 1
        printit(testno, s, fmt, 'utf-8')