<commit_before>import os
import shutil
import pytest

from unit.applications.proto import TestApplicationProto
from conftest import option


class TestApplicationPython(TestApplicationProto):
    application_type = "python"

    def load(self, script, name=None, **kwargs):
        print()
        if name is None:
            name = script

        if script[0] == '/':
            script_path = script
        else:
            script_path = option.test_dir + '/python/' + script

        if kwargs.get('isolation') and kwargs['isolation'].get('rootfs'):
            rootfs = kwargs['isolation']['rootfs']

            if not os.path.exists(rootfs + '/app/python/'):
                os.makedirs(rootfs + '/app/python/')

            if not os.path.exists(rootfs + '/app/python/' + name):
                shutil.copytree(script_path, rootfs + '/app/python/' + name)

            script_path = '/app/python/' + name

        appication_type = self.get_appication_type()

        if appication_type is None:
            appication_type = self.application_type

        self._load_conf(
            {
                "listeners": {"*:7080": {"pass": "applications/" + name}},
                "applications": {
                    name: {
                        "type": appication_type,
                        "processes": {"spare": 0},
                        "path": script_path,
                        "working_directory": script_path,
                        "module": "wsgi",
                    }
                },
            },
            **kwargs
        )<commit_msg>Tests: introduced module name configuration.<commit_after>import os
import shutil
import pytest

from unit.applications.proto import TestApplicationProto
from urllib.parse import quote
from conftest import option


class TestApplicationPython(TestApplicationProto):
    application_type = "python"
    load_module = "wsgi"

    def load(self, script, name=None, module=None, **kwargs):
        print()
        if name is None:
            name = script

        if module is None:
            module = self.load_module

        if script[0] == '/':
            script_path = script
        else:
            script_path = option.test_dir + '/python/' + script

        if kwargs.get('isolation') and kwargs['isolation'].get('rootfs'):
            rootfs = kwargs['isolation']['rootfs']

            if not os.path.exists(rootfs + '/app/python/'):
                os.makedirs(rootfs + '/app/python/')

            if not os.path.exists(rootfs + '/app/python/' + name):
                shutil.copytree(script_path, rootfs + '/app/python/' + name)

            script_path = '/app/python/' + name

        appication_type = self.get_appication_type()

        if appication_type is None:
            appication_type = self.application_type

        self._load_conf(
            {
                "listeners": {
                    "*:7080": {"pass": "applications/" + quote(name, '')}
                },
                "applications": {
                    name: {
                        "type": appication_type,
                        "processes": {"spare": 0},
                        "path": script_path,
                        "working_directory": script_path,
                        "module": module,
                    }
                },
            },
            **kwargs
        )
{'fraction_non_alphanumeric': 0.11503112955825674, 'fraction_numerical': 0.0035576638007708272, 'mean_word_length': 1.5657794676806083, 'pattern_counts': {'":': 20, '<': 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': '2476874', 'n_tokens_mistral': 918, 'n_tokens_neox': 869, 'n_words': 199}