Files
gimp/libgimp/tests/test-palette.py
Jehan 7b43a7492f libgimp: new unit testing framework for libgimp.
With Python binding, it gets very easy to test new functions. I've been
wondering if we need C counterparts, but really since it's a GObject
Introspection binding, if a function succeeds there, it should also succeed in C
code.

For now, I'm testing a few of GimpPalette API. Not all of it yet. Also I test
both the direct C binding and PDB procedure since in some cases, one or the
other may not properly working. See #10885.
2024-02-28 22:55:58 +01:00

56 lines
2.2 KiB
Python

#!/usr/bin/env python3
pal = Gimp.Palette.get_by_name('Bears')
gimp_assert('gimp_palette_get_by_name()', type(pal) == Gimp.Palette)
pal2 = Gimp.Palette.get_by_name('Bears')
gimp_assert('gimp_palette_get_by_name() is unique', pal == pal2)
colors = pal.get_colors()
gimp_assert('gimp_palette_get_colors()', len(colors) == 256 and type(colors[0]) == Gegl.Color)
n_colors = pal.get_color_count()
gimp_assert('gimp_palette_get_color_count()', len(colors) == n_colors)
# Run the same tests through PDB:
proc = Gimp.get_pdb().lookup_procedure('gimp-palette-get-by-name')
config = proc.create_config()
config.set_property('name', 'Bears')
result = proc.run(config)
status = result.index(0)
gimp_assert('gimp-palette-get-by-name', status == Gimp.PDBStatusType.SUCCESS)
pal2 = result.index(1)
gimp_assert('gimp-palette-get-by-name and gimp_palette_get_by_name() get identical result', pal == pal2)
proc = Gimp.get_pdb().lookup_procedure('gimp-palette-get-colors')
config = proc.create_config()
config.set_property('palette', pal)
result = proc.run(config)
status = result.index(0)
gimp_assert('gimp-palette-get-colors', status == Gimp.PDBStatusType.SUCCESS)
colors = result.index(1)
# XXX This test is actually what happens right now, but not what should happen.
# See: https://gitlab.gnome.org/GNOME/gimp/-/issues/10885#note_2030308
# And: https://gitlab.gnome.org/GNOME/gobject-introspection/-/issues/492
# If some day this test fails, and in particular if it can return a list of
# GeglColor, then we should remove the test and deprecate
# gimp_value_array_get_color_array() in favor of the generic
# gimp_value_array_index().
gimp_assert('gimp-palette-get-colors', type(colors) == GObject.GBoxed)
colors = result.get_color_array(1)
gimp_assert('gimp_palette_get_colors()', type(colors) == list and len(colors) == 256 and type(colors[0]) == Gegl.Color)
proc = Gimp.get_pdb().lookup_procedure('gimp-palette-get-color-count')
config = proc.create_config()
config.set_property('palette', pal)
result = proc.run(config)
status = result.index(0)
gimp_assert('gimp-palette-get-color-count', status == Gimp.PDBStatusType.SUCCESS)
n_colors = result.index(1)
gimp_assert('gimp_palette_get_color_count()', len(colors) == n_colors)