1
0
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:
Mariusz Felisiak 2022-01-26 17:47:03 +01:00 committed by GitHub
parent f97401d1b1
commit f38c3cbadc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 2 deletions

View File

@ -9,6 +9,7 @@ from django.contrib.gis.gdal import (
from django.contrib.gis.gdal.field import ( from django.contrib.gis.gdal.field import (
OFTDateTime, OFTInteger, OFTReal, OFTString, OFTDateTime, OFTInteger, OFTReal, OFTString,
) )
from django.contrib.gis.geos import GEOSGeometry
from django.test import SimpleTestCase from django.test import SimpleTestCase
from ..test_data import TEST_DATA, TestDS, get_ds_file 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__ # Incrementing through each layer, this tests DataSource.__iter__
for layer in ds: 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 # Making sure we get the number of features we expect
self.assertEqual(len(layer), source.nfeat) self.assertEqual(len(layer), source.nfeat)
@ -254,9 +257,15 @@ class DataSourceTest(SimpleTestCase):
# Incrementing through each layer and feature. # Incrementing through each layer and feature.
for layer in ds: 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 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 # Making sure we get the right Geometry name & type
self.assertEqual(source.geom, g.geom_name) self.assertEqual(source.geom, g.geom_name)
self.assertEqual(source.gtype, g.geom_type) self.assertEqual(source.gtype, g.geom_type)
@ -314,3 +323,10 @@ class DataSourceTest(SimpleTestCase):
feat = ds[0][0] feat = ds[0][0]
# Reference value obtained using `ogrinfo`. # Reference value obtained using `ogrinfo`.
self.assertEqual(676586997978, feat.get('ALAND10')) 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')

View File

@ -45,6 +45,7 @@ class TestDS(TestObj):
""" """
def __init__(self, name, *, ext='shp', **kwargs): def __init__(self, name, *, ext='shp', **kwargs):
# Shapefile is default extension, unless specified otherwise. # Shapefile is default extension, unless specified otherwise.
self.name = name
self.ds = get_ds_file(name, ext) self.ds = get_ds_file(name, ext)
super().__init__(**kwargs) super().__init__(**kwargs)