Exemplo n.º 1
0
def iter_equations(test_id, suites=None):
    assert isinstance(test_id, str), test_id
    for term, comment, message in iter_test_cases(test_id, suites):
        if is_equal(term):
            lhs = link(bohm.convert(term[1]))
            rhs = link(bohm.convert(term[2]))
            example = lhs, rhs, message
            if comment and parse_xfail(comment, test_id):
                example = pytest.mark.xfail(example)
            yield example
        else:
            raise NotImplementedError(message)
Exemplo n.º 2
0
def iter_equations(test_id, suites=None):
    assert isinstance(test_id, str), test_id
    for code, comment, message in iter_test_cases(test_id, suites):
        if is_app(code) and is_app(code[1]) and code[1][1] is EQUAL:
            lhs = code[1][2]
            rhs = code[2]
            if is_quote(lhs) and is_quote(rhs):
                lhs = link(compile_(lhs[1]))
                rhs = link(compile_(rhs[1]))
                example = lhs, rhs, message
                if comment and parse_xfail(comment, test_id):
                    example = pytest.mark.xfail(example)
                yield example
Exemplo n.º 3
0
def reduce(string, engine='engine', fmt='auto'):
    """Reduce code.

    Args:
        string: code to reduce, in some parsable format specified by fmt
        engine: 'engine'
        fmt: one of 'auto', 'polish', or 'sexpr'

    """
    if fmt == 'auto':
        fmt = guess_format(string)
    if engine not in ENGINES:
        raise ValueError('Unknown engine {}, try one of: {}'.format(
            engine, ', '.join(ENGINES.keys())))
    print('Format: {}'.format(fmt))
    print('Engine: {}'.format(engine))
    print('In: {}'.format(string))
    parse, print_, simplify = FORMATS[fmt]
    code = parse(string)
    code = link(code)
    result = ENGINES[engine].reduce(code)
    result_string = print_(result)
    print('Out: {}'.format(result_string))
    return result_string
Exemplo n.º 4
0
def test_link(code, expected):
    expected = as_code(expected)
    actual = link(code)
    assert actual == expected
Exemplo n.º 5
0
def test_link(term, expected):
    expected = as_term(expected)
    actual = link(term)
    assert actual == expected