<commit_before>import os
import unittest
from gateway.utils.resourcelocator import ResourceLocator
from unittest import TestLoader

TEST_PATH = "tests"

verbosity = 1

test_loader = unittest.defaultTestLoader


def find_test_modules(test_modules=None):
    test_locator = ResourceLocator.get_locator(TEST_PATH)
    test_suite = test_loader.discover(test_locator.ROOT_PATH)
    return test_suite

def run_tests(test_classes=None):
    test_runner = unittest.TextTestRunner(verbosity=verbosity)
    if test_classes:
        suite = load_test_from_classes(test_classes)
        if not suite.countTestCases():
            return -1
        else:
            test_runner.run(suite)
            return 0


    tests = find_test_modules(test_modules)
    test_runner.run(tests)
    return 0

def load_test_from_classes(class_names):
    test_locator = ResourceLocator.get_locator(TEST_PATH)
    test_suite = test_loader.discover(test_locator.ROOT_PATH)
    temp_ts = unittest.TestSuite()
    for test in test_suite:
        suite = test.__dict__["_tests"]
        if len(suite):
            for case in suite:
                if case.__dict__["_tests"][0].__class__.__name__ in class_names:
                    temp_ts.addTest(case)
    return temp_ts


def load_module_test_case(module_name):
    return test_loader.loadTestsFromName(module_name)<commit_msg>Add documentation Clean duplicate code remove unused code<commit_after>import os
import unittest
from gateway.utils.resourcelocator import ResourceLocator
from unittest import TestLoader

TEST_PATH = "tests"
verbosity = 1
test_loader = unittest.defaultTestLoader


def find_test_modules(test_modules=None):
    test_locator = ResourceLocator.get_locator(TEST_PATH)
    test_suite = test_loader.discover(test_locator.ROOT_PATH)
    return test_suite

def run_tests(test_classes=None):
    """
    run_tests - runs a test suite with specified paramters
    :param test_classes: list of tests classnames to only test
    :return int: -1 for failure or 0 for success
    """
    test_runner = unittest.TextTestRunner(verbosity=verbosity)

    if test_classes:
        suite = load_test_from_classes(test_classes)
        if not suite.countTestCases():
            return -1
        else:
            test_runner.run(suite)
            return 0

    tests = find_test_modules(test_modules)
    test_runner.run(tests)
    return 0

def load_test_from_classes(class_names):
    """
    load_test_from_classes - returns a suite with specified class_names
    :param class_names: list of tests classnames to add to the suite
    """
    test_suite = find_test_modules()
    temp_ts = unittest.TestSuite()
    for test in test_suite:
        suite = test.__dict__["_tests"]
        if len(suite):
            for case in suite:
                if case.__dict__["_tests"][0].__class__.__name__ in class_names:
                    temp_ts.addTest(case)
    return temp_ts
{'fraction_non_alphanumeric': 0.07042253521126761, 'fraction_numerical': 0.004122294744074201, 'mean_word_length': 3.2949852507374633, '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': '92470', 'n_tokens_mistral': 893, 'n_tokens_neox': 875, 'n_words': 202}