| 1 |
# Copyright 2018 Christoph Reiter <[email protected]> |
| 2 |
# |
| 3 |
# This library is free software; you can redistribute it and/or |
| 4 |
# modify it under the terms of the GNU Lesser General Public |
| 5 |
# License as published by the Free Software Foundation; either |
| 6 |
# version 2.1 of the License, or (at your option) any later version. |
| 7 |
# |
| 8 |
# This library is distributed in the hope that it will be useful, |
| 9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 11 |
# Lesser General Public License for more details. |
| 12 |
# |
| 13 |
# You should have received a copy of the GNU Lesser General Public |
| 14 |
# License along with this library; if not, write to the Free Software |
| 15 |
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 |
| 16 |
# USA |
| 17 |
|
| 18 |
import pytest |
| 19 |
|
| 20 |
from gi import PyGIDeprecationWarning |
| 21 |
|
| 22 |
GdkPixbuf = pytest.importorskip("gi.repository.GdkPixbuf") |
| 23 |
|
| 24 |
|
| 25 |
def test_new_from_data(): |
| 26 |
width = 600 |
| 27 |
height = 32769 |
| 28 |
pixbuf = GdkPixbuf.Pixbuf.new(GdkPixbuf.Colorspace.RGB, True, 8, width, height) |
| 29 |
pixels = pixbuf.get_pixels() |
| 30 |
new_pixbuf = GdkPixbuf.Pixbuf.new_from_data( |
| 31 |
pixels, |
| 32 |
GdkPixbuf.Colorspace.RGB, |
| 33 |
True, |
| 34 |
8, |
| 35 |
pixbuf.get_width(), |
| 36 |
pixbuf.get_height(), |
| 37 |
pixbuf.get_rowstride(), |
| 38 |
) |
| 39 |
del pixbuf |
| 40 |
del pixels |
| 41 |
new_pixels = new_pixbuf.get_pixels() |
| 42 |
assert len(new_pixels) == width * height * 4 |
| 43 |
|
| 44 |
|
| 45 |
def test_new_from_data_deprecated_args(): |
| 46 |
GdkPixbuf.Pixbuf.new_from_data(b"1234", 0, True, 8, 1, 1, 4) |
| 47 |
GdkPixbuf.Pixbuf.new_from_data(b"1234", 0, True, 8, 1, 1, 4, None) |
| 48 |
with ( |
| 49 |
pytest.warns(PyGIDeprecationWarning, match=".*destroy_fn argument.*"), |
| 50 |
pytest.warns(PyGIDeprecationWarning, match=".*destroy_fn_data argument.*"), |
| 51 |
): |
| 52 |
GdkPixbuf.Pixbuf.new_from_data( |
| 53 |
b"1234", 0, True, 8, 1, 1, 4, object(), object(), object() |
| 54 |
) |