Exemplo n.º 1
0
def has_same_result(source_path, ref_path, verbose=False, print_ast=False):
    with open(source_path, 'r') as f_source, open(ref_path, 'r') as f_ref:
        source = f_source.read()
        reference = f_ref.read()

    # Pipe stdout to a variable

    old_stdout = sys.stdout
    sys.stdout = mystdout = StringIO()

    try:
        run(source, verbose=verbose, print_ast=print_ast)
        result =  mystdout.getvalue()
    except Exception as e:
        raise e
    finally:
        sys.stdout = old_stdout

    if verbose or result != reference:
        print('')
        print(source_path)
        print(result)
        print(reference)     

    return result == reference
Exemplo n.º 2
0
def has_same_result(source_path, ref_path, verbose=False, print_ast=False):
    with open(source_path, 'r') as f_source, open(ref_path, 'r') as f_ref:
        source = f_source.read()
        reference = f_ref.read()

    # Pipe stdout to a variable

    old_stdout = sys.stdout
    sys.stdout = mystdout = StringIO()

    try:
        run(source, verbose=verbose, print_ast=print_ast)
        result = mystdout.getvalue()
    except Exception as e:
        raise e
    finally:
        sys.stdout = old_stdout

    if verbose or result != reference:
        print('')
        print(source_path)
        print(result)
        print(reference)

    return result == reference
Exemplo n.º 3
0
def test_constant_int():
    run('42;')
Exemplo n.º 4
0
def test_identifier():
    ns = {'a': 42}
    run('a;', ns)
Exemplo n.º 5
0
def assert_res(source, variables={}, verbose=False, print_ast=False):
    ns = {}
    run(source, ns, verbose, print_ast)
    for key, value in variables.items():
        eq_(ns.get(key, None), value)
Exemplo n.º 6
0
def test_constant_int():
    run('42;')
Exemplo n.º 7
0
def test_identifier():
    ns = {'a' : 42}
    run('a;', ns)
Exemplo n.º 8
0
def assert_res(source, variables={}, verbose=False, print_ast=False):
    ns = {}
    run(source, ns, verbose, print_ast)
    for key, value in variables.items():
        eq_(ns.get(key, None), value)