Пример #1
0
def test_markup(filename):
    log_path = os.path.join(os.path.dirname(__file__), 'logs', 'EAC', filename)
    log_file = Path(log_path)
    log = score_log(log_file, markup=True)

    markup_path = os.path.join(os.path.dirname(__file__), 'logs', 'EAC',
                               'markup', '{}.markup'.format(filename))
    with open(markup_path, 'r') as markup_file:
        markup_contents = markup_file.read()

    assert log['contents'] == markup_contents
Пример #2
0
def score_(args, log_file, log_path):
    log = score_log(log_file, args.markup)
    if args.score_only:
        if not log['unrecognized']:
            print(log['score'])
        else:
            print('Log is unrecognized: {}'.format(log['unrecognized']))
    else:
        try:
            print(format_score(log_path, log, args.markup))
        except UnicodeEncodeError as error:
            print('Cannot encode logpath: {}'.format(error))
Пример #3
0
def handle_file(action, file_):
    filename = get_filename()
    file_.save(filename)
    log_file = Path(filename)
    if action == 'Score':
        contents = score_log(log_file, markup=True)
        contents['contents'] = Markup(contents['contents'])
        return render_template('score.html', contents=contents)
    elif action == 'Translate':
        contents = translate_log(log_file)
        if 'log' in contents:
            contents['log'] = Markup(contents['log'])
        return render_template('translate.html', contents=contents)
Пример #4
0
def _check_log(path, score_only, translate):
    figle = Path(path)
    scored_log = score_log(figle, markup=False)
    if score_only:
        if scored_log["unrecognized"]:
            return click.secho("Unrecognized")
        return click.echo(scored_log["score"])

    try:
        click.echo(format_score(path, scored_log, markup=False))
        if translate:
            translated_log = translate_log(figle)
            click.secho(
                "\n---------------------------------------------------\n" +
                format_translation(path, translated_log))
    except UnicodeEncodeError as e:
        click.secho(f"Could not encode logpath: {e}")
Пример #5
0
def test_scoring(filename, deductions):
    log_path = os.path.join(os.path.dirname(__file__), 'logs', 'EAC', filename)
    log_file = Path(log_path)
    log = score_log(log_file)
    assert deductions == {d[0] for d in log['deductions']}
#!/usr/bin/env python3

import sys
from os import path
from pathlib import Path

from heybrochecklog.score import score_log

for log_path in sys.argv[1:]:
    log_file = Path(log_path)
    if not log_file.is_file():
        print('{} does not exist.'.format(log_path))
        continue

    log = score_log(log_file, markup=True)
    dir_, file_name = path.split(log_path)
    output_path = path.join(dir_, 'markup', file_name + '.markup')

    with open(output_path, 'w') as output_file:
        output_file.write(log['contents'])

    print('Wrote marked up log to {}.'.format(output_path))
Пример #7
0
def test_scoring(filename, unrecognized_reason):
    log_path = os.path.join(os.path.dirname(__file__), 'logs', 'unrecognized',
                            filename)
    log_file = Path(log_path)
    log = score_log(log_file)
    assert log['unrecognized'] == unrecognized_reason