1 # Copyright 2018 Christoph Reiter <reiter.christoph@gmail.com>
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.
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.
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
18 from __future__
import absolute_import
22 from gi
import PyGIDeprecationWarning
23 GdkPixbuf
= pytest
.importorskip("gi.repository.GdkPixbuf")
26 def test_new_from_data():
29 pixbuf
= GdkPixbuf
.Pixbuf
.new(
30 GdkPixbuf
.Colorspace
.RGB
, True, 8, width
, height
)
31 pixels
= pixbuf
.get_pixels()
32 new_pixbuf
= GdkPixbuf
.Pixbuf
.new_from_data(
33 pixels
, GdkPixbuf
.Colorspace
.RGB
, True, 8,
34 pixbuf
.get_width(), pixbuf
.get_height(), pixbuf
.get_rowstride())
37 new_pixels
= new_pixbuf
.get_pixels()
38 assert len(new_pixels
) == width
* height
* 4
41 def test_new_from_data_deprecated_args():
42 GdkPixbuf
.Pixbuf
.new_from_data(b
"1234", 0, True, 8, 1, 1, 4)
43 GdkPixbuf
.Pixbuf
.new_from_data(b
"1234", 0, True, 8, 1, 1, 4, None)
44 with pytest
.warns(PyGIDeprecationWarning
, match
=".*destroy_fn.*"):
45 GdkPixbuf
.Pixbuf
.new_from_data(
46 b
"1234", 0, True, 8, 1, 1, 4, object(), object(), object())
47 with pytest
.warns(PyGIDeprecationWarning
, match
=".*destroy_fn_data.*"):
48 GdkPixbuf
.Pixbuf
.new_from_data(
49 b
"1234", 0, True, 8, 1, 1, 4, object(), object(), object())