Skip to content

Commit

Permalink
Cleanup tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson authored and github-actions[bot] committed Feb 21, 2025
1 parent feb8023 commit 1959776
Showing 1 changed file with 9 additions and 24 deletions.
33 changes: 9 additions & 24 deletions tests/src/python/test_qgsfeature.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@ def test_CreateFeature(self):
feat.initAttributes(1)
feat.setAttribute(0, "text")
feat.setGeometry(QgsGeometry.fromPointXY(QgsPointXY(123, 456)))
myId = feat.id()
myExpectedId = 0
myMessage = f"\nExpected: {myExpectedId}\nGot: {myId}"
assert myId == myExpectedId, myMessage
self.assertEqual(feat.id(), 0)
self.assertEqual(feat.attributes(), ["text"])
self.assertEqual(feat.geometry().asWkt(), "Point (123 456)")

def test_FeatureDefaultConstructor(self):
"""Test for FID_IS_NULL default constructors See: https://github.com/qgis/QGIS/issues/36962"""
Expand Down Expand Up @@ -138,9 +137,7 @@ def test_ValidFeature(self):
feat = QgsFeature()
fit.nextFeature(feat)
fit.close()
myValidValue = feat.isValid()
myMessage = f"\nExpected: True\nGot: {myValidValue}"
assert myValidValue, myMessage
self.assertTrue(feat.isValid())

def test_Validity(self):
f = QgsFeature()
Expand Down Expand Up @@ -170,21 +167,14 @@ def test_Attributes(self):
feat = QgsFeature()
fit.nextFeature(feat)
fit.close()
myAttributes = feat.attributes()
myExpectedAttributes = ["Highway", 1]

# Only for printing purposes
myExpectedAttributes = ["Highway", 1]
myMessage = f"\nExpected: {myExpectedAttributes}\nGot: {myAttributes}"

assert myAttributes == myExpectedAttributes, myMessage
self.assertEqual(feat.attributes(), ["Highway", 1])

def test_SetAttributes(self):
feat = QgsFeature()
feat.initAttributes(1)
feat.setAttributes([0])
feat.setAttributes([NULL])
assert [NULL] == feat.attributes()
self.assertEqual(feat.attributes(), [NULL])

# Test different type of attributes
attributes = [
Expand All @@ -203,6 +193,7 @@ def test_SetAttributes(self):
feat.initAttributes(len(attributes))
feat.setAttributes(attributes)
self.assertEqual(feat.attributes(), attributes)
self.assertEqual([attr for attr in feat.attributes()], attributes)

def test_setAttribute(self):
feat = QgsFeature()
Expand Down Expand Up @@ -291,10 +282,7 @@ def test_DeleteAttribute(self):
feat[1] = "text2"
feat[2] = "text3"
feat.deleteAttribute(1)
myAttrs = [feat[0], feat[1]]
myExpectedAttrs = ["text1", "text3"]
myMessage = f"\nExpected: {str(myExpectedAttrs)}\nGot: {str(myAttrs)}"
assert myAttrs == myExpectedAttrs, myMessage
self.assertEqual([feat[0], feat[1]], ["text1", "text3"])

def test_DeleteAttributeByName(self):
fields = QgsFields()
Expand All @@ -315,10 +303,7 @@ def test_DeleteAttributeByName(self):
def test_SetGeometry(self):
feat = QgsFeature()
feat.setGeometry(QgsGeometry.fromPointXY(QgsPointXY(123, 456)))
myGeometry = feat.geometry()
myExpectedGeometry = "!None"
myMessage = f"\nExpected: {myExpectedGeometry}\nGot: {myGeometry}"
assert myGeometry is not None, myMessage
self.assertEqual(feat.geometry().asWkt(), "Point (123 456)")

# set from QgsAbstractGeometry
feat.setGeometry(QgsPoint(12, 34))
Expand Down

0 comments on commit 1959776

Please sign in to comment.