|
@@ -5,7 +5,7 @@ import pickle
|
|
|
import random
|
|
|
from binascii import a2b_hex
|
|
|
from io import BytesIO
|
|
|
-from unittest import mock
|
|
|
+from unittest import mock, skipIf
|
|
|
|
|
|
from django.contrib.gis import gdal
|
|
|
from django.contrib.gis.geos import (
|
|
@@ -360,6 +360,32 @@ class GEOSTest(SimpleTestCase, TestDataMixin):
|
|
|
line.reverse()
|
|
|
self.assertEqual(line.ewkt, 'SRID=4326;LINESTRING (151.2607 -33.887, 144.963 -37.8143)')
|
|
|
|
|
|
+ def _test_is_counterclockwise(self):
|
|
|
+ lr = LinearRing((0, 0), (1, 0), (0, 1), (0, 0))
|
|
|
+ self.assertIs(lr.is_counterclockwise, True)
|
|
|
+ lr.reverse()
|
|
|
+ self.assertIs(lr.is_counterclockwise, False)
|
|
|
+ msg = 'Orientation of an empty LinearRing cannot be determined.'
|
|
|
+ with self.assertRaisesMessage(ValueError, msg):
|
|
|
+ LinearRing().is_counterclockwise
|
|
|
+
|
|
|
+ @skipIf(geos_version_tuple() < (3, 7), 'GEOS >= 3.7.0 is required')
|
|
|
+ def test_is_counterclockwise(self):
|
|
|
+ self._test_is_counterclockwise()
|
|
|
+
|
|
|
+ @skipIf(geos_version_tuple() < (3, 7), 'GEOS >= 3.7.0 is required')
|
|
|
+ def test_is_counterclockwise_geos_error(self):
|
|
|
+ with mock.patch('django.contrib.gis.geos.prototypes.cs_is_ccw') as mocked:
|
|
|
+ mocked.return_value = 0
|
|
|
+ mocked.func_name = 'GEOSCoordSeq_isCCW'
|
|
|
+ msg = 'Error encountered in GEOS C function "GEOSCoordSeq_isCCW".'
|
|
|
+ with self.assertRaisesMessage(GEOSException, msg):
|
|
|
+ LinearRing((0, 0), (1, 0), (0, 1), (0, 0)).is_counterclockwise
|
|
|
+
|
|
|
+ @mock.patch('django.contrib.gis.geos.libgeos.geos_version', lambda: b'3.6.9')
|
|
|
+ def test_is_counterclockwise_fallback(self):
|
|
|
+ self._test_is_counterclockwise()
|
|
|
+
|
|
|
def test_multilinestring(self):
|
|
|
"Testing MultiLineString objects."
|
|
|
prev = fromstr('POINT(0 0)')
|