diff --git a/docs/src/further_topics/lenient_maths.rst b/docs/src/further_topics/lenient_maths.rst index 643bd37e76..818efe4763 100644 --- a/docs/src/further_topics/lenient_maths.rst +++ b/docs/src/further_topics/lenient_maths.rst @@ -84,10 +84,10 @@ represents the output of an low-resolution global atmospheric ``experiment``, forecast_reference_time 2009-09-09 17:10:00 time 2009-09-09 17:10:00 Attributes: - Conventions CF-1.5 + Conventions 'CF-1.5' STASH m01s00i004 - experiment-id RT3 50 - source Data from Met Office Unified Model 7.04 + experiment-id 'RT3 50' + source 'Data from Met Office Unified Model 7.04' Consider also the following :class:`~iris.cube.Cube`, which has the same global spatial extent, and acts as a ``control``, @@ -103,9 +103,9 @@ spatial extent, and acts as a ``control``, model_level_number 1 time 2009-09-09 17:10:00 Attributes: - Conventions CF-1.7 + Conventions 'CF-1.7' STASH m01s00i004 - source Data from Met Office Unified Model 7.04 + source 'Data from Met Office Unified Model 7.04' Now let's subtract these cubes in order to calculate a simple ``difference``, @@ -129,8 +129,8 @@ Now let's subtract these cubes in order to calculate a simple ``difference``, forecast_reference_time 2009-09-09 17:10:00 time 2009-09-09 17:10:00 Attributes: - experiment-id RT3 50 - source Data from Met Office Unified Model 7.04 + experiment-id 'RT3 50' + source 'Data from Met Office Unified Model 7.04' Note that, cube maths automatically takes care of broadcasting the dimensionality of the ``control`` up to that of the ``experiment``, in order to @@ -218,7 +218,7 @@ time perform **strict** cube maths instead, Scalar coordinates: time 2009-09-09 17:10:00 Attributes: - source Data from Met Office Unified Model 7.04 + source 'Data from Met Office Unified Model 7.04' Although the numerical result of this strict cube maths operation is identical, it is not as rich in metadata as the :ref:`lenient alternative `. diff --git a/docs/src/further_topics/metadata.rst b/docs/src/further_topics/metadata.rst index 79e9c164a0..b8c2caa402 100644 --- a/docs/src/further_topics/metadata.rst +++ b/docs/src/further_topics/metadata.rst @@ -120,10 +120,10 @@ For example, given the following :class:`~iris.cube.Cube`, Cell methods: mean time (6 hour) Attributes: - Conventions CF-1.5 - Model scenario A1B + Conventions 'CF-1.5' + Model scenario 'A1B' STASH m01s03i236 - source Data from Met Office Unified Model 6.05 + source 'Data from Met Office Unified Model 6.05' We can easily get all of the associated metadata of the :class:`~iris.cube.Cube` using the ``metadata`` property: diff --git a/docs/src/userguide/cube_maths.rst b/docs/src/userguide/cube_maths.rst index 78490cd749..e8a1744a44 100644 --- a/docs/src/userguide/cube_maths.rst +++ b/docs/src/userguide/cube_maths.rst @@ -63,9 +63,9 @@ but with the data representing their difference: forecast_reference_time 1859-09-01 06:00:00 height 1.5 m Attributes: - Conventions CF-1.5 - Model scenario E1 - source Data from Met Office Unified Model 6.05 + Conventions 'CF-1.5' + Model scenario 'E1' + source 'Data from Met Office Unified Model 6.05' .. note:: diff --git a/docs/src/userguide/cube_statistics.rst b/docs/src/userguide/cube_statistics.rst index ac66ff4e53..980f1e132f 100644 --- a/docs/src/userguide/cube_statistics.rst +++ b/docs/src/userguide/cube_statistics.rst @@ -53,8 +53,8 @@ For instance, suppose we have a cube: forecast_reference_time 2009-11-19 04:00:00 Attributes: STASH m01s00i004 - source Data from Met Office Unified Model - um_version 7.3 + source 'Data from Met Office Unified Model' + um_version '7.3' In this case we have a 4 dimensional cube; @@ -84,8 +84,8 @@ we can pass the coordinate name and the aggregation definition to the mean model_level_number Attributes: STASH m01s00i004 - source Data from Met Office Unified Model - um_version 7.3 + source 'Data from Met Office Unified Model' + um_version '7.3' Similarly other analysis operators such as ``MAX``, ``MIN`` and ``STD_DEV`` @@ -143,8 +143,8 @@ These areas can now be passed to the ``collapsed`` method as weights: mean grid_longitude, grid_latitude Attributes: STASH m01s00i004 - source Data from Met Office Unified Model - um_version 7.3 + source 'Data from Met Office Unified Model' + um_version '7.3' Several examples of area averaging exist in the gallery which may be of interest, including an example on taking a :ref:`global area-weighted mean @@ -229,7 +229,7 @@ Printing this cube now shows that two extra coordinates exist on the cube: Cell methods: mean month, year Attributes: - Conventions CF-1.5 + Conventions 'CF-1.5' STASH m01s00i024 diff --git a/docs/src/userguide/interpolation_and_regridding.rst b/docs/src/userguide/interpolation_and_regridding.rst index 5573c4aa8e..f590485606 100644 --- a/docs/src/userguide/interpolation_and_regridding.rst +++ b/docs/src/userguide/interpolation_and_regridding.rst @@ -79,7 +79,7 @@ Let's take the air temperature cube we've seen previously: mean over years time Attributes: STASH m01s16i203 - source Data from Met Office Unified Model + source 'Data from Met Office Unified Model' We can interpolate specific values from the coordinates of the cube: @@ -98,7 +98,7 @@ We can interpolate specific values from the coordinates of the cube: mean over years time Attributes: STASH m01s16i203 - source Data from Met Office Unified Model + source 'Data from Met Office Unified Model' As we can see, the resulting cube is scalar and has longitude and latitude coordinates with the values defined in our sample points. diff --git a/docs/src/userguide/iris_cubes.rst b/docs/src/userguide/iris_cubes.rst index 64a9bfd822..d13dee369c 100644 --- a/docs/src/userguide/iris_cubes.rst +++ b/docs/src/userguide/iris_cubes.rst @@ -172,8 +172,8 @@ output as this is the quickest way of inspecting the contents of a cube. Here is forecast_reference_time 2009-11-19 04:00:00 Attributes: STASH m01s00i004 - source Data from Met Office Unified Model - um_version 7.3 + source 'Data from Met Office Unified Model' + um_version '7.3' Using this output we can deduce that: diff --git a/docs/src/userguide/loading_iris_cubes.rst b/docs/src/userguide/loading_iris_cubes.rst index ae2f807fe9..fb938975e8 100644 --- a/docs/src/userguide/loading_iris_cubes.rst +++ b/docs/src/userguide/loading_iris_cubes.rst @@ -100,8 +100,8 @@ list indexing can be used: forecast_reference_time 2009-11-19 04:00:00 Attributes: STASH m01s00i004 - source Data from Met Office Unified Model - um_version 7.3 + source 'Data from Met Office Unified Model' + um_version '7.3' Notice that the result of printing a **cube** is a little more verbose than it was when printing a **list of cubes**. In addition to the very short summary diff --git a/docs/src/userguide/navigating_a_cube.rst b/docs/src/userguide/navigating_a_cube.rst index 74b47b258e..c5924a61c6 100644 --- a/docs/src/userguide/navigating_a_cube.rst +++ b/docs/src/userguide/navigating_a_cube.rst @@ -33,9 +33,9 @@ We have already seen a basic string representation of a cube when printing: forecast_reference_time 2006-06-15 00:00:00 time 2006-06-15 00:00:00 Attributes: - Conventions CF-1.5 + Conventions 'CF-1.5' STASH m01s16i222 - source Data from Met Office Unified Model 6.01 + source 'Data from Met Office Unified Model 6.01' This representation is equivalent to passing the cube to the :func:`str` function. This function can be used on @@ -169,9 +169,9 @@ We can add and remove coordinates via :func:`Cube.add_dim_coord>> print(cube2) air_temperature / (K) (longitude: 49; latitude: 37) @@ -130,10 +130,10 @@ class Resolve: Cell methods: mean time (6 hour) Attributes: - Conventions CF-1.5 - Model scenario E1 + Conventions 'CF-1.5' + Model scenario 'E1' STASH m01s03i236 - source Data from Met Office Unified Model 6.05 + source 'Data from Met Office Unified Model 6.05' >>> print(data.shape) (240, 37, 49) @@ -153,9 +153,9 @@ class Resolve: Cell methods: mean time (6 hour) Attributes: - Conventions CF-1.5 + Conventions 'CF-1.5' STASH m01s03i236 - source Data from Met Office Unified Model 6.05 + source 'Data from Met Office Unified Model 6.05' Secondly, creating an *empty* ``resolver`` instance, that may be called *multiple* times with *different* :class:`~iris.cube.Cube` operands and *different* ``data``, @@ -2413,10 +2413,10 @@ def mapped(self): Cell methods: mean time (6 hour) Attributes: - Conventions CF-1.5 - Model scenario A1B + Conventions 'CF-1.5' + Model scenario 'A1B' STASH m01s03i236 - source Data from Met Office Unified Model 6.05 + source 'Data from Met Office Unified Model 6.05' >>> print(cube2) air_temperature / (K) (longitude: 49; latitude: 37) Dimension coordinates: @@ -2430,10 +2430,10 @@ def mapped(self): Cell methods: mean time (6 hour) Attributes: - Conventions CF-1.5 - Model scenario E1 + Conventions 'CF-1.5' + Model scenario 'E1' STASH m01s03i236 - source Data from Met Office Unified Model 6.05 + source 'Data from Met Office Unified Model 6.05' >>> Resolve().mapped is None True >>> resolver = Resolve(cube1, cube2) @@ -2481,10 +2481,10 @@ def shape(self): Cell methods: mean time (6 hour) Attributes: - Conventions CF-1.5 - Model scenario A1B + Conventions 'CF-1.5' + Model scenario 'A1B' STASH m01s03i236 - source Data from Met Office Unified Model 6.05 + source 'Data from Met Office Unified Model 6.05' >>> print(cube2) air_temperature / (K) (longitude: 49; latitude: 37) Dimension coordinates: @@ -2498,10 +2498,10 @@ def shape(self): Cell methods: mean time (6 hour) Attributes: - Conventions CF-1.5 - Model scenario E1 + Conventions 'CF-1.5' + Model scenario 'E1' STASH m01s03i236 - source Data from Met Office Unified Model 6.05 + source 'Data from Met Office Unified Model 6.05' >>> Resolve().shape is None True >>> Resolve(cube1, cube2).shape diff --git a/lib/iris/coords.py b/lib/iris/coords.py index 6e9bd6c840..b236d407da 100644 --- a/lib/iris/coords.py +++ b/lib/iris/coords.py @@ -571,10 +571,25 @@ def reindent_data_string(text, n_indent): # work for all those defined so far. show = val is not None and val is not False if show: - # add a section for this property (metadata item) - # TODO: modify to do multi-line attribute output - add_output(newline_indent) - add_output(f"{name}: {val!r}", section=name) + if name == "attributes": + # Use a multi-line form for this. + add_output(newline_indent) + add_output("attributes:", section="attributes") + max_attname_len = max(len(attr) for attr in val.keys()) + for attrname, attrval in val.items(): + attrname = attrname.ljust(max_attname_len) + if isinstance(attrval, str): + # quote strings + attrval = repr(attrval) + # and abbreviate really long ones + attrval = iris.util.clip_string(attrval) + attr_string = f"{attrname} {attrval}" + add_output(newline_indent + indent + attr_string) + else: + # add a one-line section for this property + # (aka metadata field) + add_output(newline_indent) + add_output(f"{name}: {val!r}", section=name) return "\n".join(output_lines) diff --git a/lib/iris/cube.py b/lib/iris/cube.py index 2cd29682dd..8183dd385c 100644 --- a/lib/iris/cube.py +++ b/lib/iris/cube.py @@ -745,7 +745,7 @@ class Cube(CFVariableMixin): mean over years time Attributes: STASH m01s16i203 - source Data from Met Office Unified Model + source 'Data from Met Office Unified Model' See the :doc:`user guide` for more information. @@ -3636,7 +3636,7 @@ def collapsed(self, coords, aggregator, **kwargs): mean month, year mean longitude Attributes: - Conventions CF-1.5 + Conventions 'CF-1.5' STASH m01s00i024 @@ -3871,7 +3871,7 @@ def aggregated_by(self, coords, aggregator, **kwargs): mean month, year mean year Attributes: - Conventions CF-1.5 + Conventions 'CF-1.5' STASH m01s00i024 """ @@ -4076,8 +4076,8 @@ def rolling_window(self, coord, aggregator, window, **kwargs): Attributes: STASH m01s00i024 source \ -Data from Met Office Unified Model - um_version 7.6 +'Data from Met Office Unified Model' + um_version '7.6' >>> print(air_press.rolling_window('time', iris.analysis.MEAN, 3)) @@ -4102,8 +4102,8 @@ def rolling_window(self, coord, aggregator, window, **kwargs): Attributes: STASH m01s00i024 source \ -Data from Met Office Unified Model - um_version 7.6 +'Data from Met Office Unified Model' + um_version '7.6' Notice that the forecast_period dimension now represents the 4 possible windows of size 3 from the original cube. diff --git a/lib/iris/experimental/ugrid/mesh.py b/lib/iris/experimental/ugrid/mesh.py index 9e8074c83a..7135ada63a 100644 --- a/lib/iris/experimental/ugrid/mesh.py +++ b/lib/iris/experimental/ugrid/mesh.py @@ -29,7 +29,7 @@ from ...config import get_logger from ...coords import AuxCoord, _DimensionalMetadata from ...exceptions import ConnectivityNotFoundError, CoordinateNotFoundError -from ...util import array_equal, guess_coord_axis +from ...util import array_equal, clip_string, guess_coord_axis from .metadata import ConnectivityMetadata, MeshCoordMetadata, MeshMetadata # Configure the logger. @@ -1044,7 +1044,21 @@ def line(text, i_indent=0): else: show = val is not None if show: - line(f"{name}: {val!r}", 1) + if name == "attributes": + # Use a multi-line form for this. + line("attributes:", 1) + max_attname_len = max(len(attr) for attr in val.keys()) + for attrname, attrval in val.items(): + attrname = attrname.ljust(max_attname_len) + if isinstance(attrval, str): + # quote strings + attrval = repr(attrval) + # and abbreviate really long ones + attrval = clip_string(attrval) + attr_string = f"{attrname} {attrval}" + line(attr_string, 2) + else: + line(f"{name}: {val!r}", 1) result = "\n".join(lines) return result diff --git a/lib/iris/tests/results/cdm/TestStockCubeStringRepresentations/0d_str.txt b/lib/iris/tests/results/cdm/TestStockCubeStringRepresentations/0d_str.txt index a6738e654f..a4c1157df2 100644 --- a/lib/iris/tests/results/cdm/TestStockCubeStringRepresentations/0d_str.txt +++ b/lib/iris/tests/results/cdm/TestStockCubeStringRepresentations/0d_str.txt @@ -10,4 +10,4 @@ air_potential_temperature / (K) (scalar cube) surface_altitude 413.93686 m time 2009-09-09 17:10:00 Attributes: - source Iris test case \ No newline at end of file + source 'Iris test case' \ No newline at end of file diff --git a/lib/iris/tests/results/cdm/TestStockCubeStringRepresentations/1d_str.txt b/lib/iris/tests/results/cdm/TestStockCubeStringRepresentations/1d_str.txt index 95f7e7b57e..7d43a997da 100644 --- a/lib/iris/tests/results/cdm/TestStockCubeStringRepresentations/1d_str.txt +++ b/lib/iris/tests/results/cdm/TestStockCubeStringRepresentations/1d_str.txt @@ -13,4 +13,4 @@ air_potential_temperature / (K) (grid_longitude: 100) sigma 0.9994238, bound=(1.0, 0.99846387) time 2009-09-09 17:10:00 Attributes: - source Iris test case \ No newline at end of file + source 'Iris test case' \ No newline at end of file diff --git a/lib/iris/tests/results/cdm/TestStockCubeStringRepresentations/2d_str.txt b/lib/iris/tests/results/cdm/TestStockCubeStringRepresentations/2d_str.txt index c4184d199a..9adeb35c73 100644 --- a/lib/iris/tests/results/cdm/TestStockCubeStringRepresentations/2d_str.txt +++ b/lib/iris/tests/results/cdm/TestStockCubeStringRepresentations/2d_str.txt @@ -13,4 +13,4 @@ air_potential_temperature / (K) (grid_latitude: 100; grid_longitude: 100) sigma 0.9994238, bound=(1.0, 0.99846387) time 2009-09-09 17:10:00 Attributes: - source Iris test case \ No newline at end of file + source 'Iris test case' \ No newline at end of file diff --git a/lib/iris/tests/results/cdm/TestStockCubeStringRepresentations/3d_str.txt b/lib/iris/tests/results/cdm/TestStockCubeStringRepresentations/3d_str.txt index af81d4e991..dc5e71433f 100644 --- a/lib/iris/tests/results/cdm/TestStockCubeStringRepresentations/3d_str.txt +++ b/lib/iris/tests/results/cdm/TestStockCubeStringRepresentations/3d_str.txt @@ -13,4 +13,4 @@ air_potential_temperature / (K) (model_level_number: 70; grid_latitude: 100; forecast_period 0.0 hours time 2009-09-09 17:10:00 Attributes: - source Iris test case \ No newline at end of file + source 'Iris test case' \ No newline at end of file diff --git a/lib/iris/tests/results/cdm/TestStockCubeStringRepresentations/4d_str.txt b/lib/iris/tests/results/cdm/TestStockCubeStringRepresentations/4d_str.txt index afcdedf100..52adc03efb 100644 --- a/lib/iris/tests/results/cdm/TestStockCubeStringRepresentations/4d_str.txt +++ b/lib/iris/tests/results/cdm/TestStockCubeStringRepresentations/4d_str.txt @@ -13,4 +13,4 @@ air_potential_temperature / (K) (time: 6; model_level_number: 70; grid_latit Scalar coordinates: forecast_period 0.0 hours Attributes: - source Iris test case \ No newline at end of file + source 'Iris test case' \ No newline at end of file diff --git a/lib/iris/tests/results/cdm/str_repr/0d_cube.__str__.txt b/lib/iris/tests/results/cdm/str_repr/0d_cube.__str__.txt index 6a3276d861..02e9849d38 100644 --- a/lib/iris/tests/results/cdm/str_repr/0d_cube.__str__.txt +++ b/lib/iris/tests/results/cdm/str_repr/0d_cube.__str__.txt @@ -8,4 +8,4 @@ air_temperature / (K) (scalar cube) time 1998-12-01 00:00:00 Attributes: STASH m01s16i203 - source Data from Met Office Unified Model \ No newline at end of file + source 'Data from Met Office Unified Model' \ No newline at end of file diff --git a/lib/iris/tests/results/cdm/str_repr/0d_cube.__unicode__.txt b/lib/iris/tests/results/cdm/str_repr/0d_cube.__unicode__.txt index 6a3276d861..02e9849d38 100644 --- a/lib/iris/tests/results/cdm/str_repr/0d_cube.__unicode__.txt +++ b/lib/iris/tests/results/cdm/str_repr/0d_cube.__unicode__.txt @@ -8,4 +8,4 @@ air_temperature / (K) (scalar cube) time 1998-12-01 00:00:00 Attributes: STASH m01s16i203 - source Data from Met Office Unified Model \ No newline at end of file + source 'Data from Met Office Unified Model' \ No newline at end of file diff --git a/lib/iris/tests/results/cdm/str_repr/cell_methods.__str__.txt b/lib/iris/tests/results/cdm/str_repr/cell_methods.__str__.txt index ba93542e51..ffb6a62daf 100644 --- a/lib/iris/tests/results/cdm/str_repr/cell_methods.__str__.txt +++ b/lib/iris/tests/results/cdm/str_repr/cell_methods.__str__.txt @@ -14,4 +14,4 @@ air_temperature / (K) (latitude: 73; longitude: 96) percentile longitude (6 minutes, This is another test comment) Attributes: STASH m01s16i203 - source Data from Met Office Unified Model \ No newline at end of file + source 'Data from Met Office Unified Model' \ No newline at end of file diff --git a/lib/iris/tests/results/cdm/str_repr/missing_coords_cube.str.txt b/lib/iris/tests/results/cdm/str_repr/missing_coords_cube.str.txt index 1b86bd6597..0ac5bd3c8a 100644 --- a/lib/iris/tests/results/cdm/str_repr/missing_coords_cube.str.txt +++ b/lib/iris/tests/results/cdm/str_repr/missing_coords_cube.str.txt @@ -11,4 +11,4 @@ air_potential_temperature / (K) (-- : 6; -- : 70; grid_latitude: 100; grid_l Scalar coordinates: forecast_period 0.0 hours Attributes: - source Iris test case \ No newline at end of file + source 'Iris test case' \ No newline at end of file diff --git a/lib/iris/tests/results/cdm/str_repr/similar.__str__.txt b/lib/iris/tests/results/cdm/str_repr/similar.__str__.txt index fc274ed4c1..394e52e5c9 100644 --- a/lib/iris/tests/results/cdm/str_repr/similar.__str__.txt +++ b/lib/iris/tests/results/cdm/str_repr/similar.__str__.txt @@ -15,4 +15,4 @@ air_temperature / (K) (latitude: 73; longitude: 96) time 1998-12-01 00:00:00 Attributes: STASH m01s16i203 - source Data from Met Office Unified Model \ No newline at end of file + source 'Data from Met Office Unified Model' \ No newline at end of file diff --git a/lib/iris/tests/results/cdm/str_repr/unicode_attribute.__unicode__.txt b/lib/iris/tests/results/cdm/str_repr/unicode_attribute.__unicode__.txt index 29c181345c..594ad11688 100644 --- a/lib/iris/tests/results/cdm/str_repr/unicode_attribute.__unicode__.txt +++ b/lib/iris/tests/results/cdm/str_repr/unicode_attribute.__unicode__.txt @@ -2,4 +2,4 @@ thingness / (1) (foo: 11) Dimension coordinates: foo x Attributes: - source ꀀabcd޴ \ No newline at end of file + source 'ꀀabcd\u07b4' \ No newline at end of file diff --git a/lib/iris/tests/results/coord_api/str_repr/aux_nontime_str.txt b/lib/iris/tests/results/coord_api/str_repr/aux_nontime_str.txt index 0361e88eef..3030ea962a 100644 --- a/lib/iris/tests/results/coord_api/str_repr/aux_nontime_str.txt +++ b/lib/iris/tests/results/coord_api/str_repr/aux_nontime_str.txt @@ -11,4 +11,5 @@ DimCoord : level_height / (m) shape: (10,) bounds(10, 2) dtype: float32 long_name: 'level_height' - attributes: {'positive': 'up'} \ No newline at end of file + attributes: + positive 'up' \ No newline at end of file diff --git a/lib/iris/tests/results/derived/no_orog.__str__.txt b/lib/iris/tests/results/derived/no_orog.__str__.txt index e277b5d276..de139592a6 100644 --- a/lib/iris/tests/results/derived/no_orog.__str__.txt +++ b/lib/iris/tests/results/derived/no_orog.__str__.txt @@ -13,4 +13,4 @@ air_potential_temperature / (K) (time: 6; model_level_number: 70; grid_latit Scalar coordinates: forecast_period 0.0 hours Attributes: - source Iris test case \ No newline at end of file + source 'Iris test case' \ No newline at end of file diff --git a/lib/iris/tests/results/derived/removed_orog.__str__.txt b/lib/iris/tests/results/derived/removed_orog.__str__.txt index 0c24cded80..a9ef3bd017 100644 --- a/lib/iris/tests/results/derived/removed_orog.__str__.txt +++ b/lib/iris/tests/results/derived/removed_orog.__str__.txt @@ -12,4 +12,4 @@ air_potential_temperature / (K) (time: 6; model_level_number: 70; grid_latit Scalar coordinates: forecast_period 0.0 hours Attributes: - source Iris test case \ No newline at end of file + source 'Iris test case' \ No newline at end of file diff --git a/lib/iris/tests/results/derived/removed_sigma.__str__.txt b/lib/iris/tests/results/derived/removed_sigma.__str__.txt index 94e850ec62..c3eaf48483 100644 --- a/lib/iris/tests/results/derived/removed_sigma.__str__.txt +++ b/lib/iris/tests/results/derived/removed_sigma.__str__.txt @@ -12,4 +12,4 @@ air_potential_temperature / (K) (time: 6; model_level_number: 70; grid_latit Scalar coordinates: forecast_period 0.0 hours Attributes: - source Iris test case \ No newline at end of file + source 'Iris test case' \ No newline at end of file diff --git a/lib/iris/tests/test_coord_api.py b/lib/iris/tests/test_coord_api.py index 3445b089e8..87270b524c 100644 --- a/lib/iris/tests/test_coord_api.py +++ b/lib/iris/tests/test_coord_api.py @@ -256,7 +256,8 @@ def test_basic(self): " points: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]", " shape: (10,)", " dtype: int64", - " attributes: {'monty': 'python'}", + " attributes:", + " monty 'python'", ] ) self.assertEqual(result, str(b)) @@ -360,7 +361,8 @@ def test_basic(self): " points: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]", " shape: (10,)", " dtype: int64", - " attributes: {'monty': 'python'}", + " attributes:", + " monty 'python'", ] ) self.assertEqual(result, str(b)) diff --git a/lib/iris/tests/unit/coords/test_AncillaryVariable.py b/lib/iris/tests/unit/coords/test_AncillaryVariable.py index 51e070a226..4d520ac414 100644 --- a/lib/iris/tests/unit/coords/test_AncillaryVariable.py +++ b/lib/iris/tests/unit/coords/test_AncillaryVariable.py @@ -442,7 +442,8 @@ def test_non_time_values(self): " standard_name: 'height'", " long_name: 'height of detector'", " var_name: 'height'", - " attributes: {'notes': 'Measured from sea level'}", + " attributes:", + " notes 'Measured from sea level'", ] ) self.assertEqual(expected, ancillary_var.__str__()) diff --git a/lib/iris/tests/unit/coords/test_CellMeasure.py b/lib/iris/tests/unit/coords/test_CellMeasure.py index 873a257c8e..0bd66c6e98 100644 --- a/lib/iris/tests/unit/coords/test_CellMeasure.py +++ b/lib/iris/tests/unit/coords/test_CellMeasure.py @@ -103,7 +103,8 @@ def test___str__(self): " standard_name: 'cell_area'", " long_name: 'measured_area'", " var_name: 'area'", - " attributes: {'notes': '1m accuracy'}", + " attributes:", + " notes '1m accuracy'", " measure: 'area'", ] ) diff --git a/lib/iris/tests/unit/coords/test__DimensionalMetadata.py b/lib/iris/tests/unit/coords/test__DimensionalMetadata.py index d403b6c4e2..22291c4cac 100644 --- a/lib/iris/tests/unit/coords/test__DimensionalMetadata.py +++ b/lib/iris/tests/unit/coords/test__DimensionalMetadata.py @@ -320,8 +320,11 @@ def test_attributes(self): "empty": [], "None": None, "string": "this", - "long_long_long_long_long_long_name": 3, - "other": "long_long_long_long_long_long_value", + "long_long_long_long_long_name": 3, + "other": ( + "long_long_long_long_long_long_long_long_" + "long_long_long_long_long_long_long_long_value" + ), "float": 4.3, } ) @@ -333,15 +336,19 @@ def test_attributes(self): " shape: (5,)", " dtype: float64", " long_name: 'x'", - # At present, some nasty long lines... + " attributes:", + " array [0. 1. 2. 3. 4. 5. 6.]", + " list [1, 2, 3]", + " empty []", + " None None", + " string 'this'", + " long_long_long_long_long_name 3", ( - " attributes: {'array': array([0., 1., 2., 3., 4., 5., " - "6.]), 'list': [1, 2, 3], 'empty': [], " - "'None': None, 'string': 'this', " - "'long_long_long_long_long_long_name': 3, " - "'other': 'long_long_long_long_long_long_value', " - "'float': 4.3}" + " other " + "'long_long_long_long_long_long_long_long_" + "long_long_long_long_long_long..." ), + " float 4.3", ] self.assertLines(expected, result) @@ -920,7 +927,9 @@ def test_meshcoord(self): " dtype: int64", " standard_name: 'longitude'", " long_name: 'long-name'", - " attributes: {'a': 1, 'b': 'c'}", + " attributes:", + " a 1", + " b 'c'", " axis: 'x'", ] self.assertLines(expected, result) diff --git a/lib/iris/tests/unit/experimental/ugrid/mesh/test_Connectivity.py b/lib/iris/tests/unit/experimental/ugrid/mesh/test_Connectivity.py index c0117ffc79..b452a8a87c 100644 --- a/lib/iris/tests/unit/experimental/ugrid/mesh/test_Connectivity.py +++ b/lib/iris/tests/unit/experimental/ugrid/mesh/test_Connectivity.py @@ -107,7 +107,8 @@ def test___str__(self): " dtype: int64", " long_name: 'my_face_nodes'", " var_name: 'face_nodes'", - " attributes: {'notes': 'this is a test'}", + " attributes:", + " notes 'this is a test'", " cf_role: 'face_node_connectivity'", " start_index: 1", " src_dim: 1", diff --git a/lib/iris/tests/unit/experimental/ugrid/mesh/test_Mesh.py b/lib/iris/tests/unit/experimental/ugrid/mesh/test_Mesh.py index 1df67deb66..fd84c13668 100644 --- a/lib/iris/tests/unit/experimental/ugrid/mesh/test_Mesh.py +++ b/lib/iris/tests/unit/experimental/ugrid/mesh/test_Mesh.py @@ -129,7 +129,8 @@ def test___str__(self): " ", " long_name: 'my_topology_mesh'", " var_name: 'mesh'", - " attributes: {'notes': 'this is a test'}", + " attributes:", + " notes 'this is a test'", ] self.assertEqual(expected, str(self.mesh).split("\n")) @@ -427,7 +428,8 @@ def test___str__(self): ), " long_name: 'my_topology_mesh'", " var_name: 'mesh'", - " attributes: {'notes': 'this is a test'}", + " attributes:", + " notes 'this is a test'", ] self.assertEqual(expected, str(self.mesh).split("\n")) @@ -474,7 +476,8 @@ def test___str__noedgecoords(self): ), " long_name: 'my_topology_mesh'", " var_name: 'mesh'", - " attributes: {'notes': 'this is a test'}", + " attributes:", + " notes 'this is a test'", ] self.assertEqual(expected, str(alt_mesh).split("\n")) @@ -696,6 +699,19 @@ def test___str__emptyattributes(self): self.mesh.attributes.clear() self.assertNotIn("attributes", str(self.mesh)) + def test__str__longstringattribute(self): + self.mesh.attributes["long_string"] = ( + "long_x_10_long_x_20_long_x_30_long_x_40_" + "long_x_50_long_x_60_long_x_70_long_x_80_" + ) + result = str(self.mesh) + # Note: initial single-quote, but no final one : this is correct ! + expected = ( + "'long_x_10_long_x_20_long_x_30_long_x_40_" + "long_x_50_long_x_60_long_x_70..." + ) + self.assertIn(expected + ":END", result + ":END") + def test___str__units_stdname(self): # These are usually missing, but they *can* be present. mesh_kwargs = self.kwargs.copy() @@ -713,7 +729,8 @@ def test___str__units_stdname(self): " long_name: 'my_topology_mesh'", " var_name: 'mesh'", " units: Unit('m')", - " attributes: {'notes': 'this is a test'}", + " attributes:", + " notes 'this is a test'", ] ) self.assertTrue(result.endswith(expected)) diff --git a/lib/iris/tests/unit/experimental/ugrid/mesh/test_MeshCoord.py b/lib/iris/tests/unit/experimental/ugrid/mesh/test_MeshCoord.py index 8c2e652c31..15db8b8d74 100644 --- a/lib/iris/tests/unit/experimental/ugrid/mesh/test_MeshCoord.py +++ b/lib/iris/tests/unit/experimental/ugrid/mesh/test_MeshCoord.py @@ -300,7 +300,8 @@ def _expected_elements_regexp( if not matched_any_upto: regexp += ".*" matched_any_upto = True - regexp += "attributes: {[^}]*}\n *" + # match 'attributes:' followed by N*lines with larger indent + regexp += "attributes:(\n [^ \n]+ +[^ \n]+)+\n " # After those items, expect 'axis' next # N.B. this FAILS if we had attributes when we didn't expect them regexp += f"axis: '{axis}'$" # N.B. this is always the end diff --git a/lib/iris/tests/unit/representation/cube_printout/test_CubePrintout.py b/lib/iris/tests/unit/representation/cube_printout/test_CubePrintout.py index 8370c719f0..40a932b9e0 100644 --- a/lib/iris/tests/unit/representation/cube_printout/test_CubePrintout.py +++ b/lib/iris/tests/unit/representation/cube_printout/test_CubePrintout.py @@ -142,7 +142,7 @@ def test_columns_long_attribute(self): " Attributes:", ( " very_very_very_very_very_long_name " - "longish string extends beyond dim columns" + "'longish string extends beyond dim columns'" ), ] self.assertEqual(rep, expected) @@ -442,7 +442,7 @@ def test_section_cube_attributes(self): " Attributes:", " list [3]", " number 1.2", - " string four five in a string", + " string 'four five in a string'", " z_tupular (6, (7, 8))", ] self.assertEqual(rep, expected) @@ -464,7 +464,7 @@ def test_section_cube_attributes__string_extras(self): " Attributes:", " escaped 'escaped\\tstring'", ( - " long this is very very very " + " long 'this is very very very " "very very very very very very very very very very..." ), ( diff --git a/lib/iris/tests/unit/representation/cube_summary/test_CubeSummary.py b/lib/iris/tests/unit/representation/cube_summary/test_CubeSummary.py index c8af3437e6..3e411c020d 100644 --- a/lib/iris/tests/unit/representation/cube_summary/test_CubeSummary.py +++ b/lib/iris/tests/unit/representation/cube_summary/test_CubeSummary.py @@ -183,7 +183,11 @@ def test_attributes(self): attribute_section = rep.scalar_sections["Attributes:"] attribute_contents = attribute_section.contents - expected_contents = ["a: 1", "b: two", "c: ' this \\n that\\tand.'"] + expected_contents = [ + "a: 1", + "b: 'two'", + "c: ' this \\n that\\tand.'", + ] # Note: a string with \n or \t in it gets "repr-d". # Other strings don't (though in coord 'extra' lines, they do.)