Best Python code snippet using fMBT_python
test_qgsexpressionbuilderwidget.py
Source:test_qgsexpressionbuilderwidget.py
...62 """ check through widget model to ensure it is initially populated with functions """63 w = QgsExpressionBuilderWidget()64 m = w.model()65 # check that some standard expression functions are shown66 items = m.findItems('lower', Qt.MatchRecursive)67 self.assertEqual(len(items), 1)68 items = m.findItems('upper', Qt.MatchRecursive)69 self.assertEqual(len(items), 1)70 items = m.findItems('asdasdasda#$@#$', Qt.MatchRecursive)71 self.assertEqual(len(items), 0)72 def testVariables(self):73 """ check through widget model to ensure it is populated with variables """74 w = QgsExpressionBuilderWidget()75 m = w.model()76 s = QgsExpressionContextScope()77 s.setVariable('my_var1', 'x')78 s.setVariable('my_var2', 'y')79 c = QgsExpressionContext()80 c.appendScope(s)81 # check that variables are added when setting context82 w.setExpressionContext(c)83 items = m.findItems('my_var1', Qt.MatchRecursive)84 self.assertEqual(len(items), 1)85 items = m.findItems('my_var2', Qt.MatchRecursive)86 self.assertEqual(len(items), 1)87 items = m.findItems('not_my_var', Qt.MatchRecursive)88 self.assertEqual(len(items), 0)89 # double check that functions are still only there once90 items = m.findItems('lower', Qt.MatchRecursive)91 self.assertEqual(len(items), 1)92 items = m.findItems('upper', Qt.MatchRecursive)93 self.assertEqual(len(items), 1)94 def testLayers(self):95 """ check that layers are shown in widget model"""96 p = QgsProject.instance()97 layer = QgsVectorLayer("Point", "layer1", "memory")98 layer2 = QgsVectorLayer("Point", "layer2", "memory")99 p.addMapLayers([layer, layer2])100 w = QgsExpressionBuilderWidget()101 m = w.model()102 # check that layers are shown103 items = m.findItems('layer1', Qt.MatchRecursive)104 self.assertEqual(len(items), 1)105 items = m.findItems('layer2', Qt.MatchRecursive)106 self.assertEqual(len(items), 1)107 # change project108 p2 = QgsProject()109 layer3 = QgsVectorLayer("Point", "layer3", "memory")110 p2.addMapLayers([layer3])111 w.setProject(p2)112 m = w.model()113 items = m.findItems('layer1', Qt.MatchRecursive)114 self.assertEqual(len(items), 0)115 items = m.findItems('layer2', Qt.MatchRecursive)116 self.assertEqual(len(items), 0)117 items = m.findItems('layer3', Qt.MatchRecursive)118 self.assertEqual(len(items), 1)119 def testRelations(self):120 """ check that layers are shown in widget model"""121 p = QgsProject.instance()122 # not valid, but doesn't matter for test....123 rel = QgsRelation()124 rel.setId('rel1')125 rel.setName('Relation Number One')126 rel.setReferencingLayer(self.referencingLayer.id())127 rel.setReferencedLayer(self.referencedLayer.id())128 rel.addFieldPair('foreignkey', 'y')129 rel2 = QgsRelation()130 rel2.setId('rel2')131 rel2.setName('Relation Number Two')132 rel2.setReferencingLayer(self.referencingLayer.id())133 rel2.setReferencedLayer(self.referencedLayer.id())134 rel2.addFieldPair('foreignkey', 'y')135 p.relationManager().addRelation(rel)136 p.relationManager().addRelation(rel2)137 w = QgsExpressionBuilderWidget()138 m = w.model()139 # check that relations are shown140 items = m.findItems('Relation Number One', Qt.MatchRecursive)141 self.assertEqual(len(items), 1)142 items = m.findItems('Relation Number Two', Qt.MatchRecursive)143 self.assertEqual(len(items), 1)144if __name__ == '__main__':...
metadata.py
Source:metadata.py
...11 meta = {}12 with open ( pathname ) as fd:13 doc = xmltodict.parse( fd.read() )14 # product characteristics15 meta[ 'product' ] = { 'type' : findItems( doc, 's1sarl1:productType' )[ 0 ], 16 'class' : findItems( doc, 's1sarl1:productClass' )[ 0 ], 17 'satellite' : findItems( doc, 'safe:number' )[ 0 ],18 'mode' : findItems( doc, 's1sarl1:mode' )[ 0 ] }19 # acquisition period20 nodes = findItems( doc, 'safe:acquisitionPeriod' )21 meta[ 'acquisition' ] = { 'start' : datetime.strptime( nodes[0][ 'safe:startTime' ], '%Y-%m-%dT%H:%M:%S.%f' ),22 'stop' : datetime.strptime( nodes[0][ 'safe:stopTime' ], '%Y-%m-%dT%H:%M:%S.%f' ) }23 # software identity24 nodes = findItems( doc, 'safe:software' )25 meta[ 'software' ] = { 'name' : nodes[ 0 ][ '@name' ], 'version' : nodes[ 0 ][ '@version' ] }26 # get orbit numbers27 nodes = findItems( doc, 'safe:orbitNumber' )28 meta[ 'orbit_number' ] = { 'start' : int ( nodes[ 0 ][ 0 ][ '#text' ] ), 'stop' : int ( nodes[ 0 ][ 1 ][ '#text' ] ) }29 # get relative orbit numbers30 nodes = findItems( doc, 'safe:relativeOrbitNumber' )31 meta[ 'relative_orbit_number' ] = { 'start' : int ( nodes[ 0 ][ 0 ][ '#text' ] ), 'stop' : int ( nodes[ 0 ][ 1 ][ '#text' ] ) }32 # get orbit direction33 meta[ 'orbit_direction' ] = findItems( doc, 's1:pass' )[ 0 ]34 # get scene coordinates35 nodes = findItems( doc, 'gml:coordinates' )36 tuples = nodes[ 0 ].split( ' ' )37 # convert to float array38 meta[ 'aoi' ] = []39 for t in tuples:40 meta[ 'aoi' ].append( [ float( i ) for i in t.split( ',' ) ] )41 # get cycle number42 nodes = findItems( doc, 'safe:cycleNumber' )43 meta[ 'cycle_number' ] = int ( nodes[ 0 ] )44 # get mission take id45 nodes = findItems( doc, 's1sarl1:missionDataTakeID' )46 meta[ 'mission_take_id' ] = int ( nodes[ 0 ] )47 # get polarization channels48 nodes = findItems( doc, 's1sarl1:transmitterReceiverPolarisation' )49 meta[ 'polarization' ] = nodes[ 0 ]50 # get slice number51 nodes = findItems( doc, 's1sarl1:sliceNumber' )52 meta[ 'slice_number' ] = int ( nodes[ 0 ] )53 # get total slices54 nodes = findItems( doc, 's1sarl1:totalSlices' )55 meta[ 'total_slices' ] = int ( nodes[ 0 ] )56 return meta57def getAnnotation( annotation ):58 """59 load metadata from scene annotation file60 """61 # get xml schema for new task62 meta = {}63 with open ( annotation ) as fd:64 doc = xmltodict.parse( fd.read() )65 # get resolution66 meta[ 'pixel_spacing' ] = { 'range' : float( findItems( doc, 'rangePixelSpacing' )[ 0 ] ),67 'azimuth' : float( findItems( doc, 'azimuthPixelSpacing' )[ 0 ] ) }68 # get scene dimensions69 meta[ 'image' ] = { 'samples' : int( findItems( doc, 'numberOfSamples' )[ 0 ] ),70 'lines' : int( findItems( doc, 'numberOfLines' )[ 0 ] ) }71 # get viewing geometry72 meta[ 'projection' ] = findItems( doc, 'projection' )[ 0 ]73 meta[ 'incidence_mid_swath' ] = float ( findItems( doc, 'incidenceAngleMidSwath' )[ 0 ] )74 # get heading75 meta[ 'heading' ] = float ( findItems( doc, 'platformHeading' )[ 0 ] )76 if meta[ 'heading' ] < 0.0: 77 meta[ 'heading' ] = meta[ 'heading' ] + 360.078 return meta79def getGeolocationGrid( annotation ):80 """81 load metadata from scene annotation file82 """83 # get xml schema for new task84 meta = {}85 with open ( annotation ) as fd:86 doc = xmltodict.parse( fd.read() )87 # get gcps88 meta[ 'gcps' ] = []89 for pt in doc[ 'product' ][ 'geolocationGrid' ][ 'geolocationGridPointList' ][ 'geolocationGridPoint' ]:...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!