summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2015-07-18 15:27:59 +0200
committerClaude Paroz <claude@2xlibre.net>2015-07-18 15:34:40 +0200
commit19fcf083d364d734a52ccab0ad51143445be7b7b (patch)
treebae0feb612b41a9cb05848f75d5dffa358c6054b
parenta131d9ce551aded184bc4dbfd7257594b212b92a (diff)
Replaced try/finally by mock.patch in geos tests
-rw-r--r--tests/gis_tests/geos_tests/test_geos.py45
1 files changed, 17 insertions, 28 deletions
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,23 +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)
+ 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")
-
- old_has_gdal = gdal.HAS_GDAL
- try:
- gdal.HAS_GDAL = False
+ 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)
@@ -924,8 +921,6 @@ class GEOSTest(unittest.TestCase, TestDataMixin):
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."