1
0
mirror of https://github.com/django/django.git synced 2025-08-21 17:29:13 +00:00

Improved consistency of GEOS error messages.

This commit is contained in:
David Smith 2024-11-08 08:00:05 +00:00 committed by nessita
parent 414253866b
commit 14fc2e9703
5 changed files with 11 additions and 9 deletions

View File

@ -70,12 +70,12 @@ class GEOSCoordSeq(GEOSBase):
def _checkindex(self, index): def _checkindex(self, index):
"Check the given index." "Check the given index."
if not (0 <= index < self.size): if not (0 <= index < self.size):
raise IndexError("invalid GEOS Geometry index: %s" % index) raise IndexError(f"Invalid GEOS Geometry index: {index}")
def _checkdim(self, dim): def _checkdim(self, dim):
"Check the given dimension." "Check the given dimension."
if dim < 0 or dim > 2: if dim < 0 or dim > 2:
raise GEOSException('invalid ordinate dimension "%d"' % dim) raise GEOSException(f'Invalid ordinate dimension: "{dim:d}"')
def _get_x(self, index): def _get_x(self, index):
return capi.cs_getx(self.ptr, index, byref(c_double())) return capi.cs_getx(self.ptr, index, byref(c_double()))

View File

@ -353,7 +353,7 @@ class GEOSGeometryBase(GEOSBase):
two Geometries match the elements in pattern. two Geometries match the elements in pattern.
""" """
if not isinstance(pattern, str) or len(pattern) > 9: if not isinstance(pattern, str) or len(pattern) > 9:
raise GEOSException("invalid intersection matrix pattern") raise GEOSException("Invalid intersection matrix pattern.")
return capi.geos_relatepattern(self.ptr, other.ptr, force_bytes(pattern)) return capi.geos_relatepattern(self.ptr, other.ptr, force_bytes(pattern))
def touches(self, other): def touches(self, other):
@ -506,7 +506,9 @@ class GEOSGeometryBase(GEOSBase):
# source SRS. # source SRS.
srid = None srid = None
elif srid is None or srid < 0: elif srid is None or srid < 0:
raise GEOSException("Calling transform() with no SRID set is not supported") raise GEOSException(
"Calling transform() with no SRID set is not supported."
)
# Creating an OGR Geometry, which is then transformed. # Creating an OGR Geometry, which is then transformed.
g = gdal.OGRGeometry(self._ogr_ptr(), srid) g = gdal.OGRGeometry(self._ogr_ptr(), srid)

View File

@ -103,7 +103,7 @@ class Polygon(GEOSGeometry):
param, param,
msg=( msg=(
"Parameter must be a sequence of LinearRings or objects that can " "Parameter must be a sequence of LinearRings or objects that can "
"initialize to LinearRings" "initialize to LinearRings."
), ),
): ):
"Try to construct a ring from the given parameter." "Try to construct a ring from the given parameter."

View File

@ -9,7 +9,7 @@ class GEOSCoordSeqTest(SimpleTestCase):
with self.subTest(i): with self.subTest(i):
self.assertEqual(coord_seq[i], (i, i)) self.assertEqual(coord_seq[i], (i, i))
for i in (-3, 10): for i in (-3, 10):
msg = "invalid GEOS Geometry index: %s" % i msg = f"Invalid GEOS Geometry index: {i}"
with self.subTest(i): with self.subTest(i):
with self.assertRaisesMessage(IndexError, msg): with self.assertRaisesMessage(IndexError, msg):
coord_seq[i] coord_seq[i]

View File

@ -679,7 +679,7 @@ class GEOSTest(SimpleTestCase, TestDataMixin):
# Testing polygon construction. # Testing polygon construction.
msg = ( msg = (
"Parameter must be a sequence of LinearRings or " "Parameter must be a sequence of LinearRings or "
"objects that can initialize to LinearRings" "objects that can initialize to LinearRings."
) )
with self.assertRaisesMessage(TypeError, msg): with self.assertRaisesMessage(TypeError, msg):
Polygon(0, [1, 2, 3]) Polygon(0, [1, 2, 3])
@ -804,7 +804,7 @@ class GEOSTest(SimpleTestCase, TestDataMixin):
def test_relate_pattern(self): def test_relate_pattern(self):
"Testing relate() and relate_pattern()." "Testing relate() and relate_pattern()."
g = fromstr("POINT (0 0)") g = fromstr("POINT (0 0)")
msg = "invalid intersection matrix pattern" msg = "Invalid intersection matrix pattern."
with self.assertRaisesMessage(GEOSException, msg): with self.assertRaisesMessage(GEOSException, msg):
g.relate_pattern(0, "invalid pattern, yo") g.relate_pattern(0, "invalid pattern, yo")
for rg in self.geometries.relate_geoms: for rg in self.geometries.relate_geoms:
@ -1289,7 +1289,7 @@ class GEOSTest(SimpleTestCase, TestDataMixin):
if isinstance(g, Point): if isinstance(g, Point):
# IndexError is not raised in GEOS 3.8.0. # IndexError is not raised in GEOS 3.8.0.
if geos_version_tuple() != (3, 8, 0): if geos_version_tuple() != (3, 8, 0):
msg = "invalid GEOS Geometry index:" msg = "Invalid GEOS Geometry index:"
with self.assertRaisesMessage(IndexError, msg): with self.assertRaisesMessage(IndexError, msg):
g.x g.x
elif isinstance(g, Polygon): elif isinstance(g, Polygon):