Skip to content

Commit

Permalink
move _translate_constraints_to_var_callback to private function
Browse files Browse the repository at this point in the history
  • Loading branch information
lbdreyer committed Aug 10, 2021
1 parent 15ecb49 commit 58399fd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions lib/iris/fileformats/netcdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ def coord_from_term(term):
cube.add_aux_factory(factory)


def translate_constraints_to_var_callback(constraints):
def _translate_constraints_to_var_callback(constraints):
"""
Translate load constraints into a simple data-var filter function, if possible.
Expand Down Expand Up @@ -822,7 +822,7 @@ def load_cubes(filenames, callback=None, constraints=None):
from iris.io import run_callback

# Create a low-level data-var filter from the original load constraints, if they are suitable.
var_callback = translate_constraints_to_var_callback(constraints)
var_callback = _translate_constraints_to_var_callback(constraints)

# Create an actions engine.
engine = _actions_engine()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
# licensing details.
"""
Unit tests for
:func:`iris.fileformats.netcdf.translate_constraints_to_var_callback`.
:func:`iris.fileformats.netcdf._translate_constraints_to_var_callback`.
"""

from unittest.mock import Mock

import iris
from iris.fileformats.netcdf import translate_constraints_to_var_callback
from iris.fileformats.netcdf import _translate_constraints_to_var_callback

# import iris tests first so that some things can be initialised before
# importing anything else
Expand All @@ -36,44 +36,44 @@ def test_multiple_constraints(self):
iris.NameConstraint(standard_name="x_wind"),
iris.NameConstraint(var_name="var1"),
]
result = translate_constraints_to_var_callback(constrs)
result = _translate_constraints_to_var_callback(constrs)
self.assertIsNone(result)

def test_non_NameConstraint(self):
constr = iris.AttributeConstraint(STASH="m01s00i002")
result = translate_constraints_to_var_callback(constr)
result = _translate_constraints_to_var_callback(constr)
self.assertIsNone(result)

def test_str_constraint(self):
result = translate_constraints_to_var_callback("x_wind")
result = _translate_constraints_to_var_callback("x_wind")
self.assertIsNone(result)

def test_Constaint_with_name(self):
constr = iris.Constraint(name="x_wind")
result = translate_constraints_to_var_callback(constr)
result = _translate_constraints_to_var_callback(constr)
self.assertIsNone(result)

def test_NameConstraint_standard_name(self):
constr = iris.NameConstraint(standard_name="x_wind")
callback = translate_constraints_to_var_callback(constr)
callback = _translate_constraints_to_var_callback(constr)
result = [callback(var) for var in self.data_variables]
self.assertArrayEqual(result, [True, False, False, True])

def test_NameConstraint_long_name(self):
constr = iris.NameConstraint(long_name="x component of wind")
callback = translate_constraints_to_var_callback(constr)
callback = _translate_constraints_to_var_callback(constr)
result = [callback(var) for var in self.data_variables]
self.assertArrayEqual(result, [False, False, True, True])

def test_NameConstraint_var_name(self):
constr = iris.NameConstraint(var_name="var1")
callback = translate_constraints_to_var_callback(constr)
callback = _translate_constraints_to_var_callback(constr)
result = [callback(var) for var in self.data_variables]
self.assertArrayEqual(result, [True, False, True, True])

def test_NameConstraint_standard_name_var_name(self):
constr = iris.NameConstraint(standard_name="x_wind", var_name="var1")
callback = translate_constraints_to_var_callback(constr)
callback = _translate_constraints_to_var_callback(constr)
result = [callback(var) for var in self.data_variables]
self.assertArrayEqual(result, [True, False, False, True])

Expand All @@ -83,15 +83,15 @@ def test_NameConstraint_standard_name_long_name_var_name(self):
long_name="x component of wind",
var_name="var1",
)
callback = translate_constraints_to_var_callback(constr)
callback = _translate_constraints_to_var_callback(constr)
result = [callback(var) for var in self.data_variables]
self.assertArrayEqual(result, [False, False, False, True])

def test_NameConstraint_with_STASH(self):
constr = iris.NameConstraint(
standard_name="x_wind", STASH="m01s00i024"
)
result = translate_constraints_to_var_callback(constr)
result = _translate_constraints_to_var_callback(constr)
self.assertIsNone(result)


Expand Down

0 comments on commit 58399fd

Please sign in to comment.