Example #1
0
 def test_DeleteAttribute(self):
     feat = QgsFeature()
     feat.addAttribute(1, "text")
     feat.deleteAttribute(1)
     myCount = len(feat.attributeMap())
     myExpectedCount = 0
     myMessage = '\nExpected: %s\nGot: %s' % (myExpectedCount, myCount)
     assert myCount == myExpectedCount, myMessage        
Example #2
0
 def test_DeleteAttribute(self):
     feat = QgsFeature()
     feat.initAttributes(3)
     feat[0] = "text1"
     feat[1] = "text2"
     feat[2] = "text3"
     feat.deleteAttribute(1)
     myAttrs = [feat[0], feat[1]]
     myExpectedAttrs = ["text1", "text3"]
     myMessage = "\nExpected: %s\nGot: %s" % (str(myExpectedAttrs), str(myAttrs))
     assert myAttrs == myExpectedAttrs, myMessage
Example #3
0
 def test_DeleteAttribute(self):
     feat = QgsFeature()
     feat.initAttributes(3)
     feat[0] = QVariant("text1")
     feat[1] = QVariant("text2")
     feat[2] = QVariant("text3")
     feat.deleteAttribute(1)
     myAttrs = [ str(feat[0].toString()), str(feat[1].toString()) ]
     myExpectedAttrs = [ "text1", "text3" ]
     myMessage = '\nExpected: %s\nGot: %s' % (str(myExpectedAttrs), str(myAttrs))
     assert myAttrs == myExpectedAttrs, myMessage
Example #4
0
    def test_DeleteAttributeByName(self):
        fields = QgsFields()
        field1 = QgsField("my_field")
        fields.append(field1)
        field2 = QgsField("my_field2")
        fields.append(field2)

        feat = QgsFeature(fields)
        feat.initAttributes(2)
        feat[0] = "text1"
        feat[1] = "text2"
        with self.assertRaises(KeyError):
            feat.deleteAttribute("not present")
        self.assertTrue(feat.deleteAttribute("my_field"))
        self.assertEqual(feat.attributes(), ["text2"])
Example #5
0
    def test_DeleteAttributeByName(self):
        fields = QgsFields()
        field1 = QgsField('my_field')
        fields.append(field1)
        field2 = QgsField('my_field2')
        fields.append(field2)

        feat = QgsFeature(fields)
        feat.initAttributes(2)
        feat[0] = "text1"
        feat[1] = "text2"
        with self.assertRaises(KeyError):
            feat.deleteAttribute('not present')
        self.assertTrue(feat.deleteAttribute('my_field'))
        self.assertEqual(feat.attributes(), ['text2'])