<commit_before>#!/usr/bin/env python
# coding=utf8

import pytest

sqlalchemy = pytest.importorskip('sqlalchemy')
from sqlalchemy import create_engine, MetaData

from simplekv.db.sql import SQLAlchemyStore

from basic_store import BasicStore


# FIXME: for local testing, this needs configurable dsns
class TestSQLAlchemyStore(BasicStore):
    DSNS = [
        ('pymysql',
         'mysql+pymysql://travis:@localhost/simplekv_test'),
        ('psycopg2',
         'postgresql+psycopg2://postgres:@127.0.0.1/simplekv_test'),
        ('sqlite3',
         'sqlite:///:memory:')
    ]

    @pytest.fixture(params=DSNS, ids=[v[0] for v in DSNS])
    def engine(self, request):
        module_name, dsn = request.param
        # check module is available
        pytest.importorskip(module_name)
        return create_engine(dsn)
<commit_msg>Skip SQLAlchemy tests if DB not available.<commit_after>#!/usr/bin/env python
# coding=utf8

import pytest

sqlalchemy = pytest.importorskip('sqlalchemy')
from sqlalchemy import create_engine, MetaData
from sqlalchemy.exc import OperationalError

from simplekv.db.sql import SQLAlchemyStore

from basic_store import BasicStore


# FIXME: for local testing, this needs configurable dsns
class TestSQLAlchemyStore(BasicStore):
    DSNS = [
        ('pymysql',
         'mysql+pymysql://travis:@localhost/simplekv_test'),
        ('psycopg2',
         'postgresql+psycopg2://postgres:@127.0.0.1/simplekv_test'),
        ('sqlite3',
         'sqlite:///:memory:')
    ]

    @pytest.fixture(params=DSNS, ids=[v[0] for v in DSNS])
    def engine(self, request):
        module_name, dsn = request.param
        # check module is available
        pytest.importorskip(module_name)
        engine = create_engine(dsn)
        try:
            engine.connect()
        except OperationalError:
            pytest.skip('could not connect to database {}'.format(dsn))
        return engine

{'fraction_non_alphanumeric': 0.11169102296450939, 'fraction_numerical': 0.011482254697286013, 'mean_word_length': 3.176470588235294, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '1326715', 'n_tokens_mistral': 637, 'n_tokens_neox': 627, 'n_words': 134}