diff --git a/tests/gis_tests/geos_tests/test_geos.py b/tests/gis_tests/geos_tests/test_geos.py index b0843c9bd2..4fda24cc24 100644 --- a/tests/gis_tests/geos_tests/test_geos.py +++ b/tests/gis_tests/geos_tests/test_geos.py @@ -17,6 +17,7 @@ from django.contrib.gis.geos import ( ) from django.contrib.gis.geos.base import GEOSBase from django.contrib.gis.shortcuts import numpy +from django.test import mock from django.utils import six from django.utils.encoding import force_bytes from django.utils.six.moves import range @@ -896,7 +897,19 @@ class GEOSTest(unittest.TestCase, TestDataMixin): """ Testing `transform` method (SRID match) """ # transform() should no-op if source & dest SRIDs match, # regardless of whether GDAL is available. - if gdal.HAS_GDAL: + g = GEOSGeometry('POINT (-104.609 38.255)', 4326) + gt = g.tuple + g.transform(4326) + self.assertEqual(g.tuple, gt) + self.assertEqual(g.srid, 4326) + + g = GEOSGeometry('POINT (-104.609 38.255)', 4326) + g1 = g.transform(4326, clone=True) + self.assertEqual(g1.tuple, g.tuple) + self.assertEqual(g1.srid, 4326) + self.assertIsNot(g1, g, "Clone didn't happen") + + with mock.patch('django.contrib.gis.gdal.HAS_GDAL', False): g = GEOSGeometry('POINT (-104.609 38.255)', 4326) gt = g.tuple g.transform(4326) @@ -909,24 +922,6 @@ class GEOSTest(unittest.TestCase, TestDataMixin): self.assertEqual(g1.srid, 4326) self.assertIsNot(g1, g, "Clone didn't happen") - old_has_gdal = gdal.HAS_GDAL - try: - gdal.HAS_GDAL = False - - g = GEOSGeometry('POINT (-104.609 38.255)', 4326) - gt = g.tuple - g.transform(4326) - self.assertEqual(g.tuple, gt) - self.assertEqual(g.srid, 4326) - - g = GEOSGeometry('POINT (-104.609 38.255)', 4326) - g1 = g.transform(4326, clone=True) - self.assertEqual(g1.tuple, g.tuple) - self.assertEqual(g1.srid, 4326) - self.assertIsNot(g1, g, "Clone didn't happen") - finally: - gdal.HAS_GDAL = old_has_gdal - def test_transform_nosrid(self): """ Testing `transform` method (no SRID or negative SRID) """ @@ -942,20 +937,14 @@ class GEOSTest(unittest.TestCase, TestDataMixin): g = GEOSGeometry('POINT (-104.609 38.255)', srid=-1) self.assertRaises(GEOSException, g.transform, 2774, clone=True) - @skipUnless(HAS_GDAL, "GDAL is required.") + @mock.patch('django.contrib.gis.gdal.HAS_GDAL', False) def test_transform_nogdal(self): """ Testing `transform` method (GDAL not available) """ - old_has_gdal = gdal.HAS_GDAL - try: - gdal.HAS_GDAL = False + g = GEOSGeometry('POINT (-104.609 38.255)', 4326) + self.assertRaises(GEOSException, g.transform, 2774) - g = GEOSGeometry('POINT (-104.609 38.255)', 4326) - self.assertRaises(GEOSException, g.transform, 2774) - - g = GEOSGeometry('POINT (-104.609 38.255)', 4326) - self.assertRaises(GEOSException, g.transform, 2774, clone=True) - finally: - gdal.HAS_GDAL = old_has_gdal + g = GEOSGeometry('POINT (-104.609 38.255)', 4326) + self.assertRaises(GEOSException, g.transform, 2774, clone=True) def test_extent(self): "Testing `extent` method."