mirror of
https://github.com/django/django.git
synced 2025-08-04 19:08:28 +00:00
Fixed #28558 -- Simplified code to remove OGRIndexError.
The test is a regression for refs #4740 to show that the original fix of
OGRIndexError is no longer needed.
This is similar to the removal of GEOSIndexError in
197b187810
.
This commit is contained in:
parent
feb1a0a692
commit
9397d3add4
8 changed files with 34 additions and 65 deletions
|
@ -4,7 +4,6 @@ import unittest
|
|||
|
||||
from django.contrib.gis.gdal import (
|
||||
GDAL_VERSION, DataSource, Envelope, GDALException, OGRGeometry,
|
||||
OGRIndexError,
|
||||
)
|
||||
from django.contrib.gis.gdal.field import OFTInteger, OFTReal, OFTString
|
||||
|
||||
|
@ -84,7 +83,7 @@ class DataSourceTest(unittest.TestCase):
|
|||
self.assertEqual(source.driver, str(ds.driver))
|
||||
|
||||
# Making sure indexing works
|
||||
with self.assertRaises(OGRIndexError):
|
||||
with self.assertRaises(IndexError):
|
||||
ds[len(ds)]
|
||||
|
||||
def test02_invalid_shp(self):
|
||||
|
@ -120,9 +119,9 @@ class DataSourceTest(unittest.TestCase):
|
|||
self.assertIn(f, source.fields)
|
||||
|
||||
# Negative FIDs are not allowed.
|
||||
with self.assertRaises(OGRIndexError):
|
||||
with self.assertRaises(IndexError):
|
||||
layer.__getitem__(-1)
|
||||
with self.assertRaises(OGRIndexError):
|
||||
with self.assertRaises(IndexError):
|
||||
layer.__getitem__(50000)
|
||||
|
||||
if hasattr(source, 'field_values'):
|
||||
|
|
|
@ -4,9 +4,10 @@ import unittest
|
|||
from binascii import b2a_hex
|
||||
|
||||
from django.contrib.gis.gdal import (
|
||||
CoordTransform, GDALException, OGRGeometry, OGRGeomType, OGRIndexError,
|
||||
SpatialReference,
|
||||
CoordTransform, GDALException, OGRGeometry, OGRGeomType, SpatialReference,
|
||||
)
|
||||
from django.template import Context
|
||||
from django.template.engine import Engine
|
||||
|
||||
from ..test_data import TestDataMixin
|
||||
|
||||
|
@ -157,7 +158,7 @@ class OGRGeomTest(unittest.TestCase, TestDataMixin):
|
|||
self.assertEqual(ls.coords, linestr.tuple)
|
||||
self.assertEqual(linestr, OGRGeometry(ls.wkt))
|
||||
self.assertNotEqual(linestr, prev)
|
||||
with self.assertRaises(OGRIndexError):
|
||||
with self.assertRaises(IndexError):
|
||||
linestr.__getitem__(len(linestr))
|
||||
prev = linestr
|
||||
|
||||
|
@ -182,7 +183,7 @@ class OGRGeomTest(unittest.TestCase, TestDataMixin):
|
|||
for ls in mlinestr:
|
||||
self.assertEqual(2, ls.geom_type)
|
||||
self.assertEqual('LINESTRING', ls.geom_name)
|
||||
with self.assertRaises(OGRIndexError):
|
||||
with self.assertRaises(IndexError):
|
||||
mlinestr.__getitem__(len(mlinestr))
|
||||
|
||||
def test_linearring(self):
|
||||
|
@ -232,6 +233,14 @@ class OGRGeomTest(unittest.TestCase, TestDataMixin):
|
|||
for r in poly:
|
||||
self.assertEqual('LINEARRING', r.geom_name)
|
||||
|
||||
def test_polygons_templates(self):
|
||||
# Accessing Polygon attributes in templates should work.
|
||||
engine = Engine()
|
||||
template = engine.from_string('{{ polygons.0.wkt }}')
|
||||
polygons = [OGRGeometry(p.wkt) for p in self.geometries.multipolygons[:2]]
|
||||
content = template.render(Context({'polygons': polygons}))
|
||||
self.assertIn('MULTIPOLYGON (((100', content)
|
||||
|
||||
def test_closepolygons(self):
|
||||
"Testing closing Polygon objects."
|
||||
# Both rings in this geometry are not closed.
|
||||
|
@ -254,7 +263,7 @@ class OGRGeomTest(unittest.TestCase, TestDataMixin):
|
|||
if mp.valid:
|
||||
self.assertEqual(mp.n_p, mpoly.point_count)
|
||||
self.assertEqual(mp.num_geom, len(mpoly))
|
||||
with self.assertRaises(OGRIndexError):
|
||||
with self.assertRaises(IndexError):
|
||||
mpoly.__getitem__(len(mpoly))
|
||||
for p in mpoly:
|
||||
self.assertEqual('POLYGON', p.geom_name)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue