import asyncio
from aiopg import sa

import unittest

from sqlalchemy import MetaData, Table, Column, Integer, String

meta = MetaData()
tbl = Table('sa_tbl3', meta,
            Column('id', Integer, nullable=False,
                   primary_key=True),
            Column('name', String(255)))


class TestEngine(unittest.TestCase):
    def setUp(self):
        self.loop = asyncio.new_event_loop()
        asyncio.set_event_loop(None)
        self.engine = self.loop.run_until_complete(
            sa.create_engine(database='aiopg',
                             user='aiopg',
                             password='passwd',
                             host='127.0.0.1',
                             loop=self.loop))
        self.loop.run_until_complete(self.start())

    def tearDown(self):
        self.loop.close()

    @asyncio.coroutine
    def start(self, **kwargs):
        with (yield from self.engine) as conn:
            yield from conn.execute("DROP TABLE IF EXISTS sa_tbl3")
            yield from conn.execute("CREATE TABLE sa_tbl3 "
                                    "(id serial, name varchar(255))")

    def test_dialect(self):
        self.assertEqual(sa.dialect, self.engine.dialect)

    def test_name(self):
        self.assertEqual('postgresql', self.engine.name)

    def test_driver(self):
        self.assertEqual('psycopg2', self.engine.driver)

    def test_dsn(self):
        self.assertEqual(
            'dbname=aiopg user=aiopg password=xxxxxx host=127.0.0.1',
            self.engine.dsn)

@@ -481,28 +481,255 @@
 omplete(
-%0A           
+self.make_engine())%0A        self.loop.run_until_complete(self.start())%0A%0A    def tearDown(self):%0A        self.loop.close()%0A%0A    @asyncio.coroutine%0A    def make_engine(self, use_loop=True):%0A        if use_loop:%0A            return (yield from
  sa.crea
@@ -785,16 +785,35 @@
         
+      
+             
 user='ai
@@ -847,16 +847,35 @@
         
+          
+         
 password
@@ -914,16 +914,35 @@
         
+              
+     
 host='12
@@ -943,32 +943,51 @@
 st='127.0.0.1',%0A
+                   
                 
@@ -1028,100 +1028,274 @@
     
-self.loop.run_until_complete(self.start())%0A%0A    def tearDown(self):%0A        self.loop.close(
+else:%0A            return (yield from sa.create_engine(database='aiopg',%0A                                                user='aiopg',%0A                                                password='passwd',%0A                                                host='127.0.0.1')
 )%0A%0A 
@@ -1338,18 +1338,8 @@
 self
-, **kwargs
 ):%0A 
@@ -1987,8 +1987,902 @@
 ne.dsn)%0A
+%0A    def test_make_engine_with_default_loop(self):%0A%0A        @asyncio.coroutine%0A        def go():%0A            yield from self.make_engine(use_loop=False)%0A%0A        asyncio.set_event_loop(self.loop)%0A        try:%0A            self.loop.run_until_complete(go())%0A        finally:%0A            asyncio.set_event_loop(None)%0A%0A    def test_not_context_manager(self):%0A        @asyncio.coroutine%0A        def go():%0A            with self.assertRaises(RuntimeError):%0A                with self.engine:%0A                    pass%0A        self.loop.run_until_complete(go())%0A%0A    def test_release_transacted(self):%0A        @asyncio.coroutine%0A        def go():%0A            conn = yield from self.engine.acquire()%0A            tr = yield from conn.begin()%0A            with self.assertRaises(sa.InvalidRequestError):%0A                self.engine.release(conn)%0A            del tr%0A        self.loop.run_until_complete(go())%0A

Add missing tests for engine