<commit_before>import pytest

from dockci.models.job import Job, JobStageTmp
from dockci.models.project import Project
from dockci.server import DB


def create_project(slug, **kwargs):
    """ Create a ``Project`` with defaults """
    final_kwargs = dict(
        name=slug,
        slug=slug,
        utility=False,
        repo='test',
        public=True,
    )
    final_kwargs.update(kwargs)
    return Project(**final_kwargs)


def create_job(**kwargs):
    """ Create a ``Job`` with defaults """
    final_kwargs = dict(
        repo_fs='test',
        commit='test',
    )
    final_kwargs.update(kwargs)
    return Job(**final_kwargs)


class TestProjectsSummary(object):
    """ Ensure ``Project.get_status_summary`` behaves as expected """

    def setup_method(self, _):
        JobStageTmp.query.delete()
        Job.query.delete()
    def teardown_method(self, _):
        JobStageTmp.query.delete()
        Job.query.delete()


    @pytest.mark.parametrize('models,p_filters,exp_s,exp_f,exp_b,exp_i', [
        (
            (
                (create_project('p1'),              create_job(result='success')),
                (create_project('p2'),              create_job()),
                (create_project('u', utility=True), create_job()),
            ),
            None,
            1, 0, 0, 2,
        ),
        (
            (
                (create_project('p1'),              create_job()),
                (create_project('p2'),              create_job()),
                (create_project('u', utility=True), create_job(result='success')),
            ),
            None,
            1, 0, 0, 2,
        ),
        (
            (
                (create_project('p1'),              create_job(result='success')),
                (create_project('p2'),              create_job()),
                (create_project('u', utility=True), create_job(result='success')),
            ),
            None,
            2, 0, 0, 1,
        ),
        (
            (
                (create_project('p1'),              create_job(result='fail')),
                (create_project('p2'),              create_job()),
                (create_project('u', utility=True), create_job(result='success')),
            ),
            None,
            1, 1, 0, 1,
        ),
        (
            (
                (create_project('p1'),              create_job(result='broken')),
                (create_project('p2'),              create_job()),
                (create_project('u', utility=True), create_job(result='success')),
            ),
            None,
            1, 0, 1, 1,
        ),
        (
            (
                (create_project('p1'),              create_job(result='broken')),
                (create_project('p2'),              create_job()),
                (create_project('u', utility=True), create_job(result='success')),
            ),
            {'utility': False},
            0, 0, 1, 1,
        ),
        (
            (
                (create_project('p1'),              create_job(result='broken')),
                (create_project('p2'),              create_job()),
                (create_project('u', utility=True), create_job(result='success')),
            ),
            {'utility': True},
            1, 0, 0, 0,
        ),
        (
            (
                (create_project('p1'),              create_job(result='broken')),
                (create_project('p2'),              create_job(result='broken')),
                (create_project('u', utility=True), create_job(result='success')),
            ),
            None,
            1, 0, 2, 0,
        ),
    ])
    def test_it(self, db, models, p_filters, exp_s, exp_f, exp_b, exp_i):
        """ Commit models, assert status summary is accurate """
        for project, *jobs in models:
            DB.session.add(project)
            for job in jobs:
                job.project = project
                DB.session.add(job)
                print('job')

        DB.session.commit()

        assert Project.get_status_summary(p_filters) == dict(
            success=exp_s,
            fail=exp_f,
            broken=exp_b,
            incomplete=exp_i,
        )<commit_msg>Remoe debug print<commit_after>import pytest

from dockci.models.job import Job, JobStageTmp
from dockci.models.project import Project
from dockci.server import DB


def create_project(slug, **kwargs):
    """ Create a ``Project`` with defaults """
    final_kwargs = dict(
        name=slug,
        slug=slug,
        utility=False,
        repo='test',
        public=True,
    )
    final_kwargs.update(kwargs)
    return Project(**final_kwargs)


def create_job(**kwargs):
    """ Create a ``Job`` with defaults """
    final_kwargs = dict(
        repo_fs='test',
        commit='test',
    )
    final_kwargs.update(kwargs)
    return Job(**final_kwargs)


class TestProjectsSummary(object):
    """ Ensure ``Project.get_status_summary`` behaves as expected """

    def setup_method(self, _):
        JobStageTmp.query.delete()
        Job.query.delete()
    def teardown_method(self, _):
        JobStageTmp.query.delete()
        Job.query.delete()


    @pytest.mark.parametrize('models,p_filters,exp_s,exp_f,exp_b,exp_i', [
        (
            (
                (create_project('p1'),              create_job(result='success')),
                (create_project('p2'),              create_job()),
                (create_project('u', utility=True), create_job()),
            ),
            None,
            1, 0, 0, 2,
        ),
        (
            (
                (create_project('p1'),              create_job()),
                (create_project('p2'),              create_job()),
                (create_project('u', utility=True), create_job(result='success')),
            ),
            None,
            1, 0, 0, 2,
        ),
        (
            (
                (create_project('p1'),              create_job(result='success')),
                (create_project('p2'),              create_job()),
                (create_project('u', utility=True), create_job(result='success')),
            ),
            None,
            2, 0, 0, 1,
        ),
        (
            (
                (create_project('p1'),              create_job(result='fail')),
                (create_project('p2'),              create_job()),
                (create_project('u', utility=True), create_job(result='success')),
            ),
            None,
            1, 1, 0, 1,
        ),
        (
            (
                (create_project('p1'),              create_job(result='broken')),
                (create_project('p2'),              create_job()),
                (create_project('u', utility=True), create_job(result='success')),
            ),
            None,
            1, 0, 1, 1,
        ),
        (
            (
                (create_project('p1'),              create_job(result='broken')),
                (create_project('p2'),              create_job()),
                (create_project('u', utility=True), create_job(result='success')),
            ),
            {'utility': False},
            0, 0, 1, 1,
        ),
        (
            (
                (create_project('p1'),              create_job(result='broken')),
                (create_project('p2'),              create_job()),
                (create_project('u', utility=True), create_job(result='success')),
            ),
            {'utility': True},
            1, 0, 0, 0,
        ),
        (
            (
                (create_project('p1'),              create_job(result='broken')),
                (create_project('p2'),              create_job(result='broken')),
                (create_project('u', utility=True), create_job(result='success')),
            ),
            None,
            1, 0, 2, 0,
        ),
    ])
    def test_it(self, db, models, p_filters, exp_s, exp_f, exp_b, exp_i):
        """ Commit models, assert status summary is accurate """
        for project, *jobs in models:
            DB.session.add(project)
            for job in jobs:
                job.project = project
                DB.session.add(job)

        DB.session.commit()

        assert Project.get_status_summary(p_filters) == dict(
            success=exp_s,
            fail=exp_f,
            broken=exp_b,
            incomplete=exp_i,
        )
{'fraction_non_alphanumeric': 0.1396294082486551, 'fraction_numerical': 0.011476389719067543, 'mean_word_length': 1.4663915094339623, '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': '5545140', 'n_tokens_mistral': 2425, 'n_tokens_neox': 2300, 'n_words': 399}