当前位置: 首页>>代码示例>>Python>>正文


Python PGDatabase.uri方法代码示例

本文整理汇总了Python中db_manager.db_plugins.postgis.plugin.PGDatabase.uri方法的典型用法代码示例。如果您正苦于以下问题:Python PGDatabase.uri方法的具体用法?Python PGDatabase.uri怎么用?Python PGDatabase.uri使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在db_manager.db_plugins.postgis.plugin.PGDatabase的用法示例。


在下文中一共展示了PGDatabase.uri方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_rasterTableGdalURI

# 需要导入模块: from db_manager.db_plugins.postgis.plugin import PGDatabase [as 别名]
# 或者: from db_manager.db_plugins.postgis.plugin.PGDatabase import uri [as 别名]
    def test_rasterTableGdalURI(self):

        def check_rasterTableGdalURI(expected_dbname):
            tables = database.tables()
            raster_tables_count = 0
            for tab in tables:
                if tab.type == Table.RasterType:
                    raster_tables_count += 1
                    gdalUri = tab.gdalUri()
                    m = re.search(' dbname=\'([^ ]*)\' ', gdalUri)
                    self.assertTrue(m)
                    actual_dbname = m.group(1)
                    self.assertEqual(actual_dbname, expected_dbname)
                #print(tab.type)
                #print(tab.quotedName())
                #print(tab)

            # We need to make sure a database is created with at
            # least one raster table !
            self.assertEqual(raster_tables_count, 1)

        obj = QObject() # needs to be kept alive

        # Test for empty URI
        # See https://issues.qgis.org/issues/16625
        # and https://issues.qgis.org/issues/10600

        expected_dbname = self.testdb
        os.environ['PGDATABASE'] = expected_dbname

        database = PGDatabase(obj, QgsDataSourceUri())
        self.assertIsInstance(database, PGDatabase)

        uri = database.uri()
        self.assertEqual(uri.host(), '')
        self.assertEqual(uri.username(), '')
        self.assertEqual(uri.database(), expected_dbname)
        self.assertEqual(uri.service(), '')

        check_rasterTableGdalURI(expected_dbname)

        # Test for service-only URI
        # See https://issues.qgis.org/issues/16626

        os.environ['PGDATABASE'] = 'fake'
        database = PGDatabase(obj, QgsDataSourceUri('service=dbmanager'))
        self.assertIsInstance(database, PGDatabase)

        uri = database.uri()
        self.assertEqual(uri.host(), '')
        self.assertEqual(uri.username(), '')
        self.assertEqual(uri.database(), '')
        self.assertEqual(uri.service(), 'dbmanager')

        check_rasterTableGdalURI(expected_dbname)
开发者ID:rldhont,项目名称:Quantum-GIS,代码行数:57,代码来源:plugin_test.py


注:本文中的db_manager.db_plugins.postgis.plugin.PGDatabase.uri方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。