Пример #1
0
def iter_test_cases(test_id, suites=None):
    assert isinstance(test_id, str), test_id
    print('test_id = {}'.format(test_id))
    if suites is None:
        module = import_module('pomagma.reducer.engines.{}'.format(test_id))
        suites = module.SUPPORTED_TESTDATA
    for suite in suites:
        filename = '{}/{}.sexpr'.format(TESTDATA, suite)
        print('reading {}'.format(filename))
        with open(filename) as f:
            for i, line in enumerate(f):
                parts = line.split(';', 1)
                sexpr = parts[0].strip()
                if sexpr:
                    message = 'In {}:{}\n{}'.format(filename, 1 + i, line)
                    try:
                        code = sexpr_parse(sexpr)
                    except ValueError as e:
                        raise ValueError('{} {}'.format(message, e))
                    comment = None if len(parts) < 2 else parts[1].strip()
                    yield code, comment, message
Пример #2
0
def sexpr_simplify(string):
    return sexpr_parse(string, SIGNATURE)
Пример #3
0
def test_sexpr_simplify(sexpr, expected):
    assert sexpr_simplify(sexpr) is sexpr_parse(expected)
Пример #4
0
def test_polish_simplify(sexpr, expected):
    polish = polish_print(sexpr_parse(sexpr))
    assert polish_simplify(polish) is sexpr_parse(expected)
Пример #5
0
def test_sexpr_print_parse(code):
    string = sexpr_print(code)
    assert isinstance(string, str)
    actual_code = sexpr_parse(string)
    assert actual_code == code
Пример #6
0
def test_sexpr_parse(example):
    actual = sexpr_parse(example['sexpr'])
    assert actual == example['code']