Example #1
0
def test_get_student_out_finds_main_out_if_no_postprocess():
    env = Environment(falconf_string="""
    test:
        main: python testMain.py
    """)
    flyer = Flyer(mode='test', env=env)
    flyer.create_sequence()
    flyer.run_sequence()
    formatter = Formatter(flyer)
    steps = formatter.parse_steps(flyer)
    assert 'student_outtttt' in formatter.get_student_out(flyer)
Example #2
0
def test_get_is_correct_is_none_if_no_tag():
    env = Environment(falconf_string="""
    test:
        main: python testMain.py
    """)
    flyer = Flyer(mode='test', env=env)
    flyer.create_sequence()
    flyer.run_sequence()
    formatter = Formatter(flyer)
    steps = formatter.parse_steps(flyer)
    student_out = formatter.get_student_out(flyer)
    assert formatter.get_is_correct(student_out) is None
Example #3
0
def test_get_student_out_finds_udacity_out_if_no_postprocess():
    env = Environment(falconf_string="""
    test:
        main: python testMain.py
    """)
    msg = 'this is a message'
    flyer = Flyer(mode='test', env=env)
    flyer.create_sequence()
    flyer.run_sequence()
    formatter = Formatter(flyer)
    steps = formatter.parse_steps(flyer)
    write_udacity_out(msg)
    assert msg in formatter.get_student_out(flyer)
Example #4
0
def test_get_is_correct_is_false_if_fail_tag():
    # manually passes in output
    env = Environment(falconf_string="""
    test:
        main: echo '<::FAIL>'
    """)
    flyer = Flyer(mode='test', env=env)
    flyer.create_sequence()
    flyer.run_sequence()
    formatter = Formatter(flyer)
    steps = formatter.parse_steps(flyer)
    student_out = formatter.get_student_out(flyer)
    assert not formatter.get_is_correct(student_out)
Example #5
0
def test_formatter_parses_each_step_from_flyer(successfulFlyer):
    successfulFlyer.create_sequence()
    successfulFlyer.run_sequence()
    formatter = Formatter()
    results = formatter.parse_steps(successfulFlyer)
    assert len(results) == 5
Example #6
0
def format_results(flyer, debug, output='json'):
    """
    Use debug and output to decide how to show results of the run.

    Args:
        flyer (Flyer)
        debug (boolean)
        output (string): One of 'json', 'formatted', 'clean', 'return'. Defaults to 'json'.

    Returns:
        None: if output != 'return'
        dict: if output == 'return'
    """
    formatter = Formatter(flyer, elapsed_time=ELAPSED_TIME)
    formatter.parse_steps(flyer)

    if debug:
        # print a pretty version of the results JSON
        formatter.pipe_debug_to_stdout(flyer)
        return None
    elif output == 'return':
        # just return the results dict
        return formatter.return_results(flyer)
    elif output == 'formatted':
        """
        print results as:

        ------------------
        Executing `command` ...
        stderr
        stdout
        ------------------
        """
        results = formatter.return_results(flyer)
        steps = results['steps']

        for s in range(len(steps)):
            if steps[s]['command'] is not 'noop':
                print('Executing `{}`...'.format(steps[s]['command']))
                stderr = steps[s]['err']
                if stderr != '':
                    eprint(stderr)
                stdout = steps[s]['out']
                if stdout != '':
                    print(stdout)
                if s < len(steps) - 1:
                    print('\n------------------')
        return None
    elif output == 'clean':
        """
        print results as a sequence of:

        stderr
        stdout
        """
        results = formatter.return_results(flyer)
        steps = results['steps']

        for s in range(len(steps)):
            if steps[s]['command'] is not 'noop':
                err = steps[s]['err']
                if err != '':
                    eprint(err)
                out = steps[s]['out']
                if out != '':
                    print(out)
    else:
        # print the results JSON
        formatter.pipe_to_stdout(flyer)
        return None