diff --git a/test_ncattrs.py b/test_ncattrs.py index 434ad284c5..6bcf105e17 100644 --- a/test_ncattrs.py +++ b/test_ncattrs.py @@ -93,8 +93,10 @@ def local_attr(request): def test_support(): raise ValueError("iris.FUTURE = " + str(iris.FUTURE)) + _SKIP_WARNCHECK = "_no_warnings_check" + def check_captured_warnings( expected_keys: List[str], captured_warnings: List[warnings.WarningMessage] ): @@ -483,9 +485,14 @@ def fetch_results( _MATRIX_ATTRNAMES = _LOCAL_TEST_ATTRS + list(_GLOBAL_TEST_ATTRS) + ["user"] # remove special-cases, for now _SPECIAL_ATTRS = [ - 'Conventions', "ukmo__process_flags", "missing_value", "standard_error_multiplier" + "Conventions", + "ukmo__process_flags", + "missing_value", + "standard_error_multiplier", +] +_MATRIX_ATTRNAMES = [ + attr for attr in _MATRIX_ATTRNAMES if not attr in _SPECIAL_ATTRS ] -_MATRIX_ATTRNAMES = [attr for attr in _MATRIX_ATTRNAMES if not attr in _SPECIAL_ATTRS] # @@ -493,6 +500,8 @@ def fetch_results( # Possible ones are "globalstyle", "localstyle", "userstyle". # _ATTR_STYLES = ["localstyle", "globalstyle", "userstyle"] + + def deduce_attr_style(attrname: str) -> str: # Extract the attribute "style type" from an attr_param name if attrname in _LOCAL_TEST_ATTRS: @@ -504,31 +513,30 @@ def deduce_attr_style(attrname: str) -> str: style = "userstyle" return style + # # Decode a matrix "input spec" to codes for global + local values. # + def decode_matrix_input(input_spec): def decode_specstring(spec: str) -> List[Union[str, None]]: # Decode an input spec-string to input/output attribute values assert spec[0] == "G" and spec[2] == "L" global_val = spec[1] allvals = spec[1] + spec[3:] - result = [ - None if valchar == '-' else valchar - for valchar in allvals - ] + result = [None if valchar == "-" else valchar for valchar in allvals] return result if isinstance(input_spec, str): # Single-source spec (one cube or one file) gA, vA = decode_specstring(input_spec) - result = [[gA, vA ]] + result = [[gA, vA]] else: # Dual-source spec (two files, or sets of cubes with common global) gA, vA = decode_specstring(input_spec[0]) gB, vB = decode_specstring(input_spec[1]) - result = [[gA, vA ], [gB, vB]] + result = [[gA, vA], [gB, vB]] return result @@ -539,17 +547,14 @@ def encode_matrix_result(results: List[List[str]]): if isinstance(results[0], str): results = [results] assert all( - all( - val is None or len(val) == 1 - for val in vals - ) - for vals in results + all(val is None or len(val) == 1 for val in vals) for vals in results ) + def valrep(val): return "-" if val is None else val + return list( - ''.join(['G', valrep(vals[0]), 'L'] - + list(map(valrep, vals[1:]))) + "".join(["G", valrep(vals[0]), "L"] + list(map(valrep, vals[1:]))) for vals in results ) @@ -559,6 +564,7 @@ def valrep(val): # We have the technology to save the found results also. # + @pytest.fixture(autouse=True, scope="session") def matrix_results(): matrix_filepath = Path(__file__).parent / "_testattrs_matrix_results.json" @@ -570,11 +576,11 @@ def matrix_results(): else: # Initialise empty matrix results content matrix_results = {} - for testtype in ('load', 'save', 'roundtrip'): + for testtype in ("load", "save", "roundtrip"): test_specs = matrix_results.setdefault(testtype, {}) for testcase in _MATRIX_TESTCASES: test_case_spec = test_specs.setdefault(testcase, {}) - test_case_spec['input'] = _MATRIX_TESTCASE_INPUTS[testcase] + test_case_spec["input"] = _MATRIX_TESTCASE_INPUTS[testcase] for attrstyle in _ATTR_STYLES: test_case_spec[attrstyle] = None # empty @@ -585,7 +591,6 @@ def matrix_results(): json.dump(matrix_results, matrix_filepath) - class TestRoundtrip(MixinAttrsTesting): """ Test handling of attributes in roundtrip netcdf-iris-netcdf. @@ -963,8 +968,8 @@ def test_16_localstyle(self, local_attr, origin_style, do_split): @pytest.mark.parametrize("attrname", _MATRIX_ATTRNAMES) def test_matrix(self, testcase, attrname, matrix_results): do_saves, matrix_results = matrix_results - test_spec = matrix_results['roundtrip'][testcase] - input_spec = test_spec['input'] + test_spec = matrix_results["roundtrip"][testcase] + input_spec = test_spec["input"] values = decode_matrix_input(input_spec) self.run_roundtrip_testcase(attrname, values)