本文整理汇总了Python中shake_event.ShakeEvent.localCitiesMemoryLayer方法的典型用法代码示例。如果您正苦于以下问题:Python ShakeEvent.localCitiesMemoryLayer方法的具体用法?Python ShakeEvent.localCitiesMemoryLayer怎么用?Python ShakeEvent.localCitiesMemoryLayer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类shake_event.ShakeEvent
的用法示例。
在下文中一共展示了ShakeEvent.localCitiesMemoryLayer方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testLocalCities
# 需要导入模块: from shake_event import ShakeEvent [as 别名]
# 或者: from shake_event.ShakeEvent import localCitiesMemoryLayer [as 别名]
def testLocalCities(self):
"""Test that we can retrieve the cities local to the event"""
myShakeId = '20120726022003'
myShakeEvent = ShakeEvent(myShakeId)
# Get teh mem layer
myCitiesLayer = myShakeEvent.localCitiesMemoryLayer()
myProvider = myCitiesLayer.dataProvider()
myFeature = QgsFeature()
myAttributes = myProvider.attributeIndexes()
myProvider.select(myAttributes)
myExpectedFeatureCount = 6
self.assertEquals(myProvider.featureCount(), myExpectedFeatureCount)
myStrings = []
while myProvider.nextFeature(myFeature):
# fetch map of attributes
myAttributes = myFeature.attributeMap()
for (myKey, myValue) in myAttributes.iteritems():
myStrings.append("%d: %s\n" % (myKey, myValue.toString()))
myStrings.append('------------------\n')
LOGGER.debug('Mem table:\n %s' % myStrings)
myFilePath = unique_filename(prefix='testLocalCities',
suffix='.txt',
dir=temp_dir('test'))
myFile = file(myFilePath, 'wt')
myFile.writelines(myStrings)
myFile.close()
myFixturePath = os.path.join(dataDir(), 'tests', 'testLocalCities.txt')
myFile = file(myFixturePath, 'rt')
myExpectedString = myFile.readlines()
myFile.close()
myDiff = difflib.unified_diff(myStrings, myExpectedString)
myDiffList = list(myDiff)
myDiffString = ''
for _, myLine in enumerate(myDiffList):
myDiffString += myLine
myMessage = ('Diff is not zero length:\n'
'Control file: %s\n'
'Test file: %s\n'
'Diff:\n%s'
% (myFixturePath,
myFilePath,
myDiffString))
self.assertEqual(myDiffString, '', myMessage)