Exemplo n.º 1
0
def test_symlinking_libraries():
    env = Environment(falconf_string="""
    test:
        libraries:
            - cpp
    """)
    flyer = Flyer(mode='test', env=env)
    flyer.symlink_libraries()
    assert does_file_exist('cpp/include/Grader.h')
    remove_symlink('cpp')
Exemplo n.º 2
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)
Exemplo n.º 3
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
Exemplo n.º 4
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)
Exemplo n.º 5
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)
Exemplo n.º 6
0
def fly(args, falconf, env):
    """
    Take off! Build the sequence and execute it.

    Args:
        args (dict): From argparse.
        falconf (string): falconf.yaml contents.
        env (Environment)

    Returns:
        Flyer
    """
    start_time = CURRENT_MILLI_TIME()
    env.parse_falconf(falconf)
    flyer = Flyer(mode=args['mode'], debug=args['debug'], env=env)
    flyer.create_sequence()
    flyer.run_sequence()
    end_time = CURRENT_MILLI_TIME()
    ELAPSED_TIME = end_time - start_time
    return flyer
Exemplo n.º 7
0
def debugFlyer():
    return Flyer(debug=True)
Exemplo n.º 8
0
def submitFlyer():
    return Flyer(mode='submit')
Exemplo n.º 9
0
def testFlyer():
    return Flyer(mode='test')
Exemplo n.º 10
0
def test_can_be_initialized_with_env():
    env = Environment('falconf.yaml')
    flyer = Flyer(env=env)
    assert 'test/sample' in flyer.falconf_dir
Exemplo n.º 11
0
def test_formatter_pipes_a_json_string_to_stdout():
    env = Environment('falconf.yaml')
    flyer = Flyer(mode='test', env=env)
    formatter = Formatter(flyer)
    out = capture_stdout(lambda : formatter.pipe_to_stdout(flyer))
    assert isinstance(json.loads(out), dict)
Exemplo n.º 12
0
def unsuccessfulDebugFormat():
    env = Environment('erring_falconf.yaml')
    flyer = Flyer(mode='test', debug=True, env=env)
    return Formatter(flyer)
Exemplo n.º 13
0
def successfulFormat():
    env = Environment('falconf.yaml')
    flyer = Flyer(mode='test', env=env)
    return Formatter(flyer)
Exemplo n.º 14
0
def successfulFlyer():
    env = Environment('falconf.yaml')
    return Flyer(mode='test', env=env)
Exemplo n.º 15
0
def localFlyer():
    return Flyer(local=True)
Exemplo n.º 16
0
def falconfFlyer():
    env = Environment('falconf.yaml')
    flyer = Flyer(mode='test', env=env)
    return flyer
Exemplo n.º 17
0
def main(args={}):
    """
    The main event.

    Args:
        args (dict)

    Returns:
        int: Exit code.
        string: If output == 'return'
    """
    exit_code = 1
    falconf = None
    local_falconf = None
    env = Environment()

    # this dictionary checking exists to rectify defaults with command line args and the config dict passed to udfalcon.fly()
    if not exists(dictionary=args, key='debug'):
        args['debug'] = False

    if not exists(dictionary=args, key='link'):
        args['link'] = False

    if not exists(dictionary=args, key='mode'):
        args['mode'] = 'submit'

    if not exists(dictionary=args, key='output'):
        args['output'] = 'json'

    # symlink and then shortcircuit if they used --link
    if exists(dictionary=args, key='link') and args['link']:
        flyer = Flyer()
        if flyer.symlink_libraries(args['link']):
            return 0
        else:
            return 1

    # find a falconf file
    if is_valid_falconf_specified(args):
        with open(args['config'], 'r') as f:
            falconf = f.read()

        # change the path if the falconf is elsewhere
        newpath = os.path.dirname(falconf)
        if newpath != '':
            os.chdir(newpath)

    elif file_exists('falconf.yaml') or file_exists('falconf.yml'):
        if args['debug']:
            print('Using local falconf file.')
        falconf = env.get_local_falconf()

    possible_results_output = None

    # run student code
    if falconf is not None:
        flyer = fly(args, falconf, env)
        possible_results_output = format_results(flyer, args['debug'],
                                                 args['output'])
        exit_code = 0
    elif args['debug']:
        eprint('No falconf found.')

    if possible_results_output is not None:
        return possible_results_output
    else:
        return exit_code