Beispiel #1
0
 def test_wrong_input_type_scalar(self):
     ds, _, _ = datasets_grid_metric("C")
     grid = Grid(ds)
     msg = "All data arguments must be either a DataArray or Dictionary .*?"
     with pytest.raises(
             TypeError,
             match=msg,
     ):
         grid.apply_as_grid_ufunc(lambda x: x, "not_a_dataarray", "X")
Beispiel #2
0
 def test_wrong_axis_vector_input_axis(self):
     ds, _, _ = datasets_grid_metric("C")
     grid = Grid(ds)
     msg = "Vector component with unknown axis provided. Grid has axes .*?"
     with pytest.raises(
             ValueError,
             match=msg,
     ):
         grid.apply_as_grid_ufunc(lambda x: x, {"wrong": xr.DataArray()},
                                  "X")
Beispiel #3
0
 def test_wrong_input_type_vector(self):
     ds, _, _ = datasets_grid_metric("C")
     grid = Grid(ds)
     msg = "Dictionary inputs must have a DataArray as value. Got .*?"
     with pytest.raises(
             TypeError,
             match=msg,
     ):
         grid.apply_as_grid_ufunc(lambda x: x, {"X": "not_a_dataarray"},
                                  "X")
Beispiel #4
0
 def test_multiple_keys_vector_input(self):
     ds, _, _ = datasets_grid_metric("C")
     grid = Grid(ds)
     msg = "Vector components provided as dictionaries should contain exactly one key/value pair. .*?"
     with pytest.raises(
             ValueError,
             match=msg,
     ):
         grid.apply_as_grid_ufunc(lambda x: x, {
             "X": xr.DataArray(),
             "Y": xr.DataArray()
         }, "X")
Beispiel #5
0
 def test_wrong_axis_vector_input_axis_multi_input(self):
     ds, _, _ = datasets_grid_metric("C")
     grid = Grid(ds)
     msg = "Vector component with unknown axis provided. Grid has axes .*?"
     with pytest.raises(
             ValueError,
             match=msg,
     ):
         # Passing 3 args and 2 other components should fail.
         grid.apply_as_grid_ufunc(
             lambda x: x,
             {"X": xr.DataArray()},
             {"Y": xr.DataArray()},
             axis="X",
             other_component=[{
                 "wrong": xr.DataArray()
             }, {
                 "Y": xr.DataArray()
             }],
         )
Beispiel #6
0
 def test_wrong_input_type_vector_multi_input(self):
     ds, _, _ = datasets_grid_metric("C")
     grid = Grid(ds)
     msg = "Dictionary inputs must have a DataArray as value. Got .*?"
     with pytest.raises(
             TypeError,
             match=msg,
     ):
         # Passing 3 args and 2 other components should fail.
         grid.apply_as_grid_ufunc(
             lambda x: x,
             {"X": xr.DataArray()},
             {"Y": "not_a_data_array"},
             axis="X",
             other_component=[{
                 "X": xr.DataArray()
             }, {
                 "Y": xr.DataArray()
             }],
         )
Beispiel #7
0
 def test_vector_input_data_other_mismatch(self):
     ds, _, _ = datasets_grid_metric("C")
     grid = Grid(ds)
     msg = ("When providing multiple input arguments, `other_component`"
            " needs to provide one dictionary per input")
     with pytest.raises(
             ValueError,
             match=msg,
     ):
         # Passing 3 args and 2 other components should fail.
         grid.apply_as_grid_ufunc(
             lambda x: x,
             {"X": xr.DataArray()},
             {"Y": xr.DataArray()},
             {"Z": xr.DataArray()},
             axis="X",
             other_component=[{
                 "X": xr.DataArray()
             }, {
                 "Y": xr.DataArray()
             }],
         )