def test_quality_too_low_error():
    """
    Trigger LIQ_QUALITY_TOO_LOW and ensure that liq.QualityTooLowError
    is raised
    """
    def attr_callback(value, attr):
        attr.max_colors = 10
        attr.min_quality = 99

    with pytest.raises(liq.QualityTooLowError):
        utils.get_output_datas(
            utils.try_multiple_values('flower', [None],
                                      attr_callback=attr_callback))
Exemple #2
0
def test_image_background():
    """
    Test Image.background
    """
    backgrounds = []

    def image_callback(value, image):

        # Load the background as an Image
        width, height, input_pixels = utils.load_test_image(value)
        attr = liq.Attr()
        background = attr.create_rgba(input_pixels, width, height, 0)
        backgrounds.append(background)

        # Test both the getter and setter methods
        image.background = background
        with pytest.raises(AttributeError):
            image.background

    utils.check_outputs_unique(
        utils.get_output_datas(
            utils.try_multiple_values(
                'alpha-gradient',
                ['test-card_480_360'],  # ['flower', 'test-card_480_360'],
                image_callback=image_callback)))
Exemple #3
0
def test_attr_min_opacity_stub():
    """
    Test Attr.min_opacity (stub implementation, >= liq 2.13.0)
    """
    def attr_callback(value, attr):
        # Test both the getter and setter methods
        attr.min_opacity = value
        assert attr.min_opacity == 0

        # There shouldn't be any bounds checking anymore
        attr.min_opacity = -1
        attr.min_opacity = 256

    utils.get_output_datas(
        utils.try_multiple_values('alpha-gradient', [0, 63, 127, 191, 255],
                                  attr_callback=attr_callback))
Exemple #4
0
def test_attr_min_opacity():
    """
    Test Attr.min_opacity (original implementation, < liq 2.13.0)
    """
    def attr_callback(value, attr):
        # Test both the getter and setter methods
        attr.min_opacity = value
        assert attr.min_opacity == value

        # Test bounds checking (0-255)
        with pytest.raises(ValueError):
            attr.min_opacity = -1
        with pytest.raises(ValueError):
            attr.min_opacity = 256

    utils.check_outputs_unique(
        utils.get_output_datas(
            utils.try_multiple_values('alpha-gradient', [0, 63, 127, 191, 255],
                                      attr_callback=attr_callback)))
Exemple #5
0
def test_attr_speed():
    """
    Test Attr.speed
    """
    def attr_callback(value, attr):
        # Test both the getter and setter methods
        attr.speed = value
        assert attr.speed == value

        # Test bounds checking (1-10)
        with pytest.raises(ValueError):
            attr.speed = 0
        with pytest.raises(ValueError):
            attr.speed = 11

    utils.check_outputs_unique(
        utils.get_output_datas(
            utils.try_multiple_values('flower', [1, 5, 10],
                                      attr_callback=attr_callback)))
Exemple #6
0
def test_attr_max_quality():
    """
    Test Attr.max_quality
    """
    def attr_callback(value, attr):
        # Test both the getter and setter methods
        attr.max_quality = value
        assert attr.max_quality == value

        # Test bounds checking (0-100)
        with pytest.raises(ValueError):
            attr.max_quality = -1
        with pytest.raises(ValueError):
            attr.max_quality = 101

    utils.check_outputs_unique(
        utils.get_output_datas(
            utils.try_multiple_values('flower', [0, 33, 66, 100],
                                      attr_callback=attr_callback)))
Exemple #7
0
def test_attr_min_posterization():
    """
    Test Attr.min_posterization
    """
    def attr_callback(value, attr):
        # Test both the getter and setter methods
        attr.min_posterization = value
        assert attr.min_posterization == value

        # Test bounds checking (0-4)
        with pytest.raises(ValueError):
            attr.min_posterization = -1
        with pytest.raises(ValueError):
            attr.min_posterization = 5

    utils.check_outputs_unique(
        utils.get_output_datas(
            utils.try_multiple_values('flower', [0, 1, 2, 3, 4],
                                      attr_callback=attr_callback)))
def test_result_dithering_level():
    """
    Test Result.dithering_level
    """
    def result_callback(value, result):
        # Test the setter, and ensure the getter raises AttributeError
        result.dithering_level = value
        with pytest.raises(AttributeError):
            result.dithering_level

        # Test bounds checking (0.0-1.0)
        with pytest.raises(ValueError):
            result.dithering_level = -0.1
        with pytest.raises(ValueError):
            result.dithering_level = 1.1

    utils.check_outputs_unique(
        utils.get_output_datas(
            utils.try_multiple_values('flower', [0.0, 0.5, 1.0],
                                      result_callback=result_callback)))
def test_result_output_gamma():
    """
    Test Result.output_gamma
    """
    def result_callback(value, result):
        # Test the setter, and ensure the getter raises AttributeError
        result.output_gamma = value
        assert result.output_gamma == value

        # Test bounds checking (0.0-1.0, not inclusive)
        with pytest.raises(ValueError):
            result.output_gamma = -0.1
        with pytest.raises(ValueError):
            result.output_gamma = 0.0
        with pytest.raises(ValueError):
            result.output_gamma = 1.0
        with pytest.raises(ValueError):
            result.output_gamma = 1.1

    utils.check_outputs_unique(
        utils.get_output_datas(
            utils.try_multiple_values('flower', [0.01, 0.5, 0.99],
                                      result_callback=result_callback)))
Exemple #10
0
def test_image_importance_map():
    """
    Test Image.importance_map
    """
    def image_callback(value, image):

        # Load the map as a bytearray
        width, height, input_pixels = utils.load_test_image(value)
        buffer = bytearray(width * height)
        for i in range(0, len(input_pixels), 4):
            buffer[i // 4] = input_pixels[i]

        # Test both the getter and setter methods
        image.importance_map = buffer
        with pytest.raises(AttributeError):
            image.importance_map

    utils.check_outputs_unique(
        utils.get_output_datas(
            utils.try_multiple_values(
                'alpha-gradient',
                ['importance-map-1', 'importance-map-2', 'importance-map-3'],
                image_callback=image_callback)))