From 85c5143cef71fd8a68427001096c85a4b1874c1e Mon Sep 17 00:00:00 2001 From: James McKinney <26463+jpmckinney@users.noreply.github.com> Date: Sun, 10 Dec 2023 03:17:46 -0500 Subject: [PATCH] test: Update comparisons for different WKT point orders --- boundaries/tests/test_boundary.py | 10 ++++++++-- boundaries/tests/test_geometry.py | 5 ++++- boundaries/tests/test_loadshapefiles.py | 10 ++++------ 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/boundaries/tests/test_boundary.py b/boundaries/tests/test_boundary.py index f79ce07..3770d46 100644 --- a/boundaries/tests/test_boundary.py +++ b/boundaries/tests/test_boundary.py @@ -135,5 +135,11 @@ def test_unary_union(self): boundary = Boundary(shape='MULTIPOLYGON (((0 0,0 5,2.5 5.0001,5 5,0 0)))') boundary.unary_union(Geometry(OGRGeometry('MULTIPOLYGON (((0 0,5 0,5 5,0 0)))'))) - self.assertEqual(boundary.shape.ogr.wkt, 'MULTIPOLYGON (((5 5,5 0,0 0,0 5,2.5 5.0001,5 5)))') - self.assertEqual(boundary.simple_shape.ogr.wkt, 'MULTIPOLYGON (((5 5,5 0,0 0,0 5,5 5)))') + self.assertEqual( + boundary.shape.ogr.difference(OGRGeometry('MULTIPOLYGON (((5 5,5 0,0 0,0 5,2.5 5.0001,5 5)))')).wkt, + 'POLYGON EMPTY', + ) + self.assertEqual( + boundary.simple_shape.ogr.difference(OGRGeometry('MULTIPOLYGON (((5 5,5 0,0 0,0 5,5 5)))')).wkt, + 'POLYGON EMPTY', + ) diff --git a/boundaries/tests/test_geometry.py b/boundaries/tests/test_geometry.py index 6c4e671..f284099 100644 --- a/boundaries/tests/test_geometry.py +++ b/boundaries/tests/test_geometry.py @@ -44,7 +44,10 @@ def test_unary_union(self): geometry = Geometry(OGRGeometry('MULTIPOLYGON (((0 0,0 5,5 5,0 0)),((0 0,5 0,5 5,0 0)))')).unary_union() self.assertIsInstance(geometry, Geometry) self.assertEqual(geometry.geometry.geom_name, 'MULTIPOLYGON') - self.assertEqual(geometry.wkt, 'MULTIPOLYGON (((0 0,0 5,5 5,5 0,0 0)))') + self.assertEqual( + geometry.difference(OGRGeometry('MULTIPOLYGON (((0 0,0 5,5 5,5 0,0 0)))')).wkt, + 'POLYGON EMPTY', + ) def test_merge_with_ogrgeometry(self): other = OGRGeometry('MULTIPOLYGON (((5 0,5 3,2 0,5 0)))') diff --git a/boundaries/tests/test_loadshapefiles.py b/boundaries/tests/test_loadshapefiles.py index 9cf508c..44a3397 100644 --- a/boundaries/tests/test_loadshapefiles.py +++ b/boundaries/tests/test_loadshapefiles.py @@ -5,6 +5,7 @@ from datetime import date from zipfile import BadZipfile +from django.contrib.gis.gdal import OGRGeometry from django.core.management import call_command from django.test import TestCase from testfixtures import LogCapture @@ -196,12 +197,9 @@ def test_union_merge_strategy(self): Command().load_boundary(self.feature, 'invalid') boundary = Command().load_boundary(self.feature, 'union') - try: # Django < 2.2 - self.assertEqual(boundary.shape.ogr.wkt, 'MULTIPOLYGON (((0.0001 0.0001,0 5,0 5,0 5,5 5,5 5,0.0001 0.0001)))') - self.assertEqual(boundary.simple_shape.ogr.wkt, 'MULTIPOLYGON (((0.0001 0.0001,0 5,5 5,5 5,0.0001 0.0001)))') - except AssertionError: - self.assertEqual(boundary.shape.ogr.wkt, 'MULTIPOLYGON (((0.0001 0.0001,0 5,5 5,0.0001 0.0001)))') - self.assertEqual(boundary.simple_shape.ogr.wkt, 'MULTIPOLYGON (((0.0001 0.0001,0 5,5 5,0.0001 0.0001)))') + expected = OGRGeometry('MULTIPOLYGON (((0.0001 0.0001,0 5,5 5,0.0001 0.0001)))') + self.assertEqual(boundary.shape.ogr.difference(expected).wkt, 'POLYGON EMPTY') + self.assertEqual(boundary.simple_shape.ogr.difference(expected).wkt, 'POLYGON EMPTY') self.assertRegex(boundary.centroid.ogr.wkt, r'\APOINT \(1\.6667 3\.3333666666666+7\)\Z') self.assertEqual(boundary.extent, (0.0, 0.0001, 5.0, 5.0))