|
58 | 58 |
|
59 | 59 | class TestQgsGeometry(unittest.TestCase): |
60 | 60 |
|
| 61 | + def testBool(self): |
| 62 | + """ Test boolean evaluation of QgsGeometry """ |
| 63 | + g = QgsGeometry() |
| 64 | + self.assertFalse(g) |
| 65 | + myWKT = 'Point (10 10)' |
| 66 | + g = QgsGeometry.fromWkt(myWKT) |
| 67 | + self.assertTrue(g) |
| 68 | + g.setGeometry(None) |
| 69 | + self.assertFalse(g) |
| 70 | + |
61 | 71 | def testWktPointLoading(self): |
62 | 72 | myWKT = 'Point (10 10)' |
63 | 73 | myGeometry = QgsGeometry.fromWkt(myWKT) |
@@ -1516,7 +1526,7 @@ def testConvertToType(self): |
1516 | 1526 | ######## TO LINE ######## |
1517 | 1527 | # POINT TO LINE |
1518 | 1528 | point = QgsGeometry.fromPoint(QgsPoint(1, 1)) |
1519 | | - assert point.convertToType(Qgis.Line, False) is None, "convertToType with a point should return a null geometry" |
| 1529 | + self.assertFalse(point.convertToType(Qgis.Line, False)), "convertToType with a point should return a null geometry" |
1520 | 1530 | # MultiPoint TO LINE |
1521 | 1531 | multipoint = QgsGeometry.fromMultiPoint(points[0][0]) |
1522 | 1532 | wkt = multipoint.convertToType(Qgis.Line, False).exportToWkt() |
@@ -1581,10 +1591,10 @@ def testConvertToType(self): |
1581 | 1591 | assert compareWkt(expWkt, wkt), "convertToType failed: from line to polygon. Expected:\n%s\nGot:\n%s\n" % (expWkt, wkt) |
1582 | 1592 | # LINE ( 3 vertices, with first = last ) TO Polygon |
1583 | 1593 | line = QgsGeometry.fromPolyline([QgsPoint(1, 1), QgsPoint(0, 0), QgsPoint(1, 1)]) |
1584 | | - assert line.convertToType(Qgis.Polygon, False) is None, "convertToType to polygon of a 3 vertices lines with first and last vertex identical should return a null geometry" |
| 1594 | + self.assertFalse(line.convertToType(Qgis.Polygon, False), "convertToType to polygon of a 3 vertices lines with first and last vertex identical should return a null geometry") |
1585 | 1595 | # MULTILINE ( with a part of 3 vertices, with first = last ) TO MultiPolygon |
1586 | 1596 | multiline = QgsGeometry.fromMultiPolyline([points[0][0], [QgsPoint(1, 1), QgsPoint(0, 0), QgsPoint(1, 1)]]) |
1587 | | - assert multiline.convertToType(Qgis.Polygon, True) is None, "convertToType to polygon of a 3 vertices lines with first and last vertex identical should return a null geometry" |
| 1597 | + self.assertFalse(multiline.convertToType(Qgis.Polygon, True), "convertToType to polygon of a 3 vertices lines with first and last vertex identical should return a null geometry") |
1588 | 1598 | # LINE TO MultiPolygon |
1589 | 1599 | line = QgsGeometry.fromPolyline(points[0][0]) |
1590 | 1600 | wkt = line.convertToType(Qgis.Polygon, True).exportToWkt() |
|
0 commit comments