コード例 #1
0
    def test_create_drop_bound(self):

        for meta in (MetaData, ThreadLocalMetaData):
            for bind in (testing.db, testing.db.connect()):
                metadata = meta()
                table = Table("test_table", metadata, Column("foo", Integer))
                metadata.bind = bind
                assert metadata.bind is table.bind is bind
                metadata.create_all()
                assert table.exists()
                metadata.drop_all()
                table.create()
                table.drop()
                assert not table.exists()

                metadata = meta()
                table = Table("test_table", metadata, Column("foo", Integer))

                metadata.bind = bind

                assert metadata.bind is table.bind is bind
                metadata.create_all()
                assert table.exists()
                metadata.drop_all()
                table.create()
                table.drop()
                assert not table.exists()
                if isinstance(bind, engine.Connection):
                    bind.close()
コード例 #2
0
 def test_create_drop_explicit(self):
     metadata = MetaData()
     table = Table("test_table", metadata, Column("foo", Integer))
     for bind in (testing.db, testing.db.connect()):
         for args in [([], {"bind": bind}), ([bind], {})]:
             metadata.create_all(*args[0], **args[1])
             assert table.exists(*args[0], **args[1])
             metadata.drop_all(*args[0], **args[1])
             table.create(*args[0], **args[1])
             table.drop(*args[0], **args[1])
             assert not table.exists(*args[0], **args[1])
コード例 #3
0
 def test_create_drop_constructor_bound(self):
     for bind in (testing.db, testing.db.connect()):
         try:
             for args in (([bind], {}), ([], {"bind": bind})):
                 metadata = MetaData(*args[0], **args[1])
                 table = Table(
                     "test_table", metadata, Column("foo", Integer)
                 )
                 assert metadata.bind is table.bind is bind
                 metadata.create_all()
                 assert table.exists()
                 metadata.drop_all()
                 table.create()
                 table.drop()
                 assert not table.exists()
         finally:
             if isinstance(bind, engine.Connection):
                 bind.close()