1
0
mirror of https://github.com/django/django.git synced 2025-06-06 20:19:13 +00:00

Fixed #34374 -- Fixed GIS tests on Windows.

This commit is contained in:
Heath Henley 2023-03-02 13:14:24 -05:00 committed by GitHub
parent 4cb5573352
commit 56e5ea805b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 9 deletions

View File

@ -10,6 +10,7 @@ from django.contrib.gis.gdal import GDALRaster, SpatialReference
from django.contrib.gis.gdal.error import GDALException from django.contrib.gis.gdal.error import GDALException
from django.contrib.gis.gdal.raster.band import GDALBand from django.contrib.gis.gdal.raster.band import GDALBand
from django.contrib.gis.shortcuts import numpy from django.contrib.gis.shortcuts import numpy
from django.core.files.temp import NamedTemporaryFile
from django.test import SimpleTestCase from django.test import SimpleTestCase
from ..data.rasters.textrasters import JSON_RASTER from ..data.rasters.textrasters import JSON_RASTER
@ -148,7 +149,7 @@ class GDALRasterTests(SimpleTestCase):
def test_file_based_raster_creation(self): def test_file_based_raster_creation(self):
# Prepare tempfile # Prepare tempfile
rstfile = tempfile.NamedTemporaryFile(suffix=".tif") rstfile = NamedTemporaryFile(suffix=".tif")
# Create file-based raster from scratch # Create file-based raster from scratch
GDALRaster( GDALRaster(
@ -264,7 +265,7 @@ class GDALRasterTests(SimpleTestCase):
self.assertIsNone(self.rs.vsi_buffer) self.assertIsNone(self.rs.vsi_buffer)
def test_vsi_vsizip_filesystem(self): def test_vsi_vsizip_filesystem(self):
rst_zipfile = tempfile.NamedTemporaryFile(suffix=".zip") rst_zipfile = NamedTemporaryFile(suffix=".zip")
with zipfile.ZipFile(rst_zipfile, mode="w") as zf: with zipfile.ZipFile(rst_zipfile, mode="w") as zf:
zf.write(self.rs_path, "raster.tif") zf.write(self.rs_path, "raster.tif")
rst_path = "/vsizip/" + os.path.join(rst_zipfile.name, "raster.tif") rst_path = "/vsizip/" + os.path.join(rst_zipfile.name, "raster.tif")
@ -406,7 +407,7 @@ class GDALRasterTests(SimpleTestCase):
self.assertIn("NAD83 / Florida GDL Albers", infos) self.assertIn("NAD83 / Florida GDL Albers", infos)
def test_compressed_file_based_raster_creation(self): def test_compressed_file_based_raster_creation(self):
rstfile = tempfile.NamedTemporaryFile(suffix=".tif") rstfile = NamedTemporaryFile(suffix=".tif")
# Make a compressed copy of an existing raster. # Make a compressed copy of an existing raster.
compressed = self.rs.warp( compressed = self.rs.warp(
{"papsz_options": {"compress": "packbits"}, "name": rstfile.name} {"papsz_options": {"compress": "packbits"}, "name": rstfile.name}
@ -554,7 +555,7 @@ class GDALRasterTests(SimpleTestCase):
self.assertEqual(result, [23] * 16) self.assertEqual(result, [23] * 16)
def test_raster_clone(self): def test_raster_clone(self):
rstfile = tempfile.NamedTemporaryFile(suffix=".tif") rstfile = NamedTemporaryFile(suffix=".tif")
tests = [ tests = [
("MEM", "", 23), # In memory raster. ("MEM", "", 23), # In memory raster.
("tif", rstfile.name, 99), # In file based raster. ("tif", rstfile.name, 99), # In file based raster.
@ -600,7 +601,7 @@ class GDALRasterTests(SimpleTestCase):
for srs in tests: for srs in tests:
with self.subTest(srs=srs): with self.subTest(srs=srs):
# Prepare tempfile and nodata value. # Prepare tempfile and nodata value.
rstfile = tempfile.NamedTemporaryFile(suffix=".tif") rstfile = NamedTemporaryFile(suffix=".tif")
ndv = 99 ndv = 99
# Create in file based raster. # Create in file based raster.
source = GDALRaster( source = GDALRaster(
@ -701,7 +702,7 @@ class GDALRasterTests(SimpleTestCase):
def test_raster_transform_clone(self): def test_raster_transform_clone(self):
with mock.patch.object(GDALRaster, "clone") as mocked_clone: with mock.patch.object(GDALRaster, "clone") as mocked_clone:
# Create in file based raster. # Create in file based raster.
rstfile = tempfile.NamedTemporaryFile(suffix=".tif") rstfile = NamedTemporaryFile(suffix=".tif")
source = GDALRaster( source = GDALRaster(
{ {
"datatype": 1, "datatype": 1,
@ -729,7 +730,7 @@ class GDALRasterTests(SimpleTestCase):
def test_raster_transform_clone_name(self): def test_raster_transform_clone_name(self):
# Create in file based raster. # Create in file based raster.
rstfile = tempfile.NamedTemporaryFile(suffix=".tif") rstfile = NamedTemporaryFile(suffix=".tif")
source = GDALRaster( source = GDALRaster(
{ {
"datatype": 1, "datatype": 1,

View File

@ -1,4 +1,3 @@
import tempfile
from io import StringIO from io import StringIO
from django.contrib.gis import gdal from django.contrib.gis import gdal
@ -15,6 +14,7 @@ from django.contrib.gis.geos import (
Polygon, Polygon,
fromstr, fromstr,
) )
from django.core.files.temp import NamedTemporaryFile
from django.core.management import call_command from django.core.management import call_command
from django.db import DatabaseError, NotSupportedError, connection from django.db import DatabaseError, NotSupportedError, connection
from django.db.models import F, OuterRef, Subquery from django.db.models import F, OuterRef, Subquery
@ -232,7 +232,7 @@ class GeoModelTest(TestCase):
self.assertIn('"point": "%s"' % houston.point.ewkt, result) self.assertIn('"point": "%s"' % houston.point.ewkt, result)
# Reload now dumped data # Reload now dumped data
with tempfile.NamedTemporaryFile(mode="w", suffix=".json") as tmp: with NamedTemporaryFile(mode="w", suffix=".json") as tmp:
tmp.write(result) tmp.write(result)
tmp.seek(0) tmp.seek(0)
call_command("loaddata", tmp.name, verbosity=0) call_command("loaddata", tmp.name, verbosity=0)