From 249bdb63ed2ad9b30cd21bcdc58746bc12b7c218 Mon Sep 17 00:00:00 2001 From: Patrick Peglar Date: Sun, 30 Jul 2023 23:15:10 +0100 Subject: [PATCH 1/2] Make roundtrip checking more precise + improve some tests accordingly. --- .../integration/test_netcdf__loadsaveattrs.py | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/lib/iris/tests/integration/test_netcdf__loadsaveattrs.py b/lib/iris/tests/integration/test_netcdf__loadsaveattrs.py index 77eb3e5324..e432b238b5 100644 --- a/lib/iris/tests/integration/test_netcdf__loadsaveattrs.py +++ b/lib/iris/tests/integration/test_netcdf__loadsaveattrs.py @@ -39,6 +39,7 @@ # A list of "global-style" attribute names : those which should be global attributes by # default (i.e. file- or group-level, *not* attached to a variable). + _GLOBAL_TEST_ATTRS = set(iris.fileformats.netcdf.saver._CF_GLOBAL_ATTRS) # Remove this one, which has peculiar behaviour + is tested separately # N.B. this is not the same as 'Conventions', but is caught in the crossfire when that @@ -263,16 +264,15 @@ def check_roundtrip_results( else: assert self.attrname in ds.ncattrs() assert ds.getncattr(self.attrname) == global_attr_value - if var_attr_vals: - var_attr_vals = self._default_vars_and_attrvalues(var_attr_vals) - for var_name, value in var_attr_vals.items(): - assert var_name in ds.variables - v = ds.variables[var_name] - if value is None: - assert self.attrname not in v.ncattrs() - else: - assert self.attrname in v.ncattrs() - assert v.getncattr(self.attrname) == value + var_attr_vals = self._default_vars_and_attrvalues(var_attr_vals) + for var_name, value in var_attr_vals.items(): + assert var_name in ds.variables + v = ds.variables[var_name] + if value is None: + assert self.attrname not in v.ncattrs() + else: + assert self.attrname in v.ncattrs() + assert v.getncattr(self.attrname) == value ####################################################### # Tests on "user-style" attributes. @@ -302,7 +302,7 @@ def test_02_userstyle_single_local(self): # It results in a "promoted" global attribute. self.create_roundtrip_testcase( attr_name="myname", # A generic "user" attribute with no special handling - vars_values_file1={"myvar": "single-value"}, + vars_values_file1="single-value", ) self.check_roundtrip_results( global_attr_value="single-value", # local values eclipse the global ones @@ -545,10 +545,12 @@ def test_16_localstyle(self, local_attr, origin_style): attr_name=local_attr, vars_values_file1=attrval ) - if local_attr in iris.fileformats.netcdf.saver._CF_DATA_ATTRS: - # These ones are simply discarded on loading. - # By experiment, this overlap between _CF_ATTRS and _CF_DATA_ATTRS - # currently contains only 'missing_value' and 'standard_error_multiplier'. + if ( + local_attr in ('missing_value', 'standard_error_multiplier') + and origin_style == "input_local" + ): + # These ones are actually discarded by roundtrip. + # Not clear why, but for now this captures the facts. expect_global = None expect_var = None else: From f85975472d09ed828981068f3a653b57dbe86b7d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 30 Jul 2023 23:11:46 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- lib/iris/tests/integration/test_netcdf__loadsaveattrs.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/iris/tests/integration/test_netcdf__loadsaveattrs.py b/lib/iris/tests/integration/test_netcdf__loadsaveattrs.py index e432b238b5..14d7f2fadf 100644 --- a/lib/iris/tests/integration/test_netcdf__loadsaveattrs.py +++ b/lib/iris/tests/integration/test_netcdf__loadsaveattrs.py @@ -546,8 +546,8 @@ def test_16_localstyle(self, local_attr, origin_style): ) if ( - local_attr in ('missing_value', 'standard_error_multiplier') - and origin_style == "input_local" + local_attr in ("missing_value", "standard_error_multiplier") + and origin_style == "input_local" ): # These ones are actually discarded by roundtrip. # Not clear why, but for now this captures the facts.