Esempio n. 1
0
    def test_size(self, small_cont: ImageContainer,
                  dy: Optional[Union[int, float]], dx: Optional[Union[int,
                                                                      float]]):
        res = process(small_cont, method="smooth", copy=True)
        key = Key.img.process("smooth", "image")

        assert res.shape == small_cont.shape
        np.testing.assert_array_equal(res[key].dims, small_cont["image"].dims)
Esempio n. 2
0
    def test_key_added(self, small_cont: ImageContainer,
                       key_added: Optional[str]):
        res = process(small_cont,
                      method="smooth",
                      copy=False,
                      layer_added=key_added,
                      layer="image")

        assert res is None
        assert Key.img.process("smooth", "image", layer_added=key_added)
Esempio n. 3
0
    def test_passing_kwargs(self, small_cont: ImageContainer):
        def dummy(arr: np.ndarray, sentinel: bool = False) -> np.ndarray:
            assert sentinel, "Sentinel not set."
            return arr

        res = process(small_cont, method=dummy, sentinel=True)
        key = Key.img.process(dummy, "image")

        assert res is None
        np.testing.assert_array_equal(small_cont[key].values,
                                      small_cont["image"].values)
Esempio n. 4
0
    def test_method(self, small_cont: ImageContainer,
                    method: Union[str, Callable[[np.ndarray], np.ndarray]]):
        res = process(small_cont, method=method, copy=True)
        key = Key.img.process(method, "image")

        assert isinstance(res, ImageContainer)
        assert key in res
        if callable(method):
            np.testing.assert_array_equal(small_cont["image"].values,
                                          res[key].values)
        else:
            assert not np.all(
                np.allclose(small_cont["image"].values, res[key].values))
Esempio n. 5
0
    def test_channel_dim(self, small_cont: ImageContainer,
                         method: Union[str, Callable[[np.ndarray],
                                                     np.ndarray]]):
        res = process(small_cont, method=method, copy=True, channel_dim="foo")
        key = Key.img.process(method, "image")

        assert isinstance(res, ImageContainer)

        if method == "smooth":
            np.testing.assert_array_equal(res[key].dims, ["y", "x", "foo"])
        else:
            modifier = "_".join(key.split("_")[1:])  # will be e.g `foo_smooth`
            np.testing.assert_array_equal(res[key].dims,
                                          ["y", "x", f"foo_{modifier}"])
Esempio n. 6
0
    def test_copy(self, small_cont: ImageContainer):
        orig_keys = set(small_cont)
        res = process(small_cont, method="smooth", copy=True)

        assert isinstance(res, ImageContainer)
        assert set(small_cont) == orig_keys
Esempio n. 7
0
 def test_gray_not_rgb(self, small_cont_1c: ImageContainer):
     with pytest.raises(
             ValueError,
             match=r"Expected channel dimension to be `3`, found `1`."):
         process(small_cont_1c, method="gray")
Esempio n. 8
0
 def test_invalid_layer(self, small_cont: ImageContainer):
     with pytest.raises(KeyError,
                        match=r"Image layer `foobar` not found in"):
         process(small_cont, layer="foobar")