本文整理汇总了Python中safe.utilities.keyword_io.KeywordIO.definition方法的典型用法代码示例。如果您正苦于以下问题:Python KeywordIO.definition方法的具体用法?Python KeywordIO.definition怎么用?Python KeywordIO.definition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类safe.utilities.keyword_io.KeywordIO
的用法示例。
在下文中一共展示了KeywordIO.definition方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: KeywordIOTest
# 需要导入模块: from safe.utilities.keyword_io import KeywordIO [as 别名]
# 或者: from safe.utilities.keyword_io.KeywordIO import definition [as 别名]
#.........这里部分代码省略.........
'test': 'TEST',
'layer_geometry': 'raster',
'layer_purpose': 'hazard',
'layer_mode': 'continuous',
'keyword_version': inasafe_keyword_version
}
message = 'Got:\n%s\nExpected:\n%s' % (keywords, expected_keywords)
self.assertDictEqual(keywords, expected_keywords, message)
def test_read_db_keywords(self):
"""Can we read sqlite kw with the generic read_keywords method
"""
db_path = test_data_path('other', 'test_keywords.db')
self.read_db_keywords(db_path)
def read_db_keywords(self, db_path):
"""Can we read sqlite keywords with the generic readKeywords method
"""
self.keyword_io.set_keyword_db_path(db_path)
# We need to use relative path so that the hash from URI will match
local_path = os.path.join(
os.path.dirname(__file__), 'exposure.sqlite')
sqlite_building_path = test_data_path('exposure', 'exposure.sqlite')
shutil.copy2(sqlite_building_path, local_path)
uri = QgsDataSourceURI()
uri.setDatabase('exposure.sqlite')
uri.setDataSource('', 'buildings_osm_4326', 'Geometry')
sqlite_layer = QgsVectorLayer(uri.uri(), 'OSM Buildings', 'spatialite')
expected_source = (
'dbname=\'exposure.sqlite\' table="buildings_osm_4326" ('
'Geometry) sql=')
message = 'Got source: %s\n\nExpected %s\n' % (
sqlite_layer.source(), expected_source)
self.assertEqual(sqlite_layer.source(), expected_source, message)
keywords = self.keyword_io.read_keywords(sqlite_layer)
expected_keywords = self.expected_sqlite_keywords
message = 'Got: %s\n\nExpected %s\n\nSource: %s' % (
keywords, expected_keywords, self.sqlite_layer.source())
self.assertDictEqual(keywords, expected_keywords, message)
# Delete SQL Layer so that we can delete the file
del sqlite_layer
os.remove(local_path)
def test_copy_keywords(self):
"""Test we can copy the keywords."""
out_path = unique_filename(
prefix='test_copy_keywords', suffix='.keywords')
self.keyword_io.copy_keywords(self.raster_layer, out_path)
copied_keywords = read_file_keywords(out_path)
expected_keywords = self.expected_raster_keywords
message = 'Got:\n%s\nExpected:\n%s\nSource:\n%s' % (
copied_keywords, expected_keywords, out_path)
self.assertDictEqual(copied_keywords, expected_keywords, message)
def test_definition(self):
"""Test we can get definitions for keywords.
.. versionadded:: 3.2
"""
keyword = 'hazards'
definition = self.keyword_io.definition(keyword)
self.assertTrue('description' in definition)
def test_to_message(self):
"""Test we can convert keywords to a message object.
.. versionadded:: 3.2
"""
keywords = self.keyword_io.read_keywords(self.vector_layer)
message = self.keyword_io.to_message(keywords).to_text()
self.assertIn('*Exposure*, structure------', message)
def test_dict_to_row(self):
"""Test the dict to row helper works.
.. versionadded:: 3.2
"""
keyword_value = (
"{'high': ['Kawasan Rawan Bencana III'], "
"'medium': ['Kawasan Rawan Bencana II'], "
"'low': ['Kawasan Rawan Bencana I']}")
table = self.keyword_io._dict_to_row(keyword_value)
self.assertIn(
u'\n---\n*high*, Kawasan Rawan Bencana III------',
table.to_text())
# should also work passing a dict
keyword_value = {
'high': ['Kawasan Rawan Bencana III'],
'medium': ['Kawasan Rawan Bencana II'],
'low': ['Kawasan Rawan Bencana I']}
table = self.keyword_io._dict_to_row(keyword_value)
self.assertIn(
u'\n---\n*high*, Kawasan Rawan Bencana III------',
table.to_text())