def test_crop_to_box():
    # create 1000 by 1000 test array
    arr = np.zeros(1000 * 1000).reshape([1000, 1000])
    box = chop.crop_to_box(x=50, y=50, img=arr, size=10, edge="keep")
    assert isinstance(box, np.ndarray)
    assert box.shape == (10, 10)
    assert np.zeros(100).reshape([10, 10]).all() == 0
def test_crop_to_box_error_size():
    arr = np.zeros(1000 * 1000).reshape([1000, 1000])
    with pytest.raises(ValueError):
        chop.crop_to_box(500, 500, arr, size=10.2)
    with pytest.raises(ValueError):
        chop.crop_to_box(500, 500, arr, size=-10)
    with pytest.raises(ValueError):
        chop.crop_to_box(500, 500, arr, size=15)
def test_crop_to_box_error_size_too_large():
    with pytest.raises(ValueError):
        arr = np.zeros(100 * 100).reshape([100, 100])
        chop.crop_to_box(x=50, y=50, img=arr, size=200)
def test_crop_to_box_error_edge():
    with pytest.raises(ValueError):
        arr = np.zeros(1000 * 1000).reshape([1000, 1000])
        chop.crop_to_box(x=500, y=500, img=arr, size=10, edge="error")
def test_crop_to_box_remove():
    arr = np.zeros(1000 * 1000).reshape([1000, 1000])
    box = chop.crop_to_box(x=4, y=5, img=arr, size=10, edge="remove")
    assert box is None
def test_crop_to_box_on_edge():
    arr = np.zeros(1000 * 1000).reshape([1000, 1000])
    box = chop.crop_to_box(x=995, y=5, img=arr, size=10, edge="keep")
    assert isinstance(box, np.ndarray)
    assert box.shape == (10, 10)
    assert np.zeros(100).reshape([10, 10]).all() == 0