def test_equivalent(self): sig1 = _GridUFuncSignature.from_string("(X:center)->(X:left)") sig2 = _GridUFuncSignature.from_string("(X:center)->(X:left)") assert sig1.equivalent(sig2) sig3 = _GridUFuncSignature.from_string("(Y:center)->(Y:left)") assert sig1.equivalent(sig3)
def test_select_ufunc_equivalent_signature(self): gridufunc, _ = _select_grid_ufunc( "diff", _GridUFuncSignature.from_string("(Y:center)->(Y:left)"), module=GridOpsMockUp, ) assert gridufunc is GridOpsMockUp.diff_center_to_left with pytest.raises(NotImplementedError): _select_grid_ufunc( "diff", _GridUFuncSignature.from_string("(X:center)->(Y:left)"), module=GridOpsMockUp, )
def test_select_ufunc_by_kwarg(self): gridufunc, _ = _select_grid_ufunc( "diff", _GridUFuncSignature.from_string("(X:center)->(X:right)"), module=GridOpsMockUp, boundary="fill", ) assert gridufunc is GridOpsMockUp.diff_center_to_right_fill with pytest.raises(NotImplementedError): _select_grid_ufunc( "diff", _GridUFuncSignature.from_string("(X:center)->(X:right)"), module=GridOpsMockUp, boundary="nonsense", )
def test_select_ufunc_wrong_signature(self): with pytest.raises(NotImplementedError): _select_grid_ufunc( "diff", _GridUFuncSignature.from_string("(X:center)->(X:center)"), module=GridOpsMockUp, )
def test_select_ufunc(self): gridufunc, _ = _select_grid_ufunc( "diff", _GridUFuncSignature.from_string("(X:center)->(X:left)"), module=GridOpsMockUp, ) assert gridufunc is GridOpsMockUp.diff_center_to_left
def test_pass_through_other_kwargs(self): # TODO put this in test_grid.py instead? gridufunc, _ = _select_grid_ufunc( "pass", _GridUFuncSignature.from_string("()->()"), module=GridOpsMockUp, boundary="fill", ) assert gridufunc(a=1) == {"a": 1}
def test_roundtrip_from_string(self, sig_str): """Checks that the __str__ method of the signature class works""" sig = _GridUFuncSignature.from_string(sig_str) assert str(sig) == sig_str
def test_no_indices(self): sig = _GridUFuncSignature.from_string("()->()") assert sig.equivalent(sig)