Ejemplo n.º 1
0
def test_same_size():
    # Checking input and output size
    input_img = "test_img/test_original.jpg"
    greenscale(input_img)
    input_img = skimage.io.imread('test_img/test_original.jpg')
    output_img = skimage.io.imread('test_img/gs_test_original.jpg')
    assert input_img.shape == output_img.shape, "Input and output dimensions do not match"
Ejemplo n.º 2
0
def check_output_type():
    input_img = "test_img/test_original.jpg"
    greenscale(input_img)
    input_img = skimage.io.imread('test_img/test_original.jpg')
    output_img = skimage.io.imread('test_img/gs_test_original.jpg')
    assert imghdr.what(output_img) in [
        'png', 'jpeg', 'gif', 'bmp', 'jpg'
    ] and imghdr.what(output_img) == imghdr.what(
        input_img), "The output image has a different file formatest_img"
Ejemplo n.º 3
0
def test_greenscale_black():
    # Black image testing
    test_img_black = np.array([[[0, 0, 0]]], dtype="uint8")
    gs_test_img_black = np.array([[[0, 0, 0]]], dtype="uint8")

    greenscale("test_img/test_img_black.jpeg")
    output_expected = skimage.io.imread("test_img/test_img_black.jpeg")
    assert np.array_equal(
        output_expected,
        gs_test_img_black), "The greenscale function does not work properly."
Ejemplo n.º 4
0
def test_greenscale_white():
    # White image testing
    test_img = np.array([[[255, 255, 255], [255, 255, 255], [255, 255, 255]],
                         [[255, 255, 255], [255, 255, 255], [255, 255, 255]],
                         [[255, 255, 255], [255, 255, 255], [255, 255, 255]],
                         [[255, 255, 255], [255, 255, 255], [255, 255, 255]],
                         [[255, 255, 255], [255, 255, 255], [255, 255, 255]]],
                        dtype="uint8")
    gs_test_img = np.array([[[0, 230, 0], [0, 230, 0], [0, 230, 0]],
                            [[0, 230, 0], [0, 230, 0], [0, 230, 0]],
                            [[0, 230, 0], [0, 230, 0], [0, 230, 0]],
                            [[0, 230, 0], [0, 230, 0], [0, 230, 0]],
                            [[0, 230, 0], [0, 230, 0], [0, 230, 0]]],
                           dtype="uint8")

    greenscale("test_img/test_img.png")
    output_expected = skimage.io.imread("test_img/gs_test_img.png")
    assert np.array_equal(
        output_expected,
        gs_test_img), "The greenscale function does not work properly."
Ejemplo n.º 5
0
def test_invalid_input_type_error():
    with pytest.raises(FileNotFoundError):
        greenscale("Hi")
Ejemplo n.º 6
0
def test_invalid_input():
    with pytest.raises(AttributeError):
        greenscale(123)
Ejemplo n.º 7
0
def test_input_img():
    input_img = "test_img/test_original.jpg"
    greenscale(input_img)
    with pytest.raises(FileNotFoundError):
        greenscale("not a file path")