def test07b_closepolygons(self): "Testing closing Polygon objects." # Both rings in this geometry are not closed. poly = OGRGeometry("POLYGON((0 0, 5 0, 5 5, 0 5), (1 1, 2 1, 2 2, 2 1))") self.assertEqual(8, poly.point_count) print("\nBEGIN - expecting IllegalArgumentException; safe to ignore.\n") try: c = poly.centroid except OGRException: # Should raise an OGR exception, rings are not closed pass else: self.fail("Should have raised an OGRException!") print("\nEND - expecting IllegalArgumentException; safe to ignore.\n") poly.close_rings() self.assertEqual(10, poly.point_count) # Two closing points should've been added self.assertEqual(OGRGeometry("POINT(2.5 2.5)"), poly.centroid)