diff --git a/lib/iris/tests/__init__.py b/lib/iris/tests/__init__.py index 5d76746c5b..e97a3d7781 100644 --- a/lib/iris/tests/__init__.py +++ b/lib/iris/tests/__init__.py @@ -45,6 +45,7 @@ import logging import os import os.path +import re import shutil import subprocess import sys @@ -205,6 +206,19 @@ def setUpClass(cls): iris.site_configuration['cf_profile'] = None def _assert_str_same(self, reference_str, test_str, reference_filename, type_comparison_name='Strings'): + # Work around to deal with alterations to attribute typing in + # netcdf4python, introduced in 1.1 and present in 1.2. see: + # https://github.com/Unidata/netcdf-c/issues/298 + # https://github.com/Unidata/netcdf4-python/issues/529 + # https://github.com/Unidata/netcdf4-python/issues/575 + # amongst others for further details. + if type_comparison_name == 'CDL' and reference_str != test_str: + # Match where a new line contains only: + # tab|tab|string |attr_definition. + pattern = re.compile('(^\t\t)string (.+)$', re.MULTILINE) + # Replace with tab|tab|attr_definition. + replacement = r'\t\t\2' + test_str = re.sub(pattern, replacement, test_str) if reference_str != test_str: diff = ''.join(difflib.unified_diff(reference_str.splitlines(1), test_str.splitlines(1), 'Reference', 'Test result', '', '', 0))