Пример #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')
Пример #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)
Пример #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
Пример #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)
Пример #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)
Пример #6
0
def falconfFlyer():
    env = Environment('falconf.yaml')
    flyer = Flyer(mode='test', env=env)
    return flyer
Пример #7
0
def test_can_be_initialized_with_env():
    env = Environment('falconf.yaml')
    flyer = Flyer(env=env)
    assert 'test/sample' in flyer.falconf_dir
Пример #8
0
def testEnvWithNothing():
    return Environment()
Пример #9
0
def testEnvWithYamlString():
    return Environment(falconf_string="""
    test:
        env_vars:
            CAM: 'is cool'
    """)
Пример #10
0
def testEnvWithYamlFile():
    return Environment(falconf_path='falconf.yaml')
Пример #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)
Пример #12
0
def unsuccessfulDebugFormat():
    env = Environment('erring_falconf.yaml')
    flyer = Flyer(mode='test', debug=True, env=env)
    return Formatter(flyer)
Пример #13
0
def successfulFormat():
    env = Environment('falconf.yaml')
    flyer = Flyer(mode='test', env=env)
    return Formatter(flyer)
Пример #14
0
def successfulFlyer():
    env = Environment('falconf.yaml')
    return Flyer(mode='test', env=env)
Пример #15
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