示例#1
0
def test_cannot_create_graypixel_without_proper_types(pixel_value):
    with pytest.raises(TypeError):
        GrayPixel(value=pixel_value)
示例#2
0
def dummy_graypixel() -> GrayPixel:
    return GrayPixel(0)
示例#3
0
def blank_image(x: int, y: int, max_level: int = 100) -> Image:
    pixel_values = [[GrayPixel(max_level) for _ in range(x)] for _ in range(y)]
    img = Image(header="P2", max_level=255, dimensions=(x, y), contents=pixel_values)
    return img
示例#4
0
def dummy_image() -> Image:
    return Image(
        header="P2", max_level=255, dimensions=(1, 1), contents=[[GrayPixel(0)]]
    )
示例#5
0
def test_darken_operation_respects_maximum_grayscale(dummy_image: Image):
    p = GrayPixel(100)
    dummy_image.set_pixel(1, 1, p)
    darken_img = dummy_image.darken(200)
    assert not any(val.value > 0 for row in darken_img.values for val in row)
示例#6
0
def test_lighten_operation_respects_maximum_grayscale(dummy_image: Image):
    p = GrayPixel(100)
    dummy_image.set_pixel(1, 1, p)
    ligthen_img = dummy_image.lighten(200)
    assert not any(val.value > 255 for row in ligthen_img.values
                   for val in row)
示例#7
0
def test_cannot_set_pixel_at_out_of_bounds_coordinates(dummy_image: Image,
                                                       x: int, y: int):
    p = GrayPixel(1)
    with pytest.raises(ValidationError):
        dummy_image.set_pixel(x=x, y=y, pixel=p)
示例#8
0
def test_can_set_pixel_at_valid_coordinate(dummy_image: Image):
    p = GrayPixel(1)
    dummy_image.set_pixel(x=1, y=1, pixel=p)