Esempio 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
Esempio 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
Esempio n. 3
0
def test_constant_int():
    run('42;')
Esempio n. 4
0
def test_identifier():
    ns = {'a': 42}
    run('a;', ns)
Esempio 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)
Esempio n. 6
0
def test_constant_int():
    run('42;')
Esempio n. 7
0
def test_identifier():
    ns = {'a' : 42}
    run('a;', ns)
Esempio 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)