Skip to content

Commit d620250

Browse files
Merge pull request #7 from djkirkham/slice_order_test_2
Test all permutations and change order of source cube dimensions (because I'm picky).
2 parents e23f2d8 + c65d508 commit d620250

File tree

1 file changed

+14
-72
lines changed

1 file changed

+14
-72
lines changed

lib/iris/tests/unit/cube/test_Cube.py

Lines changed: 14 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
# importing anything else.
2424
import iris.tests as tests
2525

26+
from itertools import permutations
27+
2628
import biggus
2729
import numpy as np
2830
import numpy.ma as ma
@@ -418,16 +420,16 @@ def setUp(self):
418420
'''
419421
setup a 4D iris cube, each dimension is length 1.
420422
The dimensions are;
421-
dim1: height
422-
dim2: time
423-
dim3: longitude
424-
dim4: latitude
423+
dim1: time
424+
dim2: height
425+
dim3: latitude
426+
dim4: longitude
425427
'''
426428
self.cube = iris.cube.Cube(np.array([[[[8.]]]]))
427-
self.cube.add_dim_coord(iris.coords.DimCoord([0], "height"), [0])
428-
self.cube.add_dim_coord(iris.coords.DimCoord([0], "time"), [1])
429-
self.cube.add_dim_coord(iris.coords.DimCoord([0], "longitude"), [2])
430-
self.cube.add_dim_coord(iris.coords.DimCoord([0], "latitude"), [3])
429+
self.cube.add_dim_coord(iris.coords.DimCoord([0], "time"), [0])
430+
self.cube.add_dim_coord(iris.coords.DimCoord([0], "height"), [1])
431+
self.cube.add_dim_coord(iris.coords.DimCoord([0], "latitude"), [2])
432+
self.cube.add_dim_coord(iris.coords.DimCoord([0], "longitude"), [3])
431433

432434
@staticmethod
433435
def expected_cube_setup(dim1name, dim2name, dim3name):
@@ -478,71 +480,11 @@ def check_order(self, dim1, dim2, dim3, dim_to_remove):
478480
sliced_cube = next(self.cube.slices([dim1, dim2, dim3]))
479481
sliced_cube.remove_coord(dim_to_remove)
480482
expected_cube = self.expected_cube_setup(dim1, dim2, dim3)
481-
return self.assertEqual(sliced_cube, expected_cube)
482-
483-
484-
def test_height_long_lat(self):
485-
'''
486-
tests the slicing in this order:
487-
height
488-
longitude
489-
latitude
490-
'''
491-
self.check_order("height", "longitude", "latitude", "time")
492-
493-
def test_long_height_lat(self):
494-
'''
495-
tests the slicing in this order:
496-
longitude
497-
height
498-
latitude
499-
'''
500-
self.check_order("longitude", "height", "latitude", "time")
501-
502-
def test_time_height_lat(self):
503-
'''
504-
tests the slicing in this order:
505-
time
506-
height
507-
latitude
508-
'''
509-
self.check_order("time", "height", "latitude", "longitude")
483+
self.assertEqual(sliced_cube, expected_cube)
510484

511-
def test_time_height_long(self):
512-
'''
513-
tests the slicing in this order:
514-
time
515-
height
516-
longitude
517-
'''
518-
self.check_order("time", "height", "longitude", "latitude")
519-
520-
def test_long_lat_height(self):
521-
'''
522-
tests the slicing in this order:
523-
longitude
524-
latitude
525-
height
526-
'''
527-
self.check_order("longitude", "latitude", "height", "time")
528-
529-
def test_lat_height_time(self):
530-
'''
531-
tests the slicing in this order:
532-
latitude
533-
height
534-
time
535-
'''
536-
self.check_order("latitude", "height", "time", "longitude")
537-
538-
def test_long_height_time(self):
539-
'''
540-
tests the slicing in this order:
541-
longitude
542-
height
543-
time
544-
'''
545-
self.check_order("longitude", "height", "time", "latitude")
485+
def test_all_permutations(self):
486+
for perm in permutations(["time", "height", "latitude", "longitude"]):
487+
self.check_order(*perm)
546488

547489

548490
@tests.skip_data

0 commit comments

Comments
 (0)