Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _get_conn_and_tracer(self):
conn = self._conn = yield from aiopg.connect(**POSTGRES_CONFIG)
Pin.get_from(conn).clone(tracer=self.tracer).onto(conn)
return conn, self.tracer
async def start_firing(number):
async with aiopg.connect(loop=loop, **pg_kwargs) as connection:
async with connection.cursor(cursor_factory=cursor_factory) as cursor:
bus = await transactional_bus_factory()
await bus.client.register_api_async(dummy_api)
for x in range(0, 50):
async with lightbus_set_database(bus, connection, apis=["my.dummy"]):
await bus.my.dummy.my_event.fire_async(field="a")
await cursor.execute(
"INSERT INTO test_table VALUES (%s)", [f"{number}-{x}"]
)
await bus.client.close_async()
async def test_connect_to_unsupported_port(unused_port, loop, pg_params):
port = unused_port()
pg_params['port'] = port
with pytest.raises(psycopg2.OperationalError):
await aiopg.connect(loop=loop, **pg_params)
async def test___del__(loop, pg_params, warning):
exc_handler = mock.Mock()
loop.set_exception_handler(exc_handler)
conn = await aiopg.connect(loop=loop, **pg_params)
with warning(ResourceWarning):
del conn
gc.collect()
msg = {'connection': mock.ANY, # conn was deleted
'message': 'Unclosed connection'}
if loop.get_debug():
msg['source_traceback'] = mock.ANY
exc_handler.assert_called_with(loop, msg)
eq_(len(spans), 1)
# Test unpatch
unpatch()
conn = yield from aiopg.connect(**POSTGRES_CONFIG)
yield from (yield from conn.cursor()).execute('select \'blah\'')
conn.close()
spans = writer.pop()
assert not spans, spans
# Test patch again
patch()
conn = yield from aiopg.connect(**POSTGRES_CONFIG)
Pin.get_from(conn).clone(service=service, tracer=tracer).onto(conn)
yield from (yield from conn.cursor()).execute('select \'blah\'')
conn.close()
spans = writer.pop()
assert spans, spans
eq_(len(spans), 1)
def _get_conn_and_tracer(self):
conn = self._conn = yield from aiopg.connect(**POSTGRES_CONFIG)
Pin.get_from(conn).clone(tracer=self.tracer).onto(conn)
return conn, self.tracer
async def test_connect_context_manager(loop, pg_params):
async with aiopg.connect(loop=loop, **pg_params) as conn:
cursor = await conn.cursor()
await cursor.execute('SELECT 42')
resp = await cursor.fetchone()
assert resp == (42,)
cursor.close()
assert conn.closed
async def aiopg_connect(args):
conn = await aiopg.connect(user=args.pguser, host=args.pghost,
port=args.pgport)
return conn