Beispiel #1
0
def get_uris(names, warning=True):
    uris = []
    for name in names:
        if '://' in name:  # regular uri string
            uri = sqlplain.util.dissect(name)
        else:  # just the driver name
            uri = sqlplain.util.dissect_from_config(
                'config://scratch/%s_uri' % name)
        if is_available(uri['name']):
            uris.append(uri)
        elif warning:
            sys.stderr.write(
                'Skipping tests for %s, driver not installed\n' % name)
    return uris
Beispiel #2
0
"Tests specific to postgres"

from sqlplain import core
from sqlplain._util import create
from sqlplain.util import is_available

if is_available('psycopg2'):

    db = core.ScratchDB('config://scratch/psycopg2_uri', create)

    def setup():
        db.open()

    def teardown():
        db.close()

    def test_named_cursor():
        cu = db.conn.dbapi.cursor('aname')
        try:
            cu.execute('select * from client')
            rows = cu.fetchall()
            assert len(rows) == 2, len(rows)
        finally:
            cu.close()

    def test_NamedTupleCursor():
        from psycopg2.extras import NamedTupleCursor

        class NamedTupleConnection(core.Connection):
            def cursor(self):
                return NamedTupleCursor(self.dbapi)