<commit_before>import re
from django.template.loader import render_to_string
from tasks.const import STATUS_SUCCESS, STATUS_FAILED
from .base import library


@library.register('py_unittest')
def py_unittest_violation(data):
    """Python unittest violation parser"""
    lines = data['raw'].split('\n')
    line = ''
    while len(lines) and not line.startswith('Ran'):
        line = lines.pop(0)

    summary = line
    status = lines.pop(1)

    data['status'] =\
        STATUS_SUCCESS if status.find('OK') == 0 else STATUS_FAILED

    data['preview'] = render_to_string('violations/py_tests/preview.html', {
        'summary': summary,
        'status': status,
    })
    data['prepared'] = render_to_string('violations/py_tests/prepared.html', {
        'raw': data['raw'],
    })

    plot = {'failures': 0, 'errors': 0}
    fail_match = re.match(r'.*failures=(\d*).*', status)
    if fail_match:
        plot['failures'] = int(fail_match.groups()[0])
    error_match = re.match(r'.*errors=(\d*).*', status)
    if error_match:
        plot['errors'] = int(error_match.groups()[0])

    data['plot'] = plot
    return data<commit_msg>Add total tests count to py unittest graph<commit_after>import re
from django.template.loader import render_to_string
from tasks.const import STATUS_SUCCESS, STATUS_FAILED
from .base import library


@library.register('py_unittest')
def py_unittest_violation(data):
    """Python unittest violation parser"""
    lines = data['raw'].split('\n')
    line = ''
    while len(lines) and not line.startswith('Ran'):
        line = lines.pop(0)

    summary = line
    status = lines.pop(1)

    data['status'] =\
        STATUS_SUCCESS if status.find('OK') == 0 else STATUS_FAILED

    data['preview'] = render_to_string('violations/py_tests/preview.html', {
        'summary': summary,
        'status': status,
    })
    data['prepared'] = render_to_string('violations/py_tests/prepared.html', {
        'raw': data['raw'],
    })

    plot = {'failures': 0, 'errors': 0}
    fail_match = re.match(r'.*failures=(\d*).*', status)
    if fail_match:
        plot['failures'] = int(fail_match.groups()[0])
    error_match = re.match(r'.*errors=(\d*).*', status)
    if error_match:
        plot['errors'] = int(error_match.groups()[0])
    total_match = re.match(r'Ran (\d*) tests .*', summary)
    if total_match:
        plot['test_count'] = int(total_match.groups()[0])

    data['plot'] = plot
    return data
{'fraction_non_alphanumeric': 0.16231647634584012, 'fraction_numerical': 0.006117455138662317, 'mean_word_length': 3.411870503597122, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4408687', 'n_tokens_mistral': 814, 'n_tokens_neox': 789, 'n_words': 167}