mirror of
https://github.com/django/django.git
synced 2024-12-22 17:16:24 +00:00
Increased test coverage for django.contrib.gis.gdal.layer.Layer.
This commit is contained in:
parent
f97401d1b1
commit
f38c3cbadc
@ -9,6 +9,7 @@ from django.contrib.gis.gdal import (
|
||||
from django.contrib.gis.gdal.field import (
|
||||
OFTDateTime, OFTInteger, OFTReal, OFTString,
|
||||
)
|
||||
from django.contrib.gis.geos import GEOSGeometry
|
||||
from django.test import SimpleTestCase
|
||||
|
||||
from ..test_data import TEST_DATA, TestDS, get_ds_file
|
||||
@ -139,6 +140,8 @@ class DataSourceTest(SimpleTestCase):
|
||||
|
||||
# Incrementing through each layer, this tests DataSource.__iter__
|
||||
for layer in ds:
|
||||
self.assertEqual(layer.name, source.name)
|
||||
self.assertEqual(str(layer), source.name)
|
||||
# Making sure we get the number of features we expect
|
||||
self.assertEqual(len(layer), source.nfeat)
|
||||
|
||||
@ -254,9 +257,15 @@ class DataSourceTest(SimpleTestCase):
|
||||
|
||||
# Incrementing through each layer and feature.
|
||||
for layer in ds:
|
||||
for feat in layer:
|
||||
geoms = layer.get_geoms()
|
||||
geos_geoms = layer.get_geoms(geos=True)
|
||||
self.assertEqual(len(geoms), len(geos_geoms))
|
||||
self.assertEqual(len(geoms), len(layer))
|
||||
for feat, geom, geos_geom in zip(layer, geoms, geos_geoms):
|
||||
g = feat.geom
|
||||
|
||||
self.assertEqual(geom, g)
|
||||
self.assertIsInstance(geos_geom, GEOSGeometry)
|
||||
self.assertEqual(g, geos_geom.ogr)
|
||||
# Making sure we get the right Geometry name & type
|
||||
self.assertEqual(source.geom, g.geom_name)
|
||||
self.assertEqual(source.gtype, g.geom_type)
|
||||
@ -314,3 +323,10 @@ class DataSourceTest(SimpleTestCase):
|
||||
feat = ds[0][0]
|
||||
# Reference value obtained using `ogrinfo`.
|
||||
self.assertEqual(676586997978, feat.get('ALAND10'))
|
||||
|
||||
def test_nonexistent_field(self):
|
||||
source = ds_list[0]
|
||||
ds = DataSource(source.ds)
|
||||
msg = 'invalid field name: nonexistent'
|
||||
with self.assertRaisesMessage(GDALException, msg):
|
||||
ds[0].get_fields('nonexistent')
|
||||
|
@ -45,6 +45,7 @@ class TestDS(TestObj):
|
||||
"""
|
||||
def __init__(self, name, *, ext='shp', **kwargs):
|
||||
# Shapefile is default extension, unless specified otherwise.
|
||||
self.name = name
|
||||
self.ds = get_ds_file(name, ext)
|
||||
super().__init__(**kwargs)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user