How to use yoga - 10 common examples

To help you get started, we’ve selected a few yoga examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wanadev / yoga / test / test_image.py View on Github external
def test_input_file(self, input_):
        output = io.BytesIO()
        yoga.image.optimize(input_, output)
        output.seek(0)
        assert output.read().startswith(_MAGIC_PNG)
github wanadev / yoga / test / test_image.py View on Github external
def test_output_path(self, tmpdir):
        output_path = os.path.join(str(tmpdir), "output1.png")
        yoga.image.optimize("test/images/alpha.png", output_path)
        output = open(output_path, "rb")
        assert output.read().startswith(_MAGIC_PNG)
github wanadev / yoga / test / test_image.py View on Github external
def test_option_output_format(self, image_path, format_, magic):
        output = io.BytesIO()
        yoga.image.optimize(image_path, output, {
            "output_format": format_
            })
        output.seek(0)
        assert output.read().startswith(magic)
github wanadev / yoga / test / test_image.py View on Github external
def test_option_resize(self, image_path, options, output_image_size):
        output = io.BytesIO()
        yoga.image.optimize(image_path, output, options)
        output.seek(0)
        image = Image.open(output)
        assert image.width == output_image_size[0]
        assert image.height == output_image_size[1]
github wanadev / yoga / test / test_image.py View on Github external
def test_jpeg_quality(self):
        output1 = io.BytesIO()
        yoga.image.optimize("test/images/image1.jpg", output1, {
            "jpeg_quality": 1.00
            })
        output1.seek(0)

        output2 = io.BytesIO()
        yoga.image.optimize("test/images/image1.jpg", output2, {
            "jpeg_quality": 0.50
            })
        output2.seek(0)

        assert len(output2.read()) < len(output1.read())
github wanadev / yoga / test / test_image.py View on Github external
def test_jpeg_quality(self):
        output1 = io.BytesIO()
        yoga.image.optimize("test/images/image1.jpg", output1, {
            "jpeg_quality": 1.00
            })
        output1.seek(0)

        output2 = io.BytesIO()
        yoga.image.optimize("test/images/image1.jpg", output2, {
            "jpeg_quality": 0.50
            })
        output2.seek(0)

        assert len(output2.read()) < len(output1.read())
github wanadev / yoga / test / test_image.py View on Github external
def test_output_file(self, tmpdir):
        output_path = os.path.join(str(tmpdir), "output2.png")
        output = open(output_path, "wb")
        yoga.image.optimize("test/images/alpha.png", output)
        output.close()
        output = open(output_path, "rb")
        assert output.read().startswith(_MAGIC_PNG)
github wanadev / yoga / test / test_image.py View on Github external
def test_output_bytesio(self):
        output = io.BytesIO()
        yoga.image.optimize("test/images/alpha.png", output)
        output.seek(0)
        assert output.read().startswith(_MAGIC_PNG)
github wanadev / yoga / test / test_image.py View on Github external
def test_option_output_format_orig_with_unsuported_output_format(self):
        output = io.BytesIO()
        with pytest.raises(ValueError):
            yoga.image.optimize("test/images/image.gif", output, {
                "output_format": "orig"
                })
github wanadev / yoga / test / test_model_helpers.py View on Github external
u"./images\\texture.png") == "images/texture.png"
        assert helpers.normalize_path(
            u".\\images/texture.png") == "images/texture.png"
        assert helpers.normalize_path(
            u"../images/texture.png") == "images/texture.png"
        assert helpers.normalize_path(
            u"..\\images\\texture.png") == "images/texture.png"
        assert helpers.normalize_path(
            u"./images/subfolder/../texture.png") == "images/texture.png"
        assert helpers.normalize_path(
            u"./images/sub1\\sub2/../../texture.png") == "images/texture.png"
        assert helpers.normalize_path(
            u"./images/texture.png") == "images/texture.png"
        assert helpers.normalize_path(
            u"/images/texture.png") == "images/texture.png"
        assert helpers.normalize_path(
            u"C:\\images\\texture.png") == "images/texture.png"

        assert helpers.normalize_path(
            u"somE_valid-caractères of files.png") == "some_valid-caracteres of files.png" # noqa