Commit 19fcf083 authored by Claude Paroz's avatar Claude Paroz
Browse files

Replaced try/finally by mock.patch in geos tests

parent a131d9ce
Loading
Loading
Loading
Loading
+19 −30
Original line number Diff line number Diff line
@@ -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,6 @@ 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)
@@ -909,10 +909,7 @@ 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

        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, clone=True)
        finally:
            gdal.HAS_GDAL = old_has_gdal

    def test_extent(self):
        "Testing `extent` method."