Skip to content

Commit 0ddcc77

Browse files
Refactor tests with recursive assertion method
1 parent 5e71bdd commit 0ddcc77

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

geotrek/core/tests/test_commands.py

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,16 @@ def test_load_paths_within_spatial_extent_no_srid_geom(self):
234234

235235
@skipIf(not settings.TREKKING_TOPOLOGY_ENABLED, 'Test with dynamic segmentation only')
236236
class ReorderTopologiesPathAggregationTest(TestCase):
237+
238+
def assertRecursiveAlmostEqual(self, a, b):
239+
if type(a) is float:
240+
assert type(b) is float
241+
self.assertAlmostEqual(a, b)
242+
else:
243+
assert len(a) == len(b)
244+
for i in range(len(a)):
245+
self.assertRecursiveAlmostEqual(a[i], b[i])
246+
237247
def setUp(self):
238248
"""
239249
⠳ ⠞
@@ -432,16 +442,17 @@ def test_split_reorder_3(self):
432442
[0, 0, 1, 1, 2, 3, 3, 4, 4])
433443
call_command('reorder_topologies', verbosity=0)
434444
geometries = self.get_geometries(topo)
435-
self.assertEqual(geometries, [LineString((700000, 6600000), (700035, 6600035), srid=2154),
436-
LineString((700035, 6600035), (700050, 6600050), srid=2154),
437-
LineString((700050, 6600050), (700035, 6600065), srid=2154),
438-
LineString((700035, 6600065),
439-
(700007.142857143, 6600092.85714286), srid=2154),
440-
Point(700007.142857143, 6600092.85714286, srid=2154),
441-
LineString((700007.142857143, 6600092.85714286), (700035, 6600065), srid=2154),
442-
LineString((700035, 6600065), (700050, 6600050), srid=2154),
443-
LineString((700050, 6600050), (700075, 6600075), srid=2154),
444-
LineString((700075, 6600075), (700100, 6600100), srid=2154)])
445+
for geom, expected in zip(geometries, [LineString((700000, 6600000), (700035, 6600035), srid=2154),
446+
LineString((700035, 6600035), (700050, 6600050), srid=2154),
447+
LineString((700050, 6600050), (700035, 6600065), srid=2154),
448+
LineString((700035, 6600065),
449+
(700007.142857143, 6600092.85714286), srid=2154),
450+
Point(700007.142857143, 6600092.85714286, srid=2154),
451+
LineString((700007.142857143, 6600092.85714286), (700035, 6600065), srid=2154),
452+
LineString((700035, 6600065), (700050, 6600050), srid=2154),
453+
LineString((700050, 6600050), (700075, 6600075), srid=2154),
454+
LineString((700075, 6600075), (700100, 6600100), srid=2154)]):
455+
self.assertRecursiveAlmostEqual(geom, expected)
445456

446457
self.assertEqual(list(PathAggregation.objects.filter(topo_object=topo).values_list('order', flat=True)),
447458
[0, 1, 2, 3, 4, 5, 6, 7, 8])
@@ -616,11 +627,12 @@ def test_split_reorder_fail(self):
616627
srid=settings.SRID), topo.geom)
617628
PathFactory.create(geom=LineString(Point(700000, 6600090), Point(700090, 6600000), srid=settings.SRID))
618629
topo.reload()
619-
self.assertEqual(MultiLineString(LineString((700000, 6600000), (700045, 6600045)),
620-
LineString((700045, 6600045), (700050, 6600050)),
621-
LineString((700050, 6600050), (700025, 6600075)),
622-
LineString((700050, 6600050), (700100, 6600100)),
623-
srid=settings.SRID), topo.geom)
630+
for expected, geom in zip(MultiLineString(LineString((700000, 6600000), (700045, 6600045)),
631+
LineString((700045, 6600045), (700050, 6600050)),
632+
LineString((700050, 6600050), (700025, 6600075)),
633+
LineString((700050, 6600050), (700100, 6600100)),
634+
srid=settings.SRID), topo.geom):
635+
self.assertRecursiveAlmostEqual(expected, geom)
624636
self.assertEqual(list(PathAggregation.objects.filter(topo_object=topo).values_list('order', flat=True)),
625637
[0, 0, 1, 2, 3])
626638
output = StringIO()

0 commit comments

Comments
 (0)