<commit_before>from django.test.runner import DiscoverRunner
from django.db import connection, IntegrityError
from django.core import management

from tenant_schemas.utils import get_tenant_model

from bluebottle.test.factory_models.rates import RateSourceFactory, RateFactory
from bluebottle.test.utils import InitProjectDataMixin


class MultiTenantRunner(DiscoverRunner, InitProjectDataMixin):
    def setup_databases(self, *args, **kwargs):
        parallel = self.parallel
        self.parallel = 0
        result = super(MultiTenantRunner, self).setup_databases(**kwargs)
        self.parallel = parallel

        connection.set_schema_to_public()

        tenant2, _created = get_tenant_model().objects.get_or_create(
            domain_url='testserver2',
            schema_name='test2',
            client_name='test2')

        tenant, _created = get_tenant_model().objects.get_or_create(
            domain_url='testserver',
            schema_name='test',
            client_name='test')

        connection.set_tenant(tenant)

        self.init_projects()

        try:
            rate_source = RateSourceFactory.create(base_currency='USD')
            RateFactory.create(source=rate_source, currency='USD', value=1)
            RateFactory.create(source=rate_source, currency='EUR', value=1.5)
            RateFactory.create(source=rate_source, currency='XOF', value=1000)
            RateFactory.create(source=rate_source, currency='NGN', value=500)
        except IntegrityError:
            pass

        if parallel > 1:
            for index in range(parallel):
                connection.creation.clone_test_db(
                    number=index + 1,
                    verbosity=self.verbosity,
                    keepdb=self.keepdb,
                )

<commit_msg>Fix pep8<commit_after>from django.test.runner import DiscoverRunner
from django.db import connection, IntegrityError
from django.core import management

from tenant_schemas.utils import get_tenant_model

from bluebottle.test.factory_models.rates import RateSourceFactory, RateFactory
from bluebottle.test.utils import InitProjectDataMixin


class MultiTenantRunner(DiscoverRunner, InitProjectDataMixin):
    def setup_databases(self, *args, **kwargs):
        parallel = self.parallel
        self.parallel = 0
        result = super(MultiTenantRunner, self).setup_databases(**kwargs)
        self.parallel = parallel

        connection.set_schema_to_public()

        tenant2, _created = get_tenant_model().objects.get_or_create(
            domain_url='testserver2',
            schema_name='test2',
            client_name='test2')

        tenant, _created = get_tenant_model().objects.get_or_create(
            domain_url='testserver',
            schema_name='test',
            client_name='test')

        connection.set_tenant(tenant)

        self.init_projects()

        try:
            rate_source = RateSourceFactory.create(base_currency='USD')
            RateFactory.create(source=rate_source, currency='USD', value=1)
            RateFactory.create(source=rate_source, currency='EUR', value=1.5)
            RateFactory.create(source=rate_source, currency='XOF', value=1000)
            RateFactory.create(source=rate_source, currency='NGN', value=500)
        except IntegrityError:
            pass

        if parallel > 1:
            for index in range(parallel):
                connection.creation.clone_test_db(
                    number=index + 1,
                    verbosity=self.verbosity,
                    keepdb=self.keepdb,
                )

{'fraction_non_alphanumeric': 0.08795518207282914, 'fraction_numerical': 0.00980392156862745, 'mean_word_length': 2.655066530194473, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3842169', 'n_tokens_mistral': 999, 'n_tokens_neox': 956, 'n_words': 175}