Skip to content

Commit 56e5ea8

Browse files
authored
Fixed #34374 -- Fixed GIS tests on Windows.
1 parent 4cb5573 commit 56e5ea8

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

tests/gis_tests/gdal_tests/test_raster.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from django.contrib.gis.gdal.error import GDALException
1111
from django.contrib.gis.gdal.raster.band import GDALBand
1212
from django.contrib.gis.shortcuts import numpy
13+
from django.core.files.temp import NamedTemporaryFile
1314
from django.test import SimpleTestCase
1415

1516
from ..data.rasters.textrasters import JSON_RASTER
@@ -148,7 +149,7 @@ def test_memory_based_raster_creation(self):
148149

149150
def test_file_based_raster_creation(self):
150151
# Prepare tempfile
151-
rstfile = tempfile.NamedTemporaryFile(suffix=".tif")
152+
rstfile = NamedTemporaryFile(suffix=".tif")
152153

153154
# Create file-based raster from scratch
154155
GDALRaster(
@@ -264,7 +265,7 @@ def test_vsi_buffer_property(self):
264265
self.assertIsNone(self.rs.vsi_buffer)
265266

266267
def test_vsi_vsizip_filesystem(self):
267-
rst_zipfile = tempfile.NamedTemporaryFile(suffix=".zip")
268+
rst_zipfile = NamedTemporaryFile(suffix=".zip")
268269
with zipfile.ZipFile(rst_zipfile, mode="w") as zf:
269270
zf.write(self.rs_path, "raster.tif")
270271
rst_path = "/vsizip/" + os.path.join(rst_zipfile.name, "raster.tif")
@@ -406,7 +407,7 @@ def test_raster_info_accessor(self):
406407
self.assertIn("NAD83 / Florida GDL Albers", infos)
407408

408409
def test_compressed_file_based_raster_creation(self):
409-
rstfile = tempfile.NamedTemporaryFile(suffix=".tif")
410+
rstfile = NamedTemporaryFile(suffix=".tif")
410411
# Make a compressed copy of an existing raster.
411412
compressed = self.rs.warp(
412413
{"papsz_options": {"compress": "packbits"}, "name": rstfile.name}
@@ -554,7 +555,7 @@ def test_raster_warp_nodata_zone(self):
554555
self.assertEqual(result, [23] * 16)
555556

556557
def test_raster_clone(self):
557-
rstfile = tempfile.NamedTemporaryFile(suffix=".tif")
558+
rstfile = NamedTemporaryFile(suffix=".tif")
558559
tests = [
559560
("MEM", "", 23), # In memory raster.
560561
("tif", rstfile.name, 99), # In file based raster.
@@ -600,7 +601,7 @@ def test_raster_transform(self):
600601
for srs in tests:
601602
with self.subTest(srs=srs):
602603
# Prepare tempfile and nodata value.
603-
rstfile = tempfile.NamedTemporaryFile(suffix=".tif")
604+
rstfile = NamedTemporaryFile(suffix=".tif")
604605
ndv = 99
605606
# Create in file based raster.
606607
source = GDALRaster(
@@ -701,7 +702,7 @@ def test_raster_transform(self):
701702
def test_raster_transform_clone(self):
702703
with mock.patch.object(GDALRaster, "clone") as mocked_clone:
703704
# Create in file based raster.
704-
rstfile = tempfile.NamedTemporaryFile(suffix=".tif")
705+
rstfile = NamedTemporaryFile(suffix=".tif")
705706
source = GDALRaster(
706707
{
707708
"datatype": 1,
@@ -729,7 +730,7 @@ def test_raster_transform_clone(self):
729730

730731
def test_raster_transform_clone_name(self):
731732
# Create in file based raster.
732-
rstfile = tempfile.NamedTemporaryFile(suffix=".tif")
733+
rstfile = NamedTemporaryFile(suffix=".tif")
733734
source = GDALRaster(
734735
{
735736
"datatype": 1,

tests/gis_tests/geoapp/tests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import tempfile
21
from io import StringIO
32

43
from django.contrib.gis import gdal
@@ -15,6 +14,7 @@
1514
Polygon,
1615
fromstr,
1716
)
17+
from django.core.files.temp import NamedTemporaryFile
1818
from django.core.management import call_command
1919
from django.db import DatabaseError, NotSupportedError, connection
2020
from django.db.models import F, OuterRef, Subquery
@@ -232,7 +232,7 @@ def test_dumpdata_loaddata_cycle(self):
232232
self.assertIn('"point": "%s"' % houston.point.ewkt, result)
233233

234234
# Reload now dumped data
235-
with tempfile.NamedTemporaryFile(mode="w", suffix=".json") as tmp:
235+
with NamedTemporaryFile(mode="w", suffix=".json") as tmp:
236236
tmp.write(result)
237237
tmp.seek(0)
238238
call_command("loaddata", tmp.name, verbosity=0)

0 commit comments

Comments
 (0)