def new_trace(slug, concept, title, published):
    concept = CONCEPTS[concept - 1]
    info('Creating trace challenge', slug)
    ch_dir = TRACES / slug
    if ch_dir.is_dir():
        danger(f'There is already a trace called {slug}')
        sys.exit()

    os.mkdir(ch_dir)
    create_file(ch_dir / DETAILS, build_details(concept, title, published))
    create_file(ch_dir / TRACE_CODE)
示例#2
0
def novo(slug):
    info('Criando exercício', slug)
    ex_dir = EXERCICIOS / slug
    if ex_dir.is_dir():
        danger(f'Já existe um exercício chamado {slug}')
        sys.exit()

    os.mkdir(ex_dir)
    cria_arquivo(ex_dir / DETALHES, TEMPLATE_DETALHES)
    cria_arquivo(ex_dir / ENUNCIADO)
    cria_arquivo(ex_dir / TESTES, TEMPLATE_TESTES)
    cria_arquivo(ex_dir / 'solucao.py')
    cria_arquivo(ex_dir / 'errado.py')
示例#3
0
def valida_exercicio(ex_dir):
    info('Testando exercício', ex_dir)
    ok = True
    try:
        detalhes = valida_detalhes(ex_dir)
        valida_enunciado(ex_dir)
        aplica_testes(ex_dir, detalhes.get('nome_funcao'))
    except AssertionError as e:
        danger('Erro de validação:', e)
        ok = False
    if ok:
        success("OK")
    else:
        danger('FALHA')
    return ok
def build_trace(slug=None, force=False):
    if slug:
        if not (TRACES / slug).is_dir():
            danger(f'The trace challenge {slug} does not exist.')
            sys.exit()
        run_autotracer(slug)
    else:
        info('Building all missing trace challenges')
        count = 0
        for ch_dir in TRACES.iterdir():
            if not ch_dir.is_dir(): continue
            if not force and (ch_dir / TRACE_DATA).is_file(): continue
            run_autotracer(ch_dir.name)
            count += 1
        success(f'Built {count} traces')
示例#5
0
def validate_challenge_dir(ch_dir):
    info('Validating challenge', ch_dir)
    ok = True
    try:
        details = validate_challenge_details(ch_dir)
        validate_question(ch_dir)
        run_tests_for_challenge(ch_dir, details.get('function_name'))
    except AssertionError as e:
        danger('Validation error:', e)
        ok = False
    if ok:
        success("OK")
    else:
        danger('FAIL')
    return ok
示例#6
0
def teste(nome_teste):
    if nome_teste:
        if not (EXERCICIOS / nome_teste).is_dir():
            danger(f'O exercício {nome_teste} não existe.')
            sys.exit()
        valida_exercicio(EXERCICIOS / nome_teste)
    else:
        info('Testando todos os exercícios')
        ok = True
        for ex_dir in EXERCICIOS.iterdir():
            if not ex_dir.is_dir(): continue
            if not valida_exercicio(ex_dir):
                ok = False
        if ok:
            success('Tudo ok!')
        else:
            danger('Falhou em alguma validação')
def validate_trace_dir(ch_dir):
    info('Validating trace challenge', ch_dir)
    ok = True
    try:
        validate_trace_details(ch_dir)
        validate_not_empty(ch_dir / TRACE_CODE)
        validate_not_empty(
            ch_dir / TRACE_DATA,
            msg='Trace file does not exist. Build it with admin.py build-trace'
        )
    except AssertionError as e:
        danger('Validation error:', e)
        ok = False
    if ok:
        success("OK")
    else:
        danger('FAIL')
    return ok
def validate_trace(slug=None):
    if slug:
        if not (TRACES / slug).is_dir():
            danger(f'The trace challenge {slug} does not exist.')
            sys.exit()
        validate_trace_dir(TRACES / slug)
    else:
        info('Testing all trace challenges')
        failures = []
        for ch_dir in TRACES.iterdir():
            if not ch_dir.is_dir(): continue
            if not validate_trace_dir(ch_dir):
                failures.append(ch_dir.name)
        if failures:
            danger('Failed for the following traces')
            for failure in failures:
                danger(f'  {failure}')
        else:
            success('Everything ok!')
示例#9
0
def validate_challenge(challenge_name=None):
    if challenge_name:
        if not (CHALLENGES / challenge_name).is_dir():
            danger(f'The challenge {challenge_name} does not exist.')
            sys.exit()
        validate_challenge_dir(CHALLENGES / challenge_name)
    else:
        info('Testing all challenges')
        failures = []
        for ch_dir in CHALLENGES.iterdir():
            if not ch_dir.is_dir(): continue
            if not validate_challenge_dir(ch_dir):
                failures.append(ch_dir.name)
        if failures:
            danger('Failed for the following challenges:')
            for failure in failures:
                danger(f'  {failure}')
        else:
            success('Everything ok!')
示例#10
0
def new_challenge(concept):
    concept = f'"{CONCEPTS[concept-1]}"'

    title = click.prompt('Title').strip()
    if not title:
        danger(f'Title cannot be empty')
        sys.exit()

    slug = click.prompt('Slug', default=slugify(title)).strip()
    if not slug:
        danger(f'Slug cannot be empty')
        sys.exit()

    function_name = click.prompt('Function name').strip()
    if function_name:
        function_name = f'"{function_name}"'
    else:
        function_name = 'null'

    info('Creating challenge', slug)
    ch_dir = CHALLENGES / slug
    if ch_dir.is_dir():
        danger(f'There is already a challenge called {slug}')
        sys.exit()

    os.mkdir(ch_dir)
    (ch_dir / RAW_DIR / slug).mkdir(parents=True, exist_ok=True)
    create_file(
        ch_dir / DETAILS,
        TEMPLATE_DETAILS.format(title=title,
                                function_name=function_name,
                                concept=concept))
    create_file(ch_dir / QUESTION)
    open_in_editor(ch_dir / QUESTION)
    create_file(ch_dir / TESTS, TEMPLATE_TESTS)
    open_in_editor(ch_dir / TESTS)
    create_file(ch_dir / 'solution.py')
    open_in_editor(ch_dir / 'solution.py')
    create_file(ch_dir / 'wrong.py')
    open_in_editor(ch_dir / 'wrong.py')