def _makeSqlite(parsed): from norm.sqlite import sqlite connstr = mkConnStr(parsed) db = sqlite.connect(connstr) db.row_factory = sqlite.Row runner = BlockingRunner(db) runner.db_scheme = 'sqlite' return defer.succeed(runner)
def t(i, expected): expected_parts = expected.split(' ') parsed = parseURI(i) output = mkConnStr(parsed) parts = output.split(' ') self.assertEqual(set(expected_parts), set(parts), "Expected URI\n %r\nto become like conn " "string\n %r\nbut it was\n %r" % (i, expected, output))
def _makeBlockingPostgres(parsed, connections=1): import psycopg2 from psycopg2.extras import DictCursor connstr = mkConnStr(parsed) pool = ConnectionPool() pool.db_scheme = 'postgres' for i in xrange(connections): db = psycopg2.connect(connstr, cursor_factory=DictCursor) runner = PostgresRunner(db) pool.add(runner) return defer.succeed(pool)
def _makeTxPostgres(parsed, connections=1): from norm.tx_postgres import DictConnection pool = ConnectionPool() pool.db_scheme = 'postgres' connstr = mkConnStr(parsed) dlist = [] for i in xrange(connections): conn = DictConnection() d = conn.connect(connstr) d.addCallback(lambda _: pool.add(conn)) dlist.append(d) ret = defer.gatherResults(dlist) return ret.addCallback(lambda _: pool)
def postgresConnStr(): if not postgres_url: raise SkipTest(skip_postgres) return mkConnStr(parseURI(postgres_url))
def t(self, i, expected): parsed = parseURI(i) output = mkConnStr(parsed) self.assertEqual(output, expected, "Expected URI %r to become conn " "string\n%r\nbut it was\n%r" % (i, expected, output))