def test_perturb_1channel(self) -> None:
     """
     Test basic perturbation on a known image with even windowing + stride.
     """
     impl = SlidingWindowPerturb(window_size=(2, 2), stride=(2, 2))
     # Image is slightly wide, should be occluded 6-ways.
     white_image = PIL.Image.fromarray(
         np.full((4, 6), fill_value=255, dtype=np.uint8)
     )
     assert white_image.mode == "L"
     pert_imgs, pert_masks = impl.perturb(white_image)
     assert len(pert_imgs) == 6
     assert len(pert_masks) == 6
     assert np.allclose(pert_masks, EXPECTED_MASKS_4x6)
     # Output image modes should match input
     for i, img in enumerate(pert_imgs):
         assert img.mode == "L"
     # Test for expected output perturbed image content
     assert np.allclose(
         np.asarray(pert_imgs[0]),
         np.vstack([
             np.hstack([BLACK_2x2_L, WHITE_2x2_L, WHITE_2x2_L]),
             np.hstack([WHITE_2x2_L, WHITE_2x2_L, WHITE_2x2_L]),
         ])
     )
     assert np.allclose(
         np.asarray(pert_imgs[1]),
         np.vstack([
             np.hstack([WHITE_2x2_L, BLACK_2x2_L, WHITE_2x2_L]),
             np.hstack([WHITE_2x2_L, WHITE_2x2_L, WHITE_2x2_L]),
         ])
     )
     assert np.allclose(
         np.asarray(pert_imgs[2]),
         np.vstack([
             np.hstack([WHITE_2x2_L, WHITE_2x2_L, BLACK_2x2_L]),
             np.hstack([WHITE_2x2_L, WHITE_2x2_L, WHITE_2x2_L]),
         ])
     )
     assert np.allclose(
         np.asarray(pert_imgs[3]),
         np.vstack([
             np.hstack([WHITE_2x2_L, WHITE_2x2_L, WHITE_2x2_L]),
             np.hstack([BLACK_2x2_L, WHITE_2x2_L, WHITE_2x2_L]),
         ])
     )
     assert np.allclose(
         np.asarray(pert_imgs[4]),
         np.vstack([
             np.hstack([WHITE_2x2_L, WHITE_2x2_L, WHITE_2x2_L]),
             np.hstack([WHITE_2x2_L, BLACK_2x2_L, WHITE_2x2_L]),
         ])
     )
     assert np.allclose(
         np.asarray(pert_imgs[5]),
         np.vstack([
             np.hstack([WHITE_2x2_L, WHITE_2x2_L, WHITE_2x2_L]),
             np.hstack([WHITE_2x2_L, WHITE_2x2_L, BLACK_2x2_L]),
         ])
     )
 def test_standard_config(self) -> None:
     ex_w = (777, 776)
     ex_s = (444, 445)
     impl = SlidingWindowPerturb(window_size=ex_w, stride=ex_s)
     for inst in configuration_test_helper(impl):
         assert inst.window_size == ex_w
         assert inst.stride == ex_s
 def test_init_default(self) -> None:
     """
     Test empty construction since we provide defaults.
     """
     impl = SlidingWindowPerturb()
     assert impl.window_size == (50, 50)
     assert impl.stride == (20, 20)
 def test_init_valued(self) -> None:
     """
     Test that constructor values pass.
     """
     ex_w = (777, 776)
     ex_s = (444, 445)
     impl = SlidingWindowPerturb(window_size=ex_w, stride=ex_s)
     assert impl.window_size == ex_w
     assert impl.stride == ex_s