@@ -187,10 +187,11 @@ def assertLines(self, list_of_expected_lines, string_result):
187187 self .assertEqual (list_of_expected_lines , string_result .split ("\n " ))
188188
189189
190- class Test__cfvariable_common (Mixin__string_representations , tests .IrisTest ):
190+ class Test__print_common (Mixin__string_representations , tests .IrisTest ):
191191 """
192- Test aspects common to all _DimensionalMetadata instances,
193- that is the CFVariableMixin inheritance, plus values array (data-manager).
192+ Test aspects of __str__ and __repr__ output common to all
193+ _DimensionalMetadata instances.
194+ I.E. those from CFVariableMixin, plus values array (data-manager).
194195
195196 Aspects :
196197 * standard_name:
@@ -689,9 +690,9 @@ def test_integers_masked_long(self):
689690 self .assertLines (expected , result )
690691
691692
692- class Test__cfvariable_Coord (Mixin__string_representations , tests .IrisTest ):
693+ class Test__print_Coord (Mixin__string_representations , tests .IrisTest ):
693694 """
694- Test Coord= specific aspects.
695+ Test Coord- specific aspects of __str__ and __repr__ output .
695696
696697 Aspects :
697698 * DimCoord / AuxCoord
@@ -759,9 +760,7 @@ def test_circular(self):
759760 self .assertLines (expected , result )
760761
761762
762- class Test__cfvariable_other_subclasses (
763- Mixin__string_representations , tests .IrisTest
764- ):
763+ class Test__print_noncoord (Mixin__string_representations , tests .IrisTest ):
765764 """
766765 Limited testing of other _DimensionalMetadata subclasses.
767766
@@ -918,5 +917,147 @@ def test_meshcoord(self):
918917 self .assertLines (expected , result )
919918
920919
920+ class Test_summary (Mixin__string_representations , tests .IrisTest ):
921+ """
922+ Test the controls of the 'summary' method.
923+ """
924+
925+ def test_shorten (self ):
926+ coord = self .sample_coord ()
927+ expected = self .repr_str_strings (coord )
928+ result = coord .summary (shorten = True ) + "\n " + coord .summary ()
929+ self .assertEqual (expected , result )
930+
931+ def test_max_values__default (self ):
932+ coord = self .sample_coord ()
933+ result = coord .summary ()
934+ expected = [
935+ "AuxCoord : x / (m)" ,
936+ " points: [0., 1., 2., 3., 4.]" ,
937+ " shape: (5,)" ,
938+ " dtype: float64" ,
939+ " long_name: 'x'" ,
940+ ]
941+ self .assertLines (expected , result )
942+
943+ def test_max_values__2 (self ):
944+ coord = self .sample_coord ()
945+ result = coord .summary (max_values = 2 )
946+ expected = [
947+ "AuxCoord : x / (m)" ,
948+ " points: [0., 1., ..., 3., 4.]" ,
949+ " shape: (5,)" ,
950+ " dtype: float64" ,
951+ " long_name: 'x'" ,
952+ ]
953+ self .assertLines (expected , result )
954+
955+ def test_max_values__bounded__2 (self ):
956+ coord = self .sample_coord (bounded = True )
957+ result = coord .summary (max_values = 2 )
958+ expected = [
959+ "AuxCoord : x / (m)" ,
960+ " points: [0., 1., ..., 3., 4.]" ,
961+ " bounds: [" ,
962+ " [-0.5, 0.5]," ,
963+ " [ 0.5, 1.5]," ,
964+ " ...," ,
965+ " [ 2.5, 3.5]," ,
966+ " [ 3.5, 4.5]]" ,
967+ " shape: (5,) bounds(5, 2)" ,
968+ " dtype: float64" ,
969+ " long_name: 'x'" ,
970+ ]
971+ self .assertLines (expected , result )
972+
973+ def test_max_values__0 (self ):
974+ coord = self .sample_coord (bounded = True )
975+ result = coord .summary (max_values = 0 )
976+ expected = [
977+ "AuxCoord : x / (m)" ,
978+ " points: [...]" ,
979+ " bounds: [...]" ,
980+ " shape: (5,) bounds(5, 2)" ,
981+ " dtype: float64" ,
982+ " long_name: 'x'" ,
983+ ]
984+ self .assertLines (expected , result )
985+
986+ def test_max_array_width__default (self ):
987+ coord = self .sample_coord ()
988+ coord .points = coord .points + 1000.003 # Make the output numbers wider
989+ result = coord .summary ()
990+ expected = [
991+ "AuxCoord : x / (m)" ,
992+ " points: [1000.003, 1001.003, 1002.003, 1003.003, 1004.003]" ,
993+ " shape: (5,)" ,
994+ " dtype: float64" ,
995+ " long_name: 'x'" ,
996+ ]
997+ self .assertLines (expected , result )
998+
999+ with np .printoptions (linewidth = 35 ):
1000+ result = coord .summary ()
1001+ expected = [
1002+ "AuxCoord : x / (m)" ,
1003+ " points: [" ,
1004+ " 1000.003, 1001.003," ,
1005+ " 1002.003, 1003.003," ,
1006+ " 1004.003]" ,
1007+ " shape: (5,)" ,
1008+ " dtype: float64" ,
1009+ " long_name: 'x'" ,
1010+ ]
1011+ self .assertLines (expected , result )
1012+
1013+ def test_max_array_width__set (self ):
1014+ coord = self .sample_coord ()
1015+ coord .points = coord .points + 1000.003 # Make the output numbers wider
1016+ expected = [
1017+ "AuxCoord : x / (m)" ,
1018+ " points: [" ,
1019+ " 1000.003, 1001.003," ,
1020+ " 1002.003, 1003.003," ,
1021+ " 1004.003]" ,
1022+ " shape: (5,)" ,
1023+ " dtype: float64" ,
1024+ " long_name: 'x'" ,
1025+ ]
1026+ result = coord .summary (max_array_width = 35 )
1027+ self .assertLines (expected , result )
1028+
1029+ with np .printoptions (linewidth = 999 ):
1030+ # Show that when set, it ignores the numpy setting
1031+ result = coord .summary (max_array_width = 35 )
1032+ self .assertLines (expected , result )
1033+
1034+ def test_convert_dates (self ):
1035+ coord = self .sample_coord (dates = True )
1036+ result = coord .summary ()
1037+ expected = [
1038+ "AuxCoord : x / (days since 1970-03-5, gregorian calendar)" ,
1039+ " points: [" ,
1040+ (
1041+ " 1970-03-05 00:00:00, 1970-03-06 00:00:00, "
1042+ "1970-03-07 00:00:00,"
1043+ ),
1044+ " 1970-03-08 00:00:00, 1970-03-09 00:00:00]" ,
1045+ " shape: (5,)" ,
1046+ " dtype: float64" ,
1047+ " long_name: 'x'" ,
1048+ ]
1049+ self .assertLines (expected , result )
1050+
1051+ result = coord .summary (convert_dates = False )
1052+ expected = [
1053+ "AuxCoord : x / (days since 1970-03-5, gregorian calendar)" ,
1054+ " points: [0., 1., 2., 3., 4.]" ,
1055+ " shape: (5,)" ,
1056+ " dtype: float64" ,
1057+ " long_name: 'x'" ,
1058+ ]
1059+ self .assertLines (expected , result )
1060+
1061+
9211062if __name__ == "__main__" :
9221063 tests .main ()
0 commit comments