<commit_before>#
# Copyright (C) 2021 <NAME> <<EMAIL>>
# SPDX-License-Identifier: MIT
#
# pylint: disable=missing-docstring
r"""Common utility functions.
"""
import pathlib

import anyconfig.dicts
import anyconfig.api as TT


RES_DIR = pathlib.Path(__file__).parent / '../../../' / 'res'
DIC_0 = anyconfig.dicts.convert_to(dict())


def datasets_itr(kind):
    for rdir in sorted(pathlib.Path(RES_DIR / 'multi' / kind).glob('*')):
        if not rdir.is_dir():
            continue

        exp = TT.single_load(rdir / 'e' / 'exp.json')
        opts = TT.single_load(rdir / 'options' / '00.json')

        yield (rdir, exp, opts)


def gen_datasets(kind='basics'):
    datasets = sorted(datasets_itr(kind))
    if not datasets:
        raise RuntimeError('No test data was found!')

    return datasets

# vim:sw=4:ts=4:et:
<commit_msg>change: add tests.api.load.multi_load.common.BaseTestCase to simplify test cases<commit_after>#
# Copyright (C) 2021 <NAME> <<EMAIL>>
# SPDX-License-Identifier: MIT
#
# pylint: disable=missing-docstring
r"""Common utility functions.
"""
import functools
import pathlib
import unittest

import anyconfig.dicts
import anyconfig.api as TT


RES_DIR = pathlib.Path(__file__).parent / '../../../' / 'res'
DIC_0 = anyconfig.dicts.convert_to(dict())


def datasets_itr(kind):
    for rdir in sorted(pathlib.Path(RES_DIR / 'multi' / kind).glob('*')):
        if not rdir.is_dir():
            continue

        exp = TT.single_load(rdir / 'e' / 'exp.json')
        opts = TT.single_load(rdir / 'options' / '00.json')

        yield (rdir, exp, opts)


def gen_datasets(kind):
    datasets = sorted(datasets_itr(kind))
    if not datasets:
        raise RuntimeError('No test data was found!')

    return datasets


class BaseTestCase(unittest.TestCase):

    kind = 'basics'

    @property
    @functools.lru_cache(None)
    def datasets(self):
        return gen_datasets(self.kind)

# vim:sw=4:ts=4:et:

{'fraction_non_alphanumeric': 0.14632885211995864, 'fraction_numerical': 0.009307135470527405, 'mean_word_length': 3.2434210526315788, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '7231223', 'n_tokens_mistral': 693, 'n_tokens_neox': 666, 'n_words': 152}