<commit_before>"""py.test conftest file"""

from flask import g
from py.test import fixture

from tentd import create_app
from tentd.documents import collections, Entity, Post, Follower, Following

#: Constant values for various modes
SINGLE = 'single user mode'
MULTIPLE = 'multiple user mode'
SUBDOMAINS = 'subdomain multiple user mode'

def pytest_addoption(parser):
    """Add an option to chose the modes tests will be run under"""
    parser.addoption('--mode', action='store', default='domains',
        help="the mode to run pytentd in - single, multi, domains, or all")

def pytest_generate_tests(metafunc):
    """Apply the --mode option to the app fixture"""
    if 'app' in metafunc.fixturenames:
        metafunc.parametrize('app', {
            'multi': (MULTIPLE,),
            'single': (SINGLE,),
            'domains': (SUBDOMAINS,),
            'all': (SINGLE, MULTIPLE, SUBDOMAINS),
        }[metafunc.config.option.mode], indirect=True, scope="module")

def pytest_runtest_teardown(item, nextitem):
    """If the app fixture was used, clear the database after the test"""
    if 'app' in item.fixturenames:
        for collection in collections:
            collection.drop_collection()

@fixture
def app(request):
    """Create an instance of the Tentd app prepared for testing

    The scope for this fixture is defined in pytest_generate_tests"""

    single_user_mode, use_subdomains = False, False
    
    if request.param is SINGLE:
        single_user_mode = 'the_single_user'
    elif request.param is SUBDOMAINS:
        use_subdomains = True

    app = create_app({
        'DEBUG': True,
        'TESTING': True,
        'TRAP_HTTP_EXCEPTIONS': True,
        'PRESERVE_CONTEXT_ON_EXCEPTION': False,
        'SERVER_NAME': 'example.com',
        'MONGODB_SETTINGS': {
            'db': 'tentd-testing',
        },
        'SINGLE_USER_MODE': single_user_mode,
        'USE_SUBDOMAINS': use_subdomains,<commit_msg>Stop the tests early when we can't connect to the database<commit_after>"""py.test conftest file"""

from flask import g
from mongoengine.connection import ConnectionError
from py.test import fixture, exit

from tentd import create_app
from tentd.documents import collections, Entity, Post, Follower, Following

#: Constant values for various modes
SINGLE = 'single user mode'
MULTIPLE = 'multiple user mode'
SUBDOMAINS = 'subdomain multiple user mode'

def pytest_addoption(parser):
    """Add an option to chose the modes tests will be run under"""
    parser.addoption('--mode', action='store', default='domains',
        help="the mode to run pytentd in - single, multi, domains, or all")

def pytest_generate_tests(metafunc):
    """Apply the --mode option to the app fixture"""
    if 'app' in metafunc.fixturenames:
        metafunc.parametrize('app', {
            'multi': (MULTIPLE,),
            'single': (SINGLE,),
            'domains': (SUBDOMAINS,),
            'all': (SINGLE, MULTIPLE, SUBDOMAINS),
        }[metafunc.config.option.mode], indirect=True, scope="module")

def pytest_runtest_teardown(item, nextitem):
    """If the app fixture was used, clear the database after the test"""
    if 'app' in item.fixturenames:
        for collection in collections:
            collection.drop_collection()

def pytest_runtest_makereport (item, call):
    """Stop the tests early when we can't connect to the database"""
    if hasattr(call.excinfo, 'type'):
        if call.excinfo.type == ConnectionError:
            exit("Could not connect to the database")

@fixture
def app(request):
    """Create an instance of the Tentd app prepared for testing

    The scope for this fixture is defined in pytest_generate_tests"""

    single_user_mode, use_subdomains = False, False
    
    if request.param is SINGLE:
        single_user_mode = 'the_single_user'
    elif request.param is SUBDOMAINS:
        use_subdomains = True

    app = create_app({
        'DEBUG': True,
        'TESTING': True,
        'TRAP_HTTP_EXCEPTIONS': True,
        'PRESERVE_CONTEXT_ON_EXCEPTION': False,
        'SERVER_NAME': 'example.com',
        'MONGODB_SETTINGS': {
            'db': 'tentd-testing',
        },
        'SINGLE_USER_MODE': single_user_mode,
        'USE_SUBDOMAINS': use_subdomains,
{'fraction_non_alphanumeric': 0.10548622557099128, 'fraction_numerical': 0.0, 'mean_word_length': 3.226865671641791, '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': '4788573', 'n_tokens_mistral': 1288, 'n_tokens_neox': 1281, 'n_words': 397}