From 557d90704720834929c00490f628c72234ec2c29 Mon Sep 17 00:00:00 2001 From: DongHun Kwak Date: Wed, 12 Jul 2017 08:43:05 +0900 Subject: Imported Upstream version 3.15.91 Change-Id: I0e654ffd312fd34de3c91db355c4fac8462fd8b8 Signed-off-by: DongHun Kwak --- ChangeLog | 135 ++++++++++++++++++++++++++++++++++ NEWS | 14 ++++ PKG-INFO | 4 +- configure | 24 +++--- configure.ac | 2 +- gi/overrides/GLib.py | 56 ++++++++++---- gi/overrides/GObject.py | 94 +++++++++++++----------- gi/overrides/__init__.py | 74 ++++++++++++++++++- gi/pygi-basictype.c | 12 +-- gi/pygi-cache.c | 39 ++++++++-- gi/pygi-cache.h | 5 ++ gi/pygi-closure.c | 4 +- gi/pygi-invoke.c | 41 ++++++++--- tests/test_everything.py | 170 +++++++++++++++++++++---------------------- tests/test_gi.py | 162 ++++++++++++++++++++++++++++++----------- tests/test_glib.py | 33 ++++++--- tests/test_gobject.py | 21 +++--- tests/test_internal_api.py | 4 +- tests/test_iochannel.py | 11 ++- tests/test_overrides_glib.py | 7 ++ tests/test_overrides_gtk.py | 20 ++--- tests/test_properties.py | 100 +++++++++++++------------ tests/test_repository.py | 1 + tests/test_signal.py | 111 ++++++++++++++-------------- tests/test_source.py | 8 +- tests/test_subprocess.py | 7 +- tests/testmodule.py | 3 +- 27 files changed, 795 insertions(+), 367 deletions(-) diff --git a/ChangeLog b/ChangeLog index 970c134..592649d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,138 @@ +commit 9948a67e677c8a351f2de17080d7a671882570f3 +Author: Christoph Reiter +Date: Tue Jan 27 17:47:49 2015 +0100 + + tests: Don't use deprecated override attributes + + In case the test explicitly tests the deprecated attribute + silence the resulting warnings. + + Instead of replacing GObject.PARAM_READWRITE with + GObject.ParamFlags.READWRITE use (READABLE | WRITABLE) + to not depend on a newer glib version. + + https://bugzilla.gnome.org/show_bug.cgi?id=743514 + + tests/test_everything.py | 168 + ++++++++++++++++++++++---------------------- + tests/test_gi.py | 66 ++++++++--------- + tests/test_glib.py | 33 +++++---- + tests/test_gobject.py | 21 +++--- + tests/test_internal_api.py | 4 +- + tests/test_iochannel.py | 11 +-- + tests/test_overrides_gtk.py | 20 +++--- + tests/test_properties.py | 100 ++++++++++++++------------ + tests/test_signal.py | 111 ++++++++++++++--------------- + tests/test_source.py | 8 +-- + tests/test_subprocess.py | 7 +- + tests/testmodule.py | 3 +- + 12 files changed, 292 insertions(+), 260 deletions(-) + +commit 9285b23cd1b253baaf06ddd49e2f000716bbf7f3 +Author: Christoph Reiter +Date: Tue Jan 27 16:36:02 2015 +0100 + + Add GLib.MINFLOAT etc. and mark GObject.G_MINFLOAT etc. deprecated. + + They are defined in glib, not gobject and not included in the gir; + Similar constants like G_MAXINT64 are defined in GLib gir and marked + deprecated in the GObject overrides already. + + https://bugzilla.gnome.org/show_bug.cgi?id=743514 + + gi/overrides/GLib.py | 12 ++++++++++++ + gi/overrides/GObject.py | 4 +++- + tests/test_overrides_glib.py | 7 +++++++ + 3 files changed, 22 insertions(+), 1 deletion(-) + +commit f74acb38f1410982f3419acb134adf173600e497 +Author: Christoph Reiter +Date: Tue Jan 27 16:06:03 2015 +0100 + + Emit PyGIDeprecationWarning when accessing deprecated override + attributes. + + Adds a new helper function for overrides to mark a module level + attribute + as deprecated. A warning will be emitted every time the attribute gets + accessed. + + e.g. when marking GObject.STATUS_FOO as deprecated using + + STATUS_FOO = GLib.Status.FOO + deprecated_attr("GObject", "STATUS_FOO", "GLib.Status.FOO") + __all__.append("STATUS_FOO") + + accessing it will emit + + "GObject.STATUS_FOO is deprecated; use GLib.Status.FOO instead" + + https://bugzilla.gnome.org/show_bug.cgi?id=743514 + + gi/overrides/GLib.py | 44 ++++++++++++++++------- + gi/overrides/GObject.py | 90 + +++++++++++++++++++++++++----------------------- + gi/overrides/__init__.py | 74 ++++++++++++++++++++++++++++++++++++++- + tests/test_gi.py | 70 +++++++++++++++++++++++++++++++++++++ + 4 files changed, 221 insertions(+), 57 deletions(-) + +commit a10df7d28c01d70ee33d8e4e9ddaa23f1990ca60 +Author: Christoph Reiter +Date: Tue Jan 27 19:13:54 2015 +0100 + + Add namespace and container name to callable cache and include them + in all warnings/error messages. + + https://bugzilla.gnome.org/show_bug.cgi?id=743468 + + gi/pygi-cache.c | 39 ++++++++++++++++++++++++++++++++++----- + gi/pygi-cache.h | 5 +++++ + gi/pygi-closure.c | 4 +++- + gi/pygi-invoke.c | 41 +++++++++++++++++++++++++++++------------ + tests/test_everything.py | 2 +- + tests/test_gi.py | 28 ++++++++++++++++++---------- + 6 files changed, 90 insertions(+), 29 deletions(-) + +commit 747fc3754c296ad5481d354bbf35521f886c5c61 +Author: Garrett Regier +Date: Sun Mar 1 03:30:46 2015 -0800 + + tests: Add test for GIRepository.UnionInfo.get_size() + + https://bugzilla.gnome.org/show_bug.cgi?id=745362 + + tests/test_repository.py | 1 + + 1 file changed, 1 insertion(+) + +commit 2dcce92b4fab95403b9bbedffa8a91453c947927 +Author: Garrett Regier +Date: Fri Jan 23 01:37:35 2015 -0800 + + Avoid duping filenames when marshalling from Python to C + + https://bugzilla.gnome.org/show_bug.cgi?id=744719 + + gi/pygi-basictype.c | 12 ++++++------ + 1 file changed, 6 insertions(+), 6 deletions(-) + +commit 26fe8dafb933fa76afd41e45b10a3163a7380c1e +Author: Simon Feltman +Date: Fri Feb 20 22:06:24 2015 -0800 + + configure.ac: post release version bump to 3.15.1 + + configure.ac | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +commit e8aef305d273ce551da41e74a54c5d03de5a0c2a +Author: Simon Feltman +Date: Fri Feb 20 22:04:43 2015 -0800 + + release 3.15.0 + + NEWS | 10 ++++++++++ + 1 file changed, 10 insertions(+) + commit 5dc113283c0a721c4027026bb8de7243585f1289 Author: Simon Feltman Date: Fri Feb 20 21:59:10 2015 -0800 diff --git a/NEWS b/NEWS index 48ddaca..7cc38b4 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,17 @@ +3.15.91 05-Mar-2015 + - tests: Don't use deprecated override attributes + (Christoph Reiter) (#743514) + - Add GLib.MINFLOAT etc. and mark GObject.G_MINFLOAT etc. deprecated + (Christoph Reiter) (#743514) + - Emit PyGIDeprecationWarning when accessing deprecated override attributes + (Christoph Reiter) (#743514) + - Add namespace and container name to all warnings/error messages + (Christoph Reiter) (#743468) + - tests: Add test for GIRepository.UnionInfo.get_size() + (Garrett Regier) (#745362) + - Avoid duping filenames when marshalling from Python to C + (Garrett Regier) (#744719) + 3.15.0 20-Feb-2015 - Avoid copying bytearrays from Python to C when transfer nothing (Garrett Regier) (#743278) - Allows passing arguments to opaque Boxed types (Garrett Regier) (#743214) diff --git a/PKG-INFO b/PKG-INFO index 86cbefd..32e671b 100644 --- a/PKG-INFO +++ b/PKG-INFO @@ -1,6 +1,6 @@ Metadata-Version: 1.0 Name: PyGObject -Version: 3.15.0 +Version: 3.15.91 Summary: Python bindings for GObject Home-page: http://www.pygtk.org/ Author: James Henstridge @@ -8,7 +8,7 @@ Author-email: james@daa.com.au Maintainer: Simon Feltman Maintainer-email: sfeltman@src.gnome.org License: GNU LGPL -Download-url: ftp://ftp.gnome.org/pub/GNOME/sources/pygobject/3.15/pygobject-3.15.0.tar.gz +Download-url: ftp://ftp.gnome.org/pub/GNOME/sources/pygobject/3.15/pygobject-3.15.91.tar.gz Description: Python bindings for GLib and GObject Platform: POSIX, Windows Classifier: Development Status :: 5 - Production/Stable diff --git a/configure b/configure index b8a8b80..ce4f25c 100755 --- a/configure +++ b/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.69 for pygobject 3.15.0. +# Generated by GNU Autoconf 2.69 for pygobject 3.15.91. # # Report bugs to . # @@ -591,8 +591,8 @@ MAKEFLAGS= # Identity of this package. PACKAGE_NAME='pygobject' PACKAGE_TARNAME='pygobject' -PACKAGE_VERSION='3.15.0' -PACKAGE_STRING='pygobject 3.15.0' +PACKAGE_VERSION='3.15.91' +PACKAGE_STRING='pygobject 3.15.91' PACKAGE_BUGREPORT='http://bugzilla.gnome.org/enter_bug.cgi?product=pygobject' PACKAGE_URL='https://wiki.gnome.org/Projects/PyGObject/' @@ -1395,7 +1395,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures pygobject 3.15.0 to adapt to many kinds of systems. +\`configure' configures pygobject 3.15.91 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1465,7 +1465,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of pygobject 3.15.0:";; + short | recursive ) echo "Configuration of pygobject 3.15.91:";; esac cat <<\_ACEOF @@ -1603,7 +1603,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -pygobject configure 3.15.0 +pygobject configure 3.15.91 generated by GNU Autoconf 2.69 Copyright (C) 2012 Free Software Foundation, Inc. @@ -1881,7 +1881,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by pygobject $as_me 3.15.0, which was +It was created by pygobject $as_me 3.15.91, which was generated by GNU Autoconf 2.69. Invocation command line was $ $0 $@ @@ -2245,9 +2245,9 @@ $as_echo "#define PYGOBJECT_MINOR_VERSION 15" >>confdefs.h PYGOBJECT_MINOR_VERSION=15 -$as_echo "#define PYGOBJECT_MICRO_VERSION 0" >>confdefs.h +$as_echo "#define PYGOBJECT_MICRO_VERSION 91" >>confdefs.h -PYGOBJECT_MICRO_VERSION=0 +PYGOBJECT_MICRO_VERSION=91 ac_config_headers="$ac_config_headers config.h" @@ -2767,7 +2767,7 @@ fi # Define the identity of the package. PACKAGE='pygobject' - VERSION='3.15.0' + VERSION='3.15.91' cat >>confdefs.h <<_ACEOF @@ -15377,7 +15377,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by pygobject $as_me 3.15.0, which was +This file was extended by pygobject $as_me 3.15.91, which was generated by GNU Autoconf 2.69. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -15444,7 +15444,7 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -pygobject config.status 3.15.0 +pygobject config.status 3.15.91 configured by $0, generated by GNU Autoconf 2.69, with options \\"\$ac_cs_config\\" diff --git a/configure.ac b/configure.ac index 97099d5..4b5e996 100644 --- a/configure.ac +++ b/configure.ac @@ -18,7 +18,7 @@ m4_define(python3_min_ver, 3.1) dnl the pygobject version number m4_define(pygobject_major_version, 3) m4_define(pygobject_minor_version, 15) -m4_define(pygobject_micro_version, 0) +m4_define(pygobject_micro_version, 91) m4_define(pygobject_version, pygobject_major_version.pygobject_minor_version.pygobject_micro_version) dnl versions of packages we require ... diff --git a/gi/overrides/GLib.py b/gi/overrides/GLib.py index ce15da1..455ea84 100644 --- a/gi/overrides/GLib.py +++ b/gi/overrides/GLib.py @@ -26,7 +26,7 @@ import sys from ..module import get_introspection_module from .._gi import (variant_type_from_string, source_new, source_set_callback, io_channel_read) -from ..overrides import override, deprecated +from ..overrides import override, deprecated, deprecated_attr from gi import PyGIDeprecationWarning, version_info GLib = get_introspection_module('GLib') @@ -40,6 +40,7 @@ __all__.append('option') # Types and functions still needed from static bindings from gi._gi import _glib +from gi._gi import _gobject from gi._error import GError Error = GError @@ -481,8 +482,10 @@ __all__.append('markup_escape_text') # backwards compatible names from old static bindings for n in ['DESKTOP', 'DOCUMENTS', 'DOWNLOAD', 'MUSIC', 'PICTURES', 'PUBLIC_SHARE', 'TEMPLATES', 'VIDEOS']: - globals()['USER_DIRECTORY_' + n] = getattr(GLib.UserDirectory, 'DIRECTORY_' + n) - __all__.append('USER_DIRECTORY_' + n) + attr = 'USER_DIRECTORY_' + n + deprecated_attr("GLib", attr, "GLib.UserDirectory.DIRECTORY_" + n) + globals()[attr] = getattr(GLib.UserDirectory, 'DIRECTORY_' + n) + __all__.append(attr) for n in ['ERR', 'HUP', 'IN', 'NVAL', 'OUT', 'PRI']: globals()['IO_' + n] = getattr(GLib.IOCondition, n) @@ -490,30 +493,53 @@ for n in ['ERR', 'HUP', 'IN', 'NVAL', 'OUT', 'PRI']: for n in ['APPEND', 'GET_MASK', 'IS_READABLE', 'IS_SEEKABLE', 'MASK', 'NONBLOCK', 'SET_MASK']: - globals()['IO_FLAG_' + n] = getattr(GLib.IOFlags, n) - __all__.append('IO_FLAG_' + n) + attr = 'IO_FLAG_' + n + deprecated_attr("GLib", attr, "GLib.IOFlags." + n) + globals()[attr] = getattr(GLib.IOFlags, n) + __all__.append(attr) + # spelling for the win IO_FLAG_IS_WRITEABLE = GLib.IOFlags.IS_WRITABLE +deprecated_attr("GLib", "IO_FLAG_IS_WRITEABLE", "GLib.IOFlags.IS_WRITABLE") __all__.append('IO_FLAG_IS_WRITEABLE') for n in ['AGAIN', 'EOF', 'ERROR', 'NORMAL']: - globals()['IO_STATUS_' + n] = getattr(GLib.IOStatus, n) - __all__.append('IO_STATUS_' + n) + attr = 'IO_STATUS_' + n + globals()[attr] = getattr(GLib.IOStatus, n) + deprecated_attr("GLib", attr, "GLib.IOStatus." + n) + __all__.append(attr) for n in ['CHILD_INHERITS_STDIN', 'DO_NOT_REAP_CHILD', 'FILE_AND_ARGV_ZERO', 'LEAVE_DESCRIPTORS_OPEN', 'SEARCH_PATH', 'STDERR_TO_DEV_NULL', 'STDOUT_TO_DEV_NULL']: - globals()['SPAWN_' + n] = getattr(GLib.SpawnFlags, n) - __all__.append('SPAWN_' + n) + attr = 'SPAWN_' + n + globals()[attr] = getattr(GLib.SpawnFlags, n) + deprecated_attr("GLib", attr, "GLib.SpawnFlags." + n) + __all__.append(attr) for n in ['HIDDEN', 'IN_MAIN', 'REVERSE', 'NO_ARG', 'FILENAME', 'OPTIONAL_ARG', 'NOALIAS']: - globals()['OPTION_FLAG_' + n] = getattr(GLib.OptionFlags, n) - __all__.append('OPTION_FLAG_' + n) + attr = 'OPTION_FLAG_' + n + globals()[attr] = getattr(GLib.OptionFlags, n) + deprecated_attr("GLib", attr, "GLib.OptionFlags." + n) + __all__.append(attr) for n in ['UNKNOWN_OPTION', 'BAD_VALUE', 'FAILED']: - globals()['OPTION_ERROR_' + n] = getattr(GLib.OptionError, n) - __all__.append('OPTION_ERROR_' + n) + attr = 'OPTION_ERROR_' + n + deprecated_attr("GLib", attr, "GLib.OptionError." + n) + globals()[attr] = getattr(GLib.OptionError, n) + __all__.append(attr) + + +# these are not currently exported in GLib gir, presumably because they are +# platform dependent; so get them from our static bindings +for name in ['G_MINFLOAT', 'G_MAXFLOAT', 'G_MINDOUBLE', 'G_MAXDOUBLE', + 'G_MINSHORT', 'G_MAXSHORT', 'G_MAXUSHORT', 'G_MININT', 'G_MAXINT', + 'G_MAXUINT', 'G_MINLONG', 'G_MAXLONG', 'G_MAXULONG', 'G_MAXSIZE', + 'G_MINSSIZE', 'G_MAXSSIZE', 'G_MINOFFSET', 'G_MAXOFFSET']: + attr = name.split("_", 1)[-1] + globals()[attr] = getattr(_gobject, name) + __all__.append(attr) class MainLoop(GLib.MainLoop): @@ -901,5 +927,9 @@ if not hasattr(GLib, 'unix_signal_add_full'): # obsolete constants for backwards compatibility glib_version = (GLib.MAJOR_VERSION, GLib.MINOR_VERSION, GLib.MICRO_VERSION) __all__.append('glib_version') +deprecated_attr("GLib", "glib_version", + "(GLib.MAJOR_VERSION, GLib.MINOR_VERSION, GLib.MICRO_VERSION)") + pyglib_version = version_info __all__.append('pyglib_version') +deprecated_attr("GLib", "pyglib_version", "gi.version_info") diff --git a/gi/overrides/GObject.py b/gi/overrides/GObject.py index e922ac0..28408b2 100644 --- a/gi/overrides/GObject.py +++ b/gi/overrides/GObject.py @@ -27,7 +27,7 @@ from collections import namedtuple import gi.overrides import gi.module -from gi.overrides import override +from gi.overrides import override, deprecated_attr from gi.repository import GLib from gi import PyGIDeprecationWarning @@ -56,10 +56,11 @@ for name in ['markup_escape_text', 'get_application_name', 'idle_add', 'timeout_add', 'timeout_add_seconds', 'io_add_watch', 'child_watch_add', 'get_current_time', 'spawn_async']: - globals()[name] = gi.overrides.deprecated(getattr(GLib, name), 'GLib.' + name) + globals()[name] = getattr(GLib, name) + deprecated_attr("GObject", name, "GLib." + name) __all__.append(name) -# constants are also deprecated, but cannot mark them as such +# deprecated constants for name in ['PRIORITY_DEFAULT', 'PRIORITY_DEFAULT_IDLE', 'PRIORITY_HIGH', 'PRIORITY_HIGH_IDLE', 'PRIORITY_LOW', 'IO_IN', 'IO_OUT', 'IO_PRI', 'IO_ERR', 'IO_HUP', 'IO_NVAL', @@ -77,25 +78,21 @@ for name in ['PRIORITY_DEFAULT', 'PRIORITY_DEFAULT_IDLE', 'PRIORITY_HIGH', 'OPTION_FLAG_NOALIAS', 'OPTION_ERROR_UNKNOWN_OPTION', 'OPTION_ERROR_BAD_VALUE', 'OPTION_ERROR_FAILED', 'OPTION_REMAINING', 'glib_version']: - globals()[name] = getattr(GLib, name) + with warnings.catch_warnings(): + # TODO: this uses deprecated Glib attributes, silence for now + warnings.simplefilter('ignore', PyGIDeprecationWarning) + globals()[name] = getattr(GLib, name) + deprecated_attr("GObject", name, "GLib." + name) __all__.append(name) -G_MININT8 = GLib.MININT8 -G_MAXINT8 = GLib.MAXINT8 -G_MAXUINT8 = GLib.MAXUINT8 -G_MININT16 = GLib.MININT16 -G_MAXINT16 = GLib.MAXINT16 -G_MAXUINT16 = GLib.MAXUINT16 -G_MININT32 = GLib.MININT32 -G_MAXINT32 = GLib.MAXINT32 -G_MAXUINT32 = GLib.MAXUINT32 -G_MININT64 = GLib.MININT64 -G_MAXINT64 = GLib.MAXINT64 -G_MAXUINT64 = GLib.MAXUINT64 -__all__ += ['G_MININT8', 'G_MAXINT8', 'G_MAXUINT8', 'G_MININT16', - 'G_MAXINT16', 'G_MAXUINT16', 'G_MININT32', 'G_MAXINT32', - 'G_MAXUINT32', 'G_MININT64', 'G_MAXINT64', 'G_MAXUINT64'] +for name in ['G_MININT8', 'G_MAXINT8', 'G_MAXUINT8', 'G_MININT16', + 'G_MAXINT16', 'G_MAXUINT16', 'G_MININT32', 'G_MAXINT32', + 'G_MAXUINT32', 'G_MININT64', 'G_MAXINT64', 'G_MAXUINT64']: + new_name = name.split("_", 1)[-1] + globals()[name] = getattr(GLib, new_name) + deprecated_attr("GObject", name, "GLib." + new_name) + __all__.append(name) # these are not currently exported in GLib gir, presumably because they are # platform dependent; so get them from our static bindings @@ -103,7 +100,9 @@ for name in ['G_MINFLOAT', 'G_MAXFLOAT', 'G_MINDOUBLE', 'G_MAXDOUBLE', 'G_MINSHORT', 'G_MAXSHORT', 'G_MAXUSHORT', 'G_MININT', 'G_MAXINT', 'G_MAXUINT', 'G_MINLONG', 'G_MAXLONG', 'G_MAXULONG', 'G_MAXSIZE', 'G_MINSSIZE', 'G_MAXSSIZE', 'G_MINOFFSET', 'G_MAXOFFSET']: - globals()[name] = getattr(_gobject, name) + new_name = name.split("_", 1)[-1] + globals()[name] = getattr(GLib, new_name) + deprecated_attr("GObject", name, "GLib." + new_name) __all__.append(name) @@ -145,38 +144,44 @@ __all__ += ['TYPE_INVALID', 'TYPE_NONE', 'TYPE_INTERFACE', 'TYPE_CHAR', # Deprecated, use GLib directly -Pid = GLib.Pid -GError = GLib.GError -OptionGroup = GLib.OptionGroup -OptionContext = GLib.OptionContext -__all__ += ['Pid', 'GError', 'OptionGroup', 'OptionContext'] +for name in ['Pid', 'GError', 'OptionGroup', 'OptionContext']: + globals()[name] = getattr(GLib, name) + deprecated_attr("GObject", name, "GLib." + name) + __all__.append(name) # Deprecated, use: GObject.ParamFlags.* directly -PARAM_CONSTRUCT = GObjectModule.ParamFlags.CONSTRUCT -PARAM_CONSTRUCT_ONLY = GObjectModule.ParamFlags.CONSTRUCT_ONLY -PARAM_LAX_VALIDATION = GObjectModule.ParamFlags.LAX_VALIDATION -PARAM_READABLE = GObjectModule.ParamFlags.READABLE -PARAM_WRITABLE = GObjectModule.ParamFlags.WRITABLE +for name in ['PARAM_CONSTRUCT', 'PARAM_CONSTRUCT_ONLY', 'PARAM_LAX_VALIDATION', + 'PARAM_READABLE', 'PARAM_WRITABLE']: + new_name = name.split("_", 1)[-1] + globals()[name] = getattr(GObjectModule.ParamFlags, new_name) + deprecated_attr("GObject", name, "GObject.ParamFlags." + new_name) + __all__.append(name) + # PARAM_READWRITE should come from the gi module but cannot due to: # https://bugzilla.gnome.org/show_bug.cgi?id=687615 -PARAM_READWRITE = PARAM_READABLE | PARAM_WRITABLE -__all__ += ['PARAM_CONSTRUCT', 'PARAM_CONSTRUCT_ONLY', 'PARAM_LAX_VALIDATION', - 'PARAM_READABLE', 'PARAM_WRITABLE', 'PARAM_READWRITE'] +PARAM_READWRITE = GObjectModule.ParamFlags.READABLE | \ + GObjectModule.ParamFlags.WRITABLE +__all__.append("PARAM_READWRITE") +# READWRITE is part of ParamFlags since glib 2.42. Only mark PARAM_READWRITE as +# deprecated in case ParamFlags.READWRITE is available. Also include the glib +# version in the warning so it's clear that this needs a newer glib, unlike +# the other ParamFlags related deprecations. +# https://bugzilla.gnome.org/show_bug.cgi?id=726037 +if hasattr(GObjectModule.ParamFlags, "READWRITE"): + deprecated_attr("GObject", "PARAM_READWRITE", + "GObject.ParamFlags.READWRITE (glib 2.42+)") -# Deprecated, use: GObject.SignalFlags.* directly -SIGNAL_ACTION = GObjectModule.SignalFlags.ACTION -SIGNAL_DETAILED = GObjectModule.SignalFlags.DETAILED -SIGNAL_NO_HOOKS = GObjectModule.SignalFlags.NO_HOOKS -SIGNAL_NO_RECURSE = GObjectModule.SignalFlags.NO_RECURSE -SIGNAL_RUN_CLEANUP = GObjectModule.SignalFlags.RUN_CLEANUP -SIGNAL_RUN_FIRST = GObjectModule.SignalFlags.RUN_FIRST -SIGNAL_RUN_LAST = GObjectModule.SignalFlags.RUN_LAST -__all__ += ['SIGNAL_ACTION', 'SIGNAL_DETAILED', 'SIGNAL_NO_HOOKS', - 'SIGNAL_NO_RECURSE', 'SIGNAL_RUN_CLEANUP', 'SIGNAL_RUN_FIRST', - 'SIGNAL_RUN_LAST'] +# Deprecated, use: GObject.SignalFlags.* directly +for name in ['SIGNAL_ACTION', 'SIGNAL_DETAILED', 'SIGNAL_NO_HOOKS', + 'SIGNAL_NO_RECURSE', 'SIGNAL_RUN_CLEANUP', 'SIGNAL_RUN_FIRST', + 'SIGNAL_RUN_LAST']: + new_name = name.split("_", 1)[-1] + globals()[name] = getattr(GObjectModule.SignalFlags, new_name) + deprecated_attr("GObject", name, "GObject.SignalFlags." + new_name) + __all__.append(name) # Static types GBoxed = _gobject.GBoxed @@ -705,4 +710,5 @@ SignalOverride = signalhelper.SignalOverride # Deprecated naming "property" available for backwards compatibility. # Keep this at the end of the file to avoid clobbering the builtin. property = Property +deprecated_attr("GObject", "property", "GObject.Property") __all__ += ['Property', 'Signal', 'SignalOverride', 'property'] diff --git a/gi/overrides/__init__.py b/gi/overrides/__init__.py index b337b35..62cfd30 100644 --- a/gi/overrides/__init__.py +++ b/gi/overrides/__init__.py @@ -14,6 +14,10 @@ from pkgutil import extend_path __path__ = extend_path(__path__, __name__) +# namespace -> (attr, replacement) +_deprecated_attrs = {} + + def wraps(wrapped): def assign(wrapper): wrapper.__name__ = wrapped.__name__ @@ -43,6 +47,37 @@ class OverridesProxyModule(types.ModuleType): return "<%s %r>" % (type(self).__name__, self._introspection_module) +class _DeprecatedAttribute(object): + """A deprecation descriptor for OverridesProxyModule subclasses. + + Emits a PyGIDeprecationWarning on every access and tries to act as a + normal instance attribute (can be replaced and deleted). + """ + + def __init__(self, namespace, attr, value, replacement): + self._attr = attr + self._value = value + self._warning = PyGIDeprecationWarning( + '%s.%s is deprecated; use %s instead' % ( + namespace, attr, replacement)) + + def __get__(self, instance, owner): + if instance is None: + raise AttributeError(self._attr) + warnings.warn(self._warning, stacklevel=2) + return self._value + + def __set__(self, instance, value): + attr = self._attr + # delete the descriptor, then set the instance value + delattr(type(instance), attr) + setattr(instance, attr, value) + + def __delete__(self, instance): + # delete the descriptor + delattr(type(instance), self._attr) + + def load_overrides(introspection_module): """Loads overrides for an introspection module. @@ -58,7 +93,11 @@ def load_overrides(introspection_module): has_old = module_key in sys.modules old_module = sys.modules.get(module_key) - proxy = OverridesProxyModule(introspection_module) + # Create a new sub type, so we can separate descriptors like + # _DeprecatedAttribute for each namespace. + proxy_type = type(namespace + "ProxyModule", (OverridesProxyModule, ), {}) + + proxy = proxy_type(introspection_module) sys.modules[module_key] = proxy # backwards compat: @@ -90,6 +129,19 @@ def load_overrides(introspection_module): continue setattr(proxy, var, item) + # Replace deprecated module level attributes with a descriptor + # which emits a warning when accessed. + for attr, replacement in _deprecated_attrs.pop(namespace, []): + try: + value = getattr(proxy, attr) + except AttributeError: + raise AssertionError( + "%s was set deprecated but wasn't added to __all__" % attr) + delattr(proxy, attr) + deprecated_attr = _DeprecatedAttribute( + namespace, attr, value, replacement) + setattr(proxy_type, attr, deprecated_attr) + return proxy @@ -152,6 +204,26 @@ def deprecated(fn, replacement): return wrapped +def deprecated_attr(namespace, attr, replacement): + """Marks a module level attribute as deprecated. Accessing it will emit + a PyGIDeprecationWarning warning. + + e.g. for ``deprecated_attr("GObject", "STATUS_FOO", "GLib.Status.FOO")`` + accessing GObject.STATUS_FOO will emit: + + "GObject.STATUS_FOO is deprecated; use GLib.Status.FOO instead" + + :param str namespace: + The namespace of the override this is called in. + :param str namespace: + The attribute name (which gets added to __all__). + :param str replacement: + The replacement text which will be included in the warning. + """ + + _deprecated_attrs.setdefault(namespace, []).append((attr, replacement)) + + def deprecated_init(super_init_func, arg_names, ignore=tuple(), deprecated_aliases={}, deprecated_defaults={}, category=PyGIDeprecationWarning, diff --git a/gi/pygi-basictype.c b/gi/pygi-basictype.c index e199741..432559d 100644 --- a/gi/pygi-basictype.c +++ b/gi/pygi-basictype.c @@ -253,18 +253,18 @@ _pygi_marshal_from_py_filename (PyObject *py_arg, { gchar *string_; GError *error = NULL; + PyObject *tmp = NULL; if (PyUnicode_Check (py_arg)) { - PyObject *pystr_obj = PyUnicode_AsUTF8String (py_arg); - if (!pystr_obj) + tmp = PyUnicode_AsUTF8String (py_arg); + if (!tmp) return FALSE; - string_ = g_strdup (PYGLIB_PyBytes_AsString (pystr_obj)); - Py_DECREF (pystr_obj); + string_ = PYGLIB_PyBytes_AsString (tmp); } #if PY_VERSION_HEX < 0x03000000 else if (PyString_Check (py_arg)) { - string_ = g_strdup (PyString_AsString (py_arg)); + string_ = PyString_AsString (py_arg); } #endif else { @@ -274,7 +274,7 @@ _pygi_marshal_from_py_filename (PyObject *py_arg, } arg->v_string = g_filename_from_utf8 (string_, -1, NULL, NULL, &error); - g_free (string_); + Py_XDECREF (tmp); if (arg->v_string == NULL) { PyErr_SetString (PyExc_Exception, error->message); diff --git a/gi/pygi-cache.c b/gi/pygi-cache.c index a572929..ca24517 100644 --- a/gi/pygi-cache.c +++ b/gi/pygi-cache.c @@ -657,6 +657,7 @@ _callable_cache_init (PyGICallableCache *cache, GICallableInfo *callable_info) { gint n_args; + GIBaseInfo *container; if (cache->deinit == NULL) cache->deinit = _callable_cache_deinit_real; @@ -665,18 +666,27 @@ _callable_cache_init (PyGICallableCache *cache, cache->generate_args_cache = _callable_cache_generate_args_cache_real; cache->name = g_base_info_get_name ((GIBaseInfo *) callable_info); + cache->namespace = g_base_info_get_namespace ((GIBaseInfo *) callable_info); + container = g_base_info_get_container ((GIBaseInfo *) callable_info); + cache->container_name = NULL; + /* https://bugzilla.gnome.org/show_bug.cgi?id=709456 */ + if (container != NULL && g_base_info_get_type (container) != GI_INFO_TYPE_TYPE) { + cache->container_name = g_base_info_get_name (container); + } cache->throws = g_callable_info_can_throw_gerror ((GIBaseInfo *) callable_info); if (g_base_info_is_deprecated (callable_info)) { const gchar *deprecated = g_base_info_get_attribute (callable_info, "deprecated"); gchar *warning; + gchar *full_name = pygi_callable_cache_get_full_name (cache); if (deprecated != NULL) - warning = g_strdup_printf ("%s.%s is deprecated: %s", - g_base_info_get_namespace (callable_info), cache->name, + warning = g_strdup_printf ("%s is deprecated: %s", + full_name, deprecated); else - warning = g_strdup_printf ("%s.%s is deprecated", - g_base_info_get_namespace (callable_info), cache->name); + warning = g_strdup_printf ("%s is deprecated", + full_name); + g_free (full_name); PyErr_WarnEx (PyExc_DeprecationWarning, warning, 0); g_free (warning); } @@ -696,6 +706,23 @@ _callable_cache_init (PyGICallableCache *cache, return TRUE; } +gchar * +pygi_callable_cache_get_full_name (PyGICallableCache *cache) +{ + if (cache->container_name != NULL) { + return g_strjoin (".", + cache->namespace, + cache->container_name, + cache->name, + NULL); + } else { + return g_strjoin (".", + cache->namespace, + cache->name, + NULL); + } +} + void pygi_callable_cache_free (PyGICallableCache *cache) { @@ -845,11 +872,13 @@ _constructor_cache_invoke_real (PyGIFunctionCache *function_cache, constructor_class = PyTuple_GetItem (py_args, 0); if (constructor_class == NULL) { + gchar *full_name = pygi_callable_cache_get_full_name (cache); PyErr_Clear (); PyErr_Format (PyExc_TypeError, "Constructors require the class to be passed in as an argument, " "No arguments passed to the %s constructor.", - ((PyGICallableCache *) function_cache)->name); + full_name); + g_free (full_name); return FALSE; } diff --git a/gi/pygi-cache.h b/gi/pygi-cache.h index 0361f00..098f3f1 100644 --- a/gi/pygi-cache.h +++ b/gi/pygi-cache.h @@ -158,6 +158,8 @@ typedef struct _PyGIInterfaceCache struct _PyGICallableCache { const gchar *name; + const gchar *container_name; + const gchar *namespace; PyGICallingContext calling_context; @@ -265,6 +267,9 @@ pygi_arg_cache_free (PyGIArgCache *cache); void pygi_callable_cache_free (PyGICallableCache *cache); +gchar * +pygi_callable_cache_get_full_name (PyGICallableCache *cache); + PyGIFunctionCache * pygi_function_cache_new (GICallableInfo *info); diff --git a/gi/pygi-closure.c b/gi/pygi-closure.c index 2a5a120..65f7e55 100644 --- a/gi/pygi-closure.c +++ b/gi/pygi-closure.c @@ -777,10 +777,12 @@ _pygi_marshal_from_py_interface_callback (PyGIInvokeState *state, if (user_data_cache != NULL) { state->arg_values[destroy_cache->c_arg_index].v_pointer = _pygi_invoke_closure_free; } else { + char *full_name = pygi_callable_cache_get_full_name (callable_cache); gchar *msg = g_strdup_printf("Callables passed to %s will leak references because " "the method does not support a user_data argument. " "See: https://bugzilla.gnome.org/show_bug.cgi?id=685598", - callable_cache->name); + full_name); + g_free (full_name); if (PyErr_WarnEx(PyExc_RuntimeWarning, msg, 2)) { g_free(msg); _pygi_invoke_closure_free(closure); diff --git a/gi/pygi-invoke.c b/gi/pygi-invoke.c index a65274a..0151650 100644 --- a/gi/pygi-invoke.c +++ b/gi/pygi-invoke.c @@ -26,7 +26,7 @@ #include "pygi-error.h" static gboolean -_check_for_unexpected_kwargs (const gchar *function_name, +_check_for_unexpected_kwargs (PyGICallableCache *cache, GHashTable *arg_name_hash, PyObject *py_kwargs) { @@ -54,11 +54,13 @@ _check_for_unexpected_kwargs (const gchar *function_name, * found which maps to index 0 for our hash lookup. */ if (!g_hash_table_lookup_extended (arg_name_hash, PyBytes_AsString(key), NULL, NULL)) { + char *full_name = pygi_callable_cache_get_full_name (cache); PyErr_Format (PyExc_TypeError, "%.200s() got an unexpected keyword argument '%.400s'", - function_name, + full_name, PyBytes_AsString (key)); Py_DECREF (key); + g_free (full_name); return FALSE; } @@ -84,7 +86,6 @@ _py_args_combine_and_check_length (PyGICallableCache *cache, Py_ssize_t n_py_args, n_py_kwargs, i; guint n_expected_args; GSList *l; - const gchar *function_name = cache->name; n_py_args = PyTuple_GET_SIZE (py_args); if (py_kwargs == NULL) @@ -100,24 +101,28 @@ _py_args_combine_and_check_length (PyGICallableCache *cache, } if (cache->user_data_varargs_index < 0 && n_expected_args < n_py_args) { + char *full_name = pygi_callable_cache_get_full_name (cache); PyErr_Format (PyExc_TypeError, "%.200s() takes exactly %d %sargument%s (%zd given)", - function_name, + full_name, n_expected_args, n_py_kwargs > 0 ? "non-keyword " : "", n_expected_args == 1 ? "" : "s", n_py_args); + g_free (full_name); return NULL; } if (cache->user_data_varargs_index >= 0 && n_py_kwargs > 0 && n_expected_args < n_py_args) { + char *full_name = pygi_callable_cache_get_full_name (cache); PyErr_Format (PyExc_TypeError, "%.200s() cannot use variable user data arguments with keyword arguments", - function_name); + full_name); + g_free (full_name); return NULL; } - if (n_py_kwargs > 0 && !_check_for_unexpected_kwargs (function_name, + if (n_py_kwargs > 0 && !_check_for_unexpected_kwargs (cache, cache->arg_name_hash, py_kwargs)) { return NULL; @@ -183,24 +188,28 @@ _py_args_combine_and_check_length (PyGICallableCache *cache, Py_INCREF (_PyGIDefaultArgPlaceholder); PyTuple_SET_ITEM (combined_py_args, i, _PyGIDefaultArgPlaceholder); } else { + char *full_name = pygi_callable_cache_get_full_name (cache); PyErr_Format (PyExc_TypeError, "%.200s() takes exactly %d %sargument%s (%zd given)", - function_name, + full_name, n_expected_args, n_py_kwargs > 0 ? "non-keyword " : "", n_expected_args == 1 ? "" : "s", n_py_args); + g_free (full_name); Py_DECREF (combined_py_args); return NULL; } } else if (kw_arg_item != NULL && py_arg_item != NULL) { + char *full_name = pygi_callable_cache_get_full_name (cache); PyErr_Format (PyExc_TypeError, "%.200s() got multiple values for keyword argument '%.200s'", - function_name, + full_name, arg_name); Py_DECREF (combined_py_args); + g_free (full_name); return NULL; } } @@ -362,11 +371,13 @@ _invoke_marshal_in_args (PyGIInvokeState *state, PyGIFunctionCache *function_cac gssize i; if (state->n_py_in_args > cache->n_py_args) { + char *full_name = pygi_callable_cache_get_full_name (cache); PyErr_Format (PyExc_TypeError, "%s() takes exactly %zd argument(s) (%zd given)", - cache->name, + full_name, cache->n_py_args, state->n_py_in_args); + g_free (full_name); return FALSE; } @@ -387,11 +398,13 @@ _invoke_marshal_in_args (PyGIInvokeState *state, PyGIFunctionCache *function_cac continue; if (arg_cache->py_arg_index >= state->n_py_in_args) { + char *full_name = pygi_callable_cache_get_full_name (cache); PyErr_Format (PyExc_TypeError, "%s() takes exactly %zd argument(s) (%zd given)", - cache->name, + full_name, cache->n_py_args, state->n_py_in_args); + g_free (full_name); /* clean up all of the args we have already marshalled, * since invoke will not be called @@ -410,11 +423,13 @@ _invoke_marshal_in_args (PyGIInvokeState *state, PyGIFunctionCache *function_cac case PYGI_DIRECTION_BIDIRECTIONAL: if (arg_cache->meta_type != PYGI_META_ARG_TYPE_CHILD) { if (arg_cache->py_arg_index >= state->n_py_in_args) { + char *full_name = pygi_callable_cache_get_full_name (cache); PyErr_Format (PyExc_TypeError, "%s() takes exactly %zd argument(s) (%zd given)", - cache->name, + full_name, cache->n_py_args, state->n_py_in_args); + g_free (full_name); pygi_marshal_cleanup_args_from_py_parameter_fail (state, cache, i); @@ -446,9 +461,11 @@ _invoke_marshal_in_args (PyGIInvokeState *state, PyGIFunctionCache *function_cac state->args[i] = c_arg; if (!_caller_alloc (arg_cache, c_arg)) { + char *full_name = pygi_callable_cache_get_full_name (cache); PyErr_Format (PyExc_TypeError, "Could not caller allocate argument %zd of callable %s", - i, cache->name); + i, full_name); + g_free (full_name); pygi_marshal_cleanup_args_from_py_parameter_fail (state, cache, i); diff --git a/tests/test_everything.py b/tests/test_everything.py index 88b6da1..5be9ce4 100644 --- a/tests/test_everything.py +++ b/tests/test_everything.py @@ -63,112 +63,112 @@ class TestEverything(unittest.TestCase): self.assertEqual(Everything.test_boolean_false(False), False) def test_int8(self): - self.assertEqual(Everything.test_int8(GObject.G_MAXINT8), - GObject.G_MAXINT8) - self.assertEqual(Everything.test_int8(GObject.G_MININT8), - GObject.G_MININT8) - self.assertRaises(OverflowError, Everything.test_int8, GObject.G_MAXINT8 + 1) - - self.assertEqual(Everything.test_uint8(GObject.G_MAXUINT8), - GObject.G_MAXUINT8) + self.assertEqual(Everything.test_int8(GLib.MAXINT8), + GLib.MAXINT8) + self.assertEqual(Everything.test_int8(GLib.MININT8), + GLib.MININT8) + self.assertRaises(OverflowError, Everything.test_int8, GLib.MAXINT8 + 1) + + self.assertEqual(Everything.test_uint8(GLib.MAXUINT8), + GLib.MAXUINT8) self.assertEqual(Everything.test_uint8(0), 0) self.assertRaises(OverflowError, Everything.test_uint8, -1) - self.assertRaises(OverflowError, Everything.test_uint8, GObject.G_MAXUINT8 + 1) + self.assertRaises(OverflowError, Everything.test_uint8, GLib.MAXUINT8 + 1) def test_int16(self): - self.assertEqual(Everything.test_int16(GObject.G_MAXINT16), - GObject.G_MAXINT16) - self.assertEqual(Everything.test_int16(GObject.G_MININT16), - GObject.G_MININT16) - self.assertRaises(OverflowError, Everything.test_int16, GObject.G_MAXINT16 + 1) - - self.assertEqual(Everything.test_uint16(GObject.G_MAXUINT16), - GObject.G_MAXUINT16) + self.assertEqual(Everything.test_int16(GLib.MAXINT16), + GLib.MAXINT16) + self.assertEqual(Everything.test_int16(GLib.MININT16), + GLib.MININT16) + self.assertRaises(OverflowError, Everything.test_int16, GLib.MAXINT16 + 1) + + self.assertEqual(Everything.test_uint16(GLib.MAXUINT16), + GLib.MAXUINT16) self.assertEqual(Everything.test_uint16(0), 0) self.assertRaises(OverflowError, Everything.test_uint16, -1) - self.assertRaises(OverflowError, Everything.test_uint16, GObject.G_MAXUINT16 + 1) + self.assertRaises(OverflowError, Everything.test_uint16, GLib.MAXUINT16 + 1) def test_int32(self): - self.assertEqual(Everything.test_int32(GObject.G_MAXINT32), - GObject.G_MAXINT32) - self.assertEqual(Everything.test_int32(GObject.G_MININT32), - GObject.G_MININT32) - self.assertRaises(OverflowError, Everything.test_int32, GObject.G_MAXINT32 + 1) - - self.assertEqual(Everything.test_uint32(GObject.G_MAXUINT32), - GObject.G_MAXUINT32) + self.assertEqual(Everything.test_int32(GLib.MAXINT32), + GLib.MAXINT32) + self.assertEqual(Everything.test_int32(GLib.MININT32), + GLib.MININT32) + self.assertRaises(OverflowError, Everything.test_int32, GLib.MAXINT32 + 1) + + self.assertEqual(Everything.test_uint32(GLib.MAXUINT32), + GLib.MAXUINT32) self.assertEqual(Everything.test_uint32(0), 0) self.assertRaises(OverflowError, Everything.test_uint32, -1) - self.assertRaises(OverflowError, Everything.test_uint32, GObject.G_MAXUINT32 + 1) + self.assertRaises(OverflowError, Everything.test_uint32, GLib.MAXUINT32 + 1) def test_int64(self): - self.assertEqual(Everything.test_int64(GObject.G_MAXINT64), - GObject.G_MAXINT64) - self.assertEqual(Everything.test_int64(GObject.G_MININT64), - GObject.G_MININT64) - self.assertRaises(OverflowError, Everything.test_int64, GObject.G_MAXINT64 + 1) - - self.assertEqual(Everything.test_uint64(GObject.G_MAXUINT64), - GObject.G_MAXUINT64) + self.assertEqual(Everything.test_int64(GLib.MAXINT64), + GLib.MAXINT64) + self.assertEqual(Everything.test_int64(GLib.MININT64), + GLib.MININT64) + self.assertRaises(OverflowError, Everything.test_int64, GLib.MAXINT64 + 1) + + self.assertEqual(Everything.test_uint64(GLib.MAXUINT64), + GLib.MAXUINT64) self.assertEqual(Everything.test_uint64(0), 0) self.assertRaises(OverflowError, Everything.test_uint64, -1) - self.assertRaises(OverflowError, Everything.test_uint64, GObject.G_MAXUINT64 + 1) + self.assertRaises(OverflowError, Everything.test_uint64, GLib.MAXUINT64 + 1) def test_int(self): - self.assertEqual(Everything.test_int(GObject.G_MAXINT), - GObject.G_MAXINT) - self.assertEqual(Everything.test_int(GObject.G_MININT), - GObject.G_MININT) - self.assertRaises(OverflowError, Everything.test_int, GObject.G_MAXINT + 1) - - self.assertEqual(Everything.test_uint(GObject.G_MAXUINT), - GObject.G_MAXUINT) + self.assertEqual(Everything.test_int(GLib.MAXINT), + GLib.MAXINT) + self.assertEqual(Everything.test_int(GLib.MININT), + GLib.MININT) + self.assertRaises(OverflowError, Everything.test_int, GLib.MAXINT + 1) + + self.assertEqual(Everything.test_uint(GLib.MAXUINT), + GLib.MAXUINT) self.assertEqual(Everything.test_uint(0), 0) self.assertRaises(OverflowError, Everything.test_uint, -1) - self.assertRaises(OverflowError, Everything.test_uint, GObject.G_MAXUINT + 1) + self.assertRaises(OverflowError, Everything.test_uint, GLib.MAXUINT + 1) def test_short(self): - self.assertEqual(Everything.test_short(GObject.G_MAXSHORT), - GObject.G_MAXSHORT) - self.assertEqual(Everything.test_short(GObject.G_MINSHORT), - GObject.G_MINSHORT) - self.assertRaises(OverflowError, Everything.test_short, GObject.G_MAXSHORT + 1) - - self.assertEqual(Everything.test_ushort(GObject.G_MAXUSHORT), - GObject.G_MAXUSHORT) + self.assertEqual(Everything.test_short(GLib.MAXSHORT), + GLib.MAXSHORT) + self.assertEqual(Everything.test_short(GLib.MINSHORT), + GLib.MINSHORT) + self.assertRaises(OverflowError, Everything.test_short, GLib.MAXSHORT + 1) + + self.assertEqual(Everything.test_ushort(GLib.MAXUSHORT), + GLib.MAXUSHORT) self.assertEqual(Everything.test_ushort(0), 0) self.assertRaises(OverflowError, Everything.test_ushort, -1) - self.assertRaises(OverflowError, Everything.test_ushort, GObject.G_MAXUSHORT + 1) + self.assertRaises(OverflowError, Everything.test_ushort, GLib.MAXUSHORT + 1) def test_long(self): - self.assertEqual(Everything.test_long(GObject.G_MAXLONG), - GObject.G_MAXLONG) - self.assertEqual(Everything.test_long(GObject.G_MINLONG), - GObject.G_MINLONG) - self.assertRaises(OverflowError, Everything.test_long, GObject.G_MAXLONG + 1) - - self.assertEqual(Everything.test_ulong(GObject.G_MAXULONG), - GObject.G_MAXULONG) + self.assertEqual(Everything.test_long(GLib.MAXLONG), + GLib.MAXLONG) + self.assertEqual(Everything.test_long(GLib.MINLONG), + GLib.MINLONG) + self.assertRaises(OverflowError, Everything.test_long, GLib.MAXLONG + 1) + + self.assertEqual(Everything.test_ulong(GLib.MAXULONG), + GLib.MAXULONG) self.assertEqual(Everything.test_ulong(0), 0) self.assertRaises(OverflowError, Everything.test_ulong, -1) - self.assertRaises(OverflowError, Everything.test_ulong, GObject.G_MAXULONG + 1) + self.assertRaises(OverflowError, Everything.test_ulong, GLib.MAXULONG + 1) def test_size(self): - self.assertEqual(Everything.test_ssize(GObject.G_MAXSSIZE), - GObject.G_MAXSSIZE) - self.assertEqual(Everything.test_ssize(GObject.G_MINSSIZE), - GObject.G_MINSSIZE) - self.assertRaises(OverflowError, Everything.test_ssize, GObject.G_MAXSSIZE + 1) - - self.assertEqual(Everything.test_size(GObject.G_MAXSIZE), - GObject.G_MAXSIZE) + self.assertEqual(Everything.test_ssize(GLib.MAXSSIZE), + GLib.MAXSSIZE) + self.assertEqual(Everything.test_ssize(GLib.MINSSIZE), + GLib.MINSSIZE) + self.assertRaises(OverflowError, Everything.test_ssize, GLib.MAXSSIZE + 1) + + self.assertEqual(Everything.test_size(GLib.MAXSIZE), + GLib.MAXSIZE) self.assertEqual(Everything.test_size(0), 0) self.assertRaises(OverflowError, Everything.test_size, -1) - self.assertRaises(OverflowError, Everything.test_size, GObject.G_MAXSIZE + 1) + self.assertRaises(OverflowError, Everything.test_size, GLib.MAXSIZE + 1) def test_timet(self): self.assertEqual(Everything.test_timet(42), 42) - self.assertRaises(OverflowError, Everything.test_timet, GObject.G_MAXUINT64 + 1) + self.assertRaises(OverflowError, Everything.test_timet, GLib.MAXUINT64 + 1) def test_unichar(self): self.assertEqual("c", Everything.test_unichar("c")) @@ -180,25 +180,25 @@ class TestEverything(unittest.TestCase): self.assertRaises(TypeError, Everything.test_unichar, "morethanonechar") def test_float(self): - self.assertEqual(Everything.test_float(GObject.G_MAXFLOAT), - GObject.G_MAXFLOAT) - self.assertEqual(Everything.test_float(GObject.G_MINFLOAT), - GObject.G_MINFLOAT) - self.assertRaises(OverflowError, Everything.test_float, GObject.G_MAXFLOAT * 2) + self.assertEqual(Everything.test_float(GLib.MAXFLOAT), + GLib.MAXFLOAT) + self.assertEqual(Everything.test_float(GLib.MINFLOAT), + GLib.MINFLOAT) + self.assertRaises(OverflowError, Everything.test_float, GLib.MAXFLOAT * 2) def test_double(self): - self.assertEqual(Everything.test_double(GObject.G_MAXDOUBLE), - GObject.G_MAXDOUBLE) - self.assertEqual(Everything.test_double(GObject.G_MINDOUBLE), - GObject.G_MINDOUBLE) + self.assertEqual(Everything.test_double(GLib.MAXDOUBLE), + GLib.MAXDOUBLE) + self.assertEqual(Everything.test_double(GLib.MINDOUBLE), + GLib.MINDOUBLE) (two, three) = Everything.test_multi_double_args(2.5) self.assertAlmostEqual(two, 5.0) self.assertAlmostEqual(three, 7.5) def test_value(self): - self.assertEqual(Everything.test_int_value_arg(GObject.G_MAXINT), GObject.G_MAXINT) - self.assertEqual(Everything.test_value_return(GObject.G_MAXINT), GObject.G_MAXINT) + self.assertEqual(Everything.test_int_value_arg(GLib.MAXINT), GLib.MAXINT) + self.assertEqual(Everything.test_value_return(GLib.MAXINT), GLib.MAXINT) def test_variant(self): v = Everything.test_gvariant_i() @@ -322,7 +322,7 @@ class TestEverything(unittest.TestCase): Everything.test_int8() except TypeError: (e_type, e) = sys.exc_info()[:2] - self.assertEqual(e.args, ("test_int8() takes exactly 1 argument (0 given)",)) + self.assertEqual(e.args, ("Regress.test_int8() takes exactly 1 argument (0 given)",)) def test_gtypes(self): gchararray_gtype = GObject.type_from_name('gchararray') diff --git a/tests/test_gi.py b/tests/test_gi.py index 9633f57..22a5738 100644 --- a/tests/test_gi.py +++ b/tests/test_gi.py @@ -101,8 +101,8 @@ class TestBoolean(unittest.TestCase): class TestInt8(unittest.TestCase): - MAX = GObject.G_MAXINT8 - MIN = GObject.G_MININT8 + MAX = GLib.MAXINT8 + MIN = GLib.MININT8 def test_int8_return(self): self.assertEqual(self.MAX, GIMarshallingTests.int8_return_max()) @@ -134,7 +134,7 @@ class TestInt8(unittest.TestCase): class TestUInt8(unittest.TestCase): - MAX = GObject.G_MAXUINT8 + MAX = GLib.MAXUINT8 def test_uint8_return(self): self.assertEqual(self.MAX, GIMarshallingTests.uint8_return()) @@ -160,8 +160,8 @@ class TestUInt8(unittest.TestCase): class TestInt16(unittest.TestCase): - MAX = GObject.G_MAXINT16 - MIN = GObject.G_MININT16 + MAX = GLib.MAXINT16 + MIN = GLib.MININT16 def test_int16_return(self): self.assertEqual(self.MAX, GIMarshallingTests.int16_return_max()) @@ -193,7 +193,7 @@ class TestInt16(unittest.TestCase): class TestUInt16(unittest.TestCase): - MAX = GObject.G_MAXUINT16 + MAX = GLib.MAXUINT16 def test_uint16_return(self): self.assertEqual(self.MAX, GIMarshallingTests.uint16_return()) @@ -219,8 +219,8 @@ class TestUInt16(unittest.TestCase): class TestInt32(unittest.TestCase): - MAX = GObject.G_MAXINT32 - MIN = GObject.G_MININT32 + MAX = GLib.MAXINT32 + MIN = GLib.MININT32 def test_int32_return(self): self.assertEqual(self.MAX, GIMarshallingTests.int32_return_max()) @@ -252,7 +252,7 @@ class TestInt32(unittest.TestCase): class TestUInt32(unittest.TestCase): - MAX = GObject.G_MAXUINT32 + MAX = GLib.MAXUINT32 def test_uint32_return(self): self.assertEqual(self.MAX, GIMarshallingTests.uint32_return()) @@ -337,8 +337,8 @@ class TestUInt64(unittest.TestCase): class TestShort(unittest.TestCase): - MAX = GObject.G_MAXSHORT - MIN = GObject.G_MINSHORT + MAX = GLib.MAXSHORT + MIN = GLib.MINSHORT def test_short_return(self): self.assertEqual(self.MAX, GIMarshallingTests.short_return_max()) @@ -370,7 +370,7 @@ class TestShort(unittest.TestCase): class TestUShort(unittest.TestCase): - MAX = GObject.G_MAXUSHORT + MAX = GLib.MAXUSHORT def test_ushort_return(self): self.assertEqual(self.MAX, GIMarshallingTests.ushort_return()) @@ -396,8 +396,8 @@ class TestUShort(unittest.TestCase): class TestInt(unittest.TestCase): - MAX = GObject.G_MAXINT - MIN = GObject.G_MININT + MAX = GLib.MAXINT + MIN = GLib.MININT def test_int_return(self): self.assertEqual(self.MAX, GIMarshallingTests.int_return_max()) @@ -430,7 +430,7 @@ class TestInt(unittest.TestCase): class TestUInt(unittest.TestCase): - MAX = GObject.G_MAXUINT + MAX = GLib.MAXUINT def test_uint_return(self): self.assertEqual(self.MAX, GIMarshallingTests.uint_return()) @@ -456,8 +456,8 @@ class TestUInt(unittest.TestCase): class TestLong(unittest.TestCase): - MAX = GObject.G_MAXLONG - MIN = GObject.G_MINLONG + MAX = GLib.MAXLONG + MIN = GLib.MINLONG def test_long_return(self): self.assertEqual(self.MAX, GIMarshallingTests.long_return_max()) @@ -489,7 +489,7 @@ class TestLong(unittest.TestCase): class TestULong(unittest.TestCase): - MAX = GObject.G_MAXULONG + MAX = GLib.MAXULONG def test_ulong_return(self): self.assertEqual(self.MAX, GIMarshallingTests.ulong_return()) @@ -515,8 +515,8 @@ class TestULong(unittest.TestCase): class TestSSize(unittest.TestCase): - MAX = GObject.G_MAXLONG - MIN = GObject.G_MINLONG + MAX = GLib.MAXLONG + MIN = GLib.MINLONG def test_ssize_return(self): self.assertEqual(self.MAX, GIMarshallingTests.ssize_return_max()) @@ -548,7 +548,7 @@ class TestSSize(unittest.TestCase): class TestSize(unittest.TestCase): - MAX = GObject.G_MAXULONG + MAX = GLib.MAXULONG def test_size_return(self): self.assertEqual(self.MAX, GIMarshallingTests.size_return()) @@ -590,8 +590,8 @@ class TestTimet(unittest.TestCase): class TestFloat(unittest.TestCase): - MAX = GObject.G_MAXFLOAT - MIN = GObject.G_MINFLOAT + MAX = GLib.MAXFLOAT + MIN = GLib.MINFLOAT def test_float_return(self): self.assertAlmostEqual(self.MAX, GIMarshallingTests.float_return()) @@ -610,8 +610,8 @@ class TestFloat(unittest.TestCase): class TestDouble(unittest.TestCase): - MAX = GObject.G_MAXDOUBLE - MIN = GObject.G_MINDOUBLE + MAX = GLib.MAXDOUBLE + MIN = GLib.MINDOUBLE def test_double_return(self): self.assertAlmostEqual(self.MAX, GIMarshallingTests.double_return()) @@ -962,7 +962,7 @@ class TestGArray(unittest.TestCase): self.assertEqual([-1, 0, 1, 2], GIMarshallingTests.garray_int_none_return()) def test_garray_uint64_none_return(self): - self.assertEqual([0, GObject.G_MAXUINT64], GIMarshallingTests.garray_uint64_none_return()) + self.assertEqual([0, GLib.MAXUINT64], GIMarshallingTests.garray_uint64_none_return()) def test_garray_utf8_none_return(self): self.assertEqual(['0', '1', '2'], GIMarshallingTests.garray_utf8_none_return()) @@ -982,7 +982,7 @@ class TestGArray(unittest.TestCase): self.assertRaises(TypeError, GIMarshallingTests.garray_int_none_in, None) def test_garray_uint64_none_in(self): - GIMarshallingTests.garray_uint64_none_in(Sequence([0, GObject.G_MAXUINT64])) + GIMarshallingTests.garray_uint64_none_in(Sequence([0, GLib.MAXUINT64])) def test_garray_utf8_none_in(self): GIMarshallingTests.garray_utf8_none_in(Sequence(['0', '1', '2'])) @@ -1109,7 +1109,7 @@ class TestGList(unittest.TestCase): self.assertEqual([-1, 0, 1, 2], GIMarshallingTests.glist_int_none_return()) def test_glist_uint32_none_return(self): - self.assertEqual([0, GObject.G_MAXUINT32], GIMarshallingTests.glist_uint32_none_return()) + self.assertEqual([0, GLib.MAXUINT32], GIMarshallingTests.glist_uint32_none_return()) def test_glist_utf8_none_return(self): self.assertEqual(['0', '1', '2'], GIMarshallingTests.glist_utf8_none_return()) @@ -1137,7 +1137,7 @@ class TestGList(unittest.TestCase): self.assertRaises(Exception, GIMarshallingTests.glist_int_none_in, FailingSequence((-1, 0, 1, 2))) def test_glist_uint32_none_in(self): - GIMarshallingTests.glist_uint32_none_in(Sequence((0, GObject.G_MAXUINT32))) + GIMarshallingTests.glist_uint32_none_in(Sequence((0, GLib.MAXUINT32))) def test_glist_utf8_none_in(self): GIMarshallingTests.glist_utf8_none_in(Sequence(('0', '1', '2'))) @@ -1280,7 +1280,7 @@ class TestGValue(unittest.TestCase): self.assertEqual(value.get_int(), 24) def test_gvalue_int64_in(self): - value = GObject.Value(GObject.TYPE_INT64, GObject.G_MAXINT64) + value = GObject.Value(GObject.TYPE_INT64, GLib.MAXINT64) GIMarshallingTests.gvalue_int64_in(value) def test_gvalue_in_with_type(self): @@ -1300,7 +1300,7 @@ class TestGValue(unittest.TestCase): self.assertEqual(42, GIMarshallingTests.gvalue_out()) def test_gvalue_int64_out(self): - self.assertEqual(GObject.G_MAXINT64, GIMarshallingTests.gvalue_int64_out()) + self.assertEqual(GLib.MAXINT64, GIMarshallingTests.gvalue_int64_out()) def test_gvalue_out_caller_allocates(self): self.assertEqual(42, GIMarshallingTests.gvalue_out_caller_allocates()) @@ -2636,29 +2636,29 @@ class TestKeywordArgs(unittest.TestCase): def test_type_errors(self): # test too few args - self.assertRaisesMessage(TypeError, "int_three_in_three_out() takes exactly 3 arguments (0 given)", + self.assertRaisesMessage(TypeError, "GIMarshallingTests.int_three_in_three_out() takes exactly 3 arguments (0 given)", GIMarshallingTests.int_three_in_three_out) - self.assertRaisesMessage(TypeError, "int_three_in_three_out() takes exactly 3 arguments (1 given)", + self.assertRaisesMessage(TypeError, "GIMarshallingTests.int_three_in_three_out() takes exactly 3 arguments (1 given)", GIMarshallingTests.int_three_in_three_out, 1) - self.assertRaisesMessage(TypeError, "int_three_in_three_out() takes exactly 3 arguments (0 given)", + self.assertRaisesMessage(TypeError, "GIMarshallingTests.int_three_in_three_out() takes exactly 3 arguments (0 given)", GIMarshallingTests.int_three_in_three_out, *()) - self.assertRaisesMessage(TypeError, "int_three_in_three_out() takes exactly 3 arguments (0 given)", + self.assertRaisesMessage(TypeError, "GIMarshallingTests.int_three_in_three_out() takes exactly 3 arguments (0 given)", GIMarshallingTests.int_three_in_three_out, *(), **{}) - self.assertRaisesMessage(TypeError, "int_three_in_three_out() takes exactly 3 non-keyword arguments (0 given)", + self.assertRaisesMessage(TypeError, "GIMarshallingTests.int_three_in_three_out() takes exactly 3 non-keyword arguments (0 given)", GIMarshallingTests.int_three_in_three_out, *(), **{'c': 4}) # test too many args - self.assertRaisesMessage(TypeError, "int_three_in_three_out() takes exactly 3 arguments (4 given)", + self.assertRaisesMessage(TypeError, "GIMarshallingTests.int_three_in_three_out() takes exactly 3 arguments (4 given)", GIMarshallingTests.int_three_in_three_out, *(1, 2, 3, 4)) - self.assertRaisesMessage(TypeError, "int_three_in_three_out() takes exactly 3 non-keyword arguments (4 given)", + self.assertRaisesMessage(TypeError, "GIMarshallingTests.int_three_in_three_out() takes exactly 3 non-keyword arguments (4 given)", GIMarshallingTests.int_three_in_three_out, *(1, 2, 3, 4), c=6) # test too many keyword args - self.assertRaisesMessage(TypeError, "int_three_in_three_out() got multiple values for keyword argument 'a'", + self.assertRaisesMessage(TypeError, "GIMarshallingTests.int_three_in_three_out() got multiple values for keyword argument 'a'", GIMarshallingTests.int_three_in_three_out, 1, 2, 3, **{'a': 4, 'b': 5}) - self.assertRaisesMessage(TypeError, "int_three_in_three_out() got an unexpected keyword argument 'd'", + self.assertRaisesMessage(TypeError, "GIMarshallingTests.int_three_in_three_out() got an unexpected keyword argument 'd'", GIMarshallingTests.int_three_in_three_out, d=4) - self.assertRaisesMessage(TypeError, "int_three_in_three_out() got an unexpected keyword argument 'e'", + self.assertRaisesMessage(TypeError, "GIMarshallingTests.int_three_in_three_out() got an unexpected keyword argument 'e'", GIMarshallingTests.int_three_in_three_out, **{'e': 2}) def test_kwargs_are_not_modified(self): @@ -2780,6 +2780,86 @@ class TestDeprecation(unittest.TestCase): warnings.simplefilter('always') d.set_time(1) self.assertTrue(issubclass(warn[0].category, DeprecationWarning)) + self.assertEqual(str(warn[0].message), "GLib.Date.set_time is deprecated") + + def test_function(self): + with warnings.catch_warnings(record=True) as warn: + warnings.simplefilter('always') + GLib.strcasecmp("foo", "bar") + self.assertTrue(issubclass(warn[0].category, DeprecationWarning)) + self.assertEqual(str(warn[0].message), "GLib.strcasecmp is deprecated") + + def test_deprecated_attribute_compat(self): + # test if the deprecation descriptor behaves like an instance attribute + + # save the descriptor + desc = type(GLib).__dict__["IO_STATUS_ERROR"] + + # the descriptor raises AttributeError for itself + self.assertFalse(hasattr(type(GLib), "IO_STATUS_ERROR")) + + with warnings.catch_warnings(): + warnings.simplefilter('ignore', PyGIDeprecationWarning) + self.assertTrue(hasattr(GLib, "IO_STATUS_ERROR")) + + try: + # check if replacing works + GLib.IO_STATUS_ERROR = "foo" + self.assertEqual(GLib.IO_STATUS_ERROR, "foo") + finally: + # restore descriptor + try: + del GLib.IO_STATUS_ERROR + except AttributeError: + pass + setattr(type(GLib), "IO_STATUS_ERROR", desc) + + try: + # check if deleting works + del GLib.IO_STATUS_ERROR + self.assertFalse(hasattr(GLib, "IO_STATUS_ERROR")) + finally: + # restore descriptor + try: + del GLib.IO_STATUS_ERROR + except AttributeError: + pass + setattr(type(GLib), "IO_STATUS_ERROR", desc) + + def test_deprecated_attribute_warning(self): + with warnings.catch_warnings(record=True) as warn: + warnings.simplefilter('always') + self.assertEqual(GLib.IO_STATUS_ERROR, GLib.IOStatus.ERROR) + GLib.IO_STATUS_ERROR + GLib.IO_STATUS_ERROR + self.assertEqual(len(warn), 3) + self.assertTrue( + issubclass(warn[0].category, PyGIDeprecationWarning)) + self.assertRegexpMatches( + str(warn[0].message), + ".*GLib.IO_STATUS_ERROR.*GLib.IOStatus.ERROR.*") + + def test_deprecated_attribute_warning_coverage(self): + with warnings.catch_warnings(record=True) as warn: + warnings.simplefilter('always') + GObject.markup_escape_text + GObject.PRIORITY_DEFAULT + GObject.GError + GObject.PARAM_CONSTRUCT + GObject.SIGNAL_ACTION + GObject.property + GObject.IO_STATUS_ERROR + GObject.G_MAXUINT64 + GLib.IO_STATUS_ERROR + GLib.SPAWN_SEARCH_PATH + GLib.OPTION_FLAG_HIDDEN + GLib.IO_FLAG_IS_WRITEABLE + GLib.IO_FLAG_NONBLOCK + GLib.USER_DIRECTORY_DESKTOP + GLib.OPTION_ERROR_BAD_VALUE + GLib.glib_version + GLib.pyglib_version + self.assertEqual(len(warn), 17) def test_deprecated_init_no_keywords(self): def init(self, **kwargs): diff --git a/tests/test_glib.py b/tests/test_glib.py index 17ac2de..5ede849 100644 --- a/tests/test_glib.py +++ b/tests/test_glib.py @@ -38,11 +38,14 @@ class TestGLib(unittest.TestCase): def test_xdg_dirs(self): d = GLib.get_user_data_dir() self.assertTrue('/' in d, d) - d = GLib.get_user_special_dir(GLib.USER_DIRECTORY_DESKTOP) + d = GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_MUSIC) self.assertTrue('/' in d, d) - # also works with backwards compatible enum names - self.assertEqual(GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_MUSIC), - GLib.get_user_special_dir(GLib.USER_DIRECTORY_MUSIC)) + with warnings.catch_warnings(): + warnings.simplefilter('ignore', PyGIDeprecationWarning) + + # also works with backwards compatible enum names + self.assertEqual(GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_MUSIC), + GLib.get_user_special_dir(GLib.USER_DIRECTORY_MUSIC)) for d in GLib.get_system_config_dirs(): self.assertTrue('/' in d, d) @@ -215,16 +218,22 @@ https://my.org/q?x=1&y=2 (cmd.stdout, GLib.IOCondition.IN, b'world\n')]) def test_glib_version(self): - (major, minor, micro) = GLib.glib_version - self.assertGreaterEqual(major, 2) - self.assertGreaterEqual(minor, 0) - self.assertGreaterEqual(micro, 0) + with warnings.catch_warnings(): + warnings.simplefilter('ignore', PyGIDeprecationWarning) + + (major, minor, micro) = GLib.glib_version + self.assertGreaterEqual(major, 2) + self.assertGreaterEqual(minor, 0) + self.assertGreaterEqual(micro, 0) def test_pyglib_version(self): - (major, minor, micro) = GLib.pyglib_version - self.assertGreaterEqual(major, 3) - self.assertGreaterEqual(minor, 0) - self.assertGreaterEqual(micro, 0) + with warnings.catch_warnings(): + warnings.simplefilter('ignore', PyGIDeprecationWarning) + + (major, minor, micro) = GLib.pyglib_version + self.assertGreaterEqual(major, 3) + self.assertGreaterEqual(minor, 0) + self.assertGreaterEqual(micro, 0) def test_timezone_constructor(self): timezone = GLib.TimeZone("+05:21") diff --git a/tests/test_gobject.py b/tests/test_gobject.py index a88a4bc..6c15e20 100644 --- a/tests/test_gobject.py +++ b/tests/test_gobject.py @@ -60,17 +60,20 @@ class TestGObjectAPI(unittest.TestCase): self.assertLess(GObject.PRIORITY_HIGH, GObject.PRIORITY_DEFAULT) def test_min_max_int(self): - self.assertEqual(GObject.G_MAXINT16, 2 ** 15 - 1) - self.assertEqual(GObject.G_MININT16, -2 ** 15) - self.assertEqual(GObject.G_MAXUINT16, 2 ** 16 - 1) + with warnings.catch_warnings(): + warnings.simplefilter('ignore', PyGIDeprecationWarning) - self.assertEqual(GObject.G_MAXINT32, 2 ** 31 - 1) - self.assertEqual(GObject.G_MININT32, -2 ** 31) - self.assertEqual(GObject.G_MAXUINT32, 2 ** 32 - 1) + self.assertEqual(GObject.G_MAXINT16, 2 ** 15 - 1) + self.assertEqual(GObject.G_MININT16, -2 ** 15) + self.assertEqual(GObject.G_MAXUINT16, 2 ** 16 - 1) - self.assertEqual(GObject.G_MAXINT64, 2 ** 63 - 1) - self.assertEqual(GObject.G_MININT64, -2 ** 63) - self.assertEqual(GObject.G_MAXUINT64, 2 ** 64 - 1) + self.assertEqual(GObject.G_MAXINT32, 2 ** 31 - 1) + self.assertEqual(GObject.G_MININT32, -2 ** 31) + self.assertEqual(GObject.G_MAXUINT32, 2 ** 32 - 1) + + self.assertEqual(GObject.G_MAXINT64, 2 ** 63 - 1) + self.assertEqual(GObject.G_MININT64, -2 ** 63) + self.assertEqual(GObject.G_MAXUINT64, 2 ** 64 - 1) class TestReferenceCounting(unittest.TestCase): diff --git a/tests/test_internal_api.py b/tests/test_internal_api.py index ca50f6b..eb66fdd 100644 --- a/tests/test_internal_api.py +++ b/tests/test_internal_api.py @@ -40,8 +40,8 @@ class TestGValueConversion(unittest.TestCase): self.assertEqual(testhelper.test_value(0), 0) self.assertEqual(testhelper.test_value(5), 5) self.assertEqual(testhelper.test_value(-5), -5) - self.assertEqual(testhelper.test_value(GObject.G_MAXINT32), GObject.G_MAXINT32) - self.assertEqual(testhelper.test_value(GObject.G_MININT32), GObject.G_MININT32) + self.assertEqual(testhelper.test_value(GLib.MAXINT32), GLib.MAXINT32) + self.assertEqual(testhelper.test_value(GLib.MININT32), GLib.MININT32) def test_str(self): self.assertEqual(testhelper.test_value('hello'), 'hello') diff --git a/tests/test_iochannel.py b/tests/test_iochannel.py index 259171b..02277e1 100644 --- a/tests/test_iochannel.py +++ b/tests/test_iochannel.py @@ -415,10 +415,13 @@ second line self.assertEqual(cb_reads, [b'a', b'b']) def test_backwards_compat_flags(self): - self.assertEqual(GLib.IOCondition.IN, GLib.IO_IN) - self.assertEqual(GLib.IOFlags.NONBLOCK, GLib.IO_FLAG_NONBLOCK) - self.assertEqual(GLib.IOFlags.IS_SEEKABLE, GLib.IO_FLAG_IS_SEEKABLE) - self.assertEqual(GLib.IOStatus.NORMAL, GLib.IO_STATUS_NORMAL) + with warnings.catch_warnings(): + warnings.simplefilter('ignore', PyGIDeprecationWarning) + + self.assertEqual(GLib.IOCondition.IN, GLib.IO_IN) + self.assertEqual(GLib.IOFlags.NONBLOCK, GLib.IO_FLAG_NONBLOCK) + self.assertEqual(GLib.IOFlags.IS_SEEKABLE, GLib.IO_FLAG_IS_SEEKABLE) + self.assertEqual(GLib.IOStatus.NORMAL, GLib.IO_STATUS_NORMAL) if __name__ == '__main__': unittest.main() diff --git a/tests/test_overrides_glib.py b/tests/test_overrides_glib.py index af68895..4f630dc 100644 --- a/tests/test_overrides_glib.py +++ b/tests/test_overrides_glib.py @@ -494,3 +494,10 @@ class TestGVariant(unittest.TestCase): # with override constructor v = GLib.Variant('(is)', (1, 'somestring')) self.assertEqual(str(v), "(1, 'somestring')") + + +class TestConstants(unittest.TestCase): + + def test_basic_types_limits(self): + self.assertTrue(isinstance(GLib.MINFLOAT, float)) + self.assertTrue(isinstance(GLib.MAXLONG, (int, _long))) diff --git a/tests/test_overrides_gtk.py b/tests/test_overrides_gtk.py index a57b7da..bd477bf 100644 --- a/tests/test_overrides_gtk.py +++ b/tests/test_overrides_gtk.py @@ -908,8 +908,8 @@ class TestTreeModel(unittest.TestCase): i % 2, bool(i % 2), i, - GObject.G_MAXULONG, - GObject.G_MININT64, + GLib.MAXULONG, + GLib.MININT64, 0xffffffffffffffff, 254, _bytes('a') @@ -930,8 +930,8 @@ class TestTreeModel(unittest.TestCase): 7, i % 2, 8, bool(i % 2), 9, i, - 10, GObject.G_MAXULONG, - 11, GObject.G_MININT64, + 10, GLib.MAXULONG, + 11, GLib.MININT64, 12, 0xffffffffffffffff, 13, 254, 14, _bytes('a')) @@ -950,8 +950,8 @@ class TestTreeModel(unittest.TestCase): 7: i % 2, 8: bool(i % 2), 9: i, - 10: GObject.G_MAXULONG, - 11: GObject.G_MININT64, + 10: GLib.MAXULONG, + 11: GLib.MININT64, 12: 0xffffffffffffffff, 13: 254, 14: _bytes('a')}) @@ -971,8 +971,8 @@ class TestTreeModel(unittest.TestCase): i % 2, bool(i % 2), i, - GObject.G_MAXULONG, - GObject.G_MININT64, + GLib.MAXULONG, + GLib.MININT64, 0xffffffffffffffff, 254, _bytes('a'))) @@ -1011,9 +1011,9 @@ class TestTreeModel(unittest.TestCase): uint_ = tree_store.get_value(treeiter, 9) self.assertEqual(uint_, i) ulong_ = tree_store.get_value(treeiter, 10) - self.assertEqual(ulong_, GObject.G_MAXULONG) + self.assertEqual(ulong_, GLib.MAXULONG) int64_ = tree_store.get_value(treeiter, 11) - self.assertEqual(int64_, GObject.G_MININT64) + self.assertEqual(int64_, GLib.MININT64) uint64_ = tree_store.get_value(treeiter, 12) self.assertEqual(uint64_, 0xffffffffffffffff) uchar_ = tree_store.get_value(treeiter, 13) diff --git a/tests/test_properties.py b/tests/test_properties.py index a147aae..6010bc2 100644 --- a/tests/test_properties.py +++ b/tests/test_properties.py @@ -8,8 +8,7 @@ import unittest import gi from gi.repository import GObject -from gi.repository.GObject import GType, new, PARAM_READWRITE, \ - PARAM_CONSTRUCT, PARAM_READABLE, PARAM_WRITABLE, PARAM_CONSTRUCT_ONLY +from gi.repository.GObject import ParamFlags, GType, new from gi.repository.GObject import \ TYPE_INT, TYPE_UINT, TYPE_LONG, TYPE_ULONG, TYPE_INT64, \ TYPE_UINT64, TYPE_GTYPE, TYPE_INVALID, TYPE_NONE, TYPE_STRV, \ @@ -17,9 +16,9 @@ from gi.repository.GObject import \ TYPE_DOUBLE, TYPE_POINTER, TYPE_BOXED, TYPE_PARAM, TYPE_OBJECT, \ TYPE_STRING, TYPE_PYOBJECT, TYPE_VARIANT -from gi.repository.GObject import \ - G_MININT, G_MAXINT, G_MAXUINT, G_MINLONG, G_MAXLONG, G_MAXULONG, \ - G_MAXUINT64, G_MAXINT64, G_MININT64 +from gi.repository.GLib import \ + MININT, MAXINT, MAXUINT, MINLONG, MAXLONG, MAXULONG, \ + MAXUINT64, MAXINT64, MININT64 from gi.repository import Gio from gi.repository import GLib @@ -48,38 +47,49 @@ class PropertyObject(GObject.GObject): normal = GObject.Property(type=str) construct = GObject.Property( type=str, - flags=PARAM_READWRITE | PARAM_CONSTRUCT, default='default') + flags=ParamFlags.READABLE | ParamFlags.WRITABLE | ParamFlags.CONSTRUCT, + default='default') + construct_only = GObject.Property( type=str, - flags=PARAM_READWRITE | PARAM_CONSTRUCT_ONLY) + flags=ParamFlags.READABLE | ParamFlags.WRITABLE | ParamFlags.CONSTRUCT_ONLY) + uint64 = GObject.Property( - type=TYPE_UINT64, flags=PARAM_READWRITE | PARAM_CONSTRUCT) + type=TYPE_UINT64, + flags=ParamFlags.READABLE | ParamFlags.WRITABLE | ParamFlags.CONSTRUCT) enum = GObject.Property( type=Gio.SocketType, default=Gio.SocketType.STREAM) boxed = GObject.Property( - type=GLib.Regex, flags=PARAM_READWRITE | PARAM_CONSTRUCT) + type=GLib.Regex, + flags=ParamFlags.READABLE | ParamFlags.WRITABLE | ParamFlags.CONSTRUCT) flags = GObject.Property( - type=GIMarshallingTests.Flags, flags=PARAM_READWRITE | PARAM_CONSTRUCT, + type=GIMarshallingTests.Flags, + flags=ParamFlags.READABLE | ParamFlags.WRITABLE | ParamFlags.CONSTRUCT, default=GIMarshallingTests.Flags.VALUE1) gtype = GObject.Property( - type=TYPE_GTYPE, flags=PARAM_READWRITE | PARAM_CONSTRUCT) + type=TYPE_GTYPE, + flags=ParamFlags.READABLE | ParamFlags.WRITABLE | ParamFlags.CONSTRUCT) strings = GObject.Property( - type=TYPE_STRV, flags=PARAM_READWRITE | PARAM_CONSTRUCT) + type=TYPE_STRV, + flags=ParamFlags.READABLE | ParamFlags.WRITABLE | ParamFlags.CONSTRUCT) variant = GObject.Property( - type=TYPE_VARIANT, flags=PARAM_READWRITE | PARAM_CONSTRUCT) + type=TYPE_VARIANT, + flags=ParamFlags.READABLE | ParamFlags.WRITABLE | ParamFlags.CONSTRUCT) variant_def = GObject.Property( - type=TYPE_VARIANT, flags=PARAM_READWRITE | PARAM_CONSTRUCT, + type=TYPE_VARIANT, + flags=ParamFlags.READABLE | ParamFlags.WRITABLE | ParamFlags.CONSTRUCT, default=GLib.Variant('i', 42)) interface = GObject.Property( - type=Gio.File, flags=PARAM_READWRITE | PARAM_CONSTRUCT) + type=Gio.File, + flags=ParamFlags.READABLE | ParamFlags.WRITABLE | ParamFlags.CONSTRUCT) if has_regress: @@ -210,7 +220,7 @@ class TestPropertyObject(unittest.TestCase): __gproperties__ = { 'time': (TYPE_UINT64, 'Time', 'Time', _long(0), (1 << 64) - 1, _long(0), - PARAM_READABLE) + ParamFlags.READABLE) } except OverflowError: (etype, ex) = sys.exc_info()[2:] @@ -443,7 +453,7 @@ class TestPropertyObject(unittest.TestCase): d = {} for key, (gtype, min, max) in types_.items(): d[key] = (gtype, 'blurb', 'desc', min, max, 0, - PARAM_READABLE | PARAM_WRITABLE) + ParamFlags.READABLE | ParamFlags.WRITABLE) return d class RangeCheck(GObject.GObject): @@ -645,12 +655,12 @@ class TestProperty(unittest.TestCase): def test_range(self): types_ = [ - (TYPE_INT, G_MININT, G_MAXINT), - (TYPE_UINT, 0, G_MAXUINT), - (TYPE_LONG, G_MINLONG, G_MAXLONG), - (TYPE_ULONG, 0, G_MAXULONG), - (TYPE_INT64, G_MININT64, G_MAXINT64), - (TYPE_UINT64, 0, G_MAXUINT64), + (TYPE_INT, MININT, MAXINT), + (TYPE_UINT, 0, MAXUINT), + (TYPE_LONG, MINLONG, MAXLONG), + (TYPE_ULONG, 0, MAXULONG), + (TYPE_INT64, MININT64, MAXINT64), + (TYPE_UINT64, 0, MAXUINT64), ] for gtype, min, max in types_: @@ -969,24 +979,24 @@ class CPropertiesTestBase(object): def test_char(self): self.assertEqual(self.get_prop(self.obj, 'some-char'), 0) - self.set_prop(self.obj, 'some-char', GObject.G_MAXINT8) - self.assertEqual(self.get_prop(self.obj, 'some-char'), GObject.G_MAXINT8) + self.set_prop(self.obj, 'some-char', GLib.MAXINT8) + self.assertEqual(self.get_prop(self.obj, 'some-char'), GLib.MAXINT8) obj = GIMarshallingTests.PropertiesObject(some_char=-42) self.assertEqual(self.get_prop(obj, 'some-char'), -42) def test_uchar(self): self.assertEqual(self.get_prop(self.obj, 'some-uchar'), 0) - self.set_prop(self.obj, 'some-uchar', GObject.G_MAXUINT8) - self.assertEqual(self.get_prop(self.obj, 'some-uchar'), GObject.G_MAXUINT8) + self.set_prop(self.obj, 'some-uchar', GLib.MAXUINT8) + self.assertEqual(self.get_prop(self.obj, 'some-uchar'), GLib.MAXUINT8) obj = GIMarshallingTests.PropertiesObject(some_uchar=42) self.assertEqual(self.get_prop(obj, 'some-uchar'), 42) def test_int(self): self.assertEqual(self.get_prop(self.obj, 'some_int'), 0) - self.set_prop(self.obj, 'some-int', GObject.G_MAXINT) - self.assertEqual(self.get_prop(self.obj, 'some_int'), GObject.G_MAXINT) + self.set_prop(self.obj, 'some-int', GLib.MAXINT) + self.assertEqual(self.get_prop(self.obj, 'some_int'), GLib.MAXINT) obj = GIMarshallingTests.PropertiesObject(some_int=-42) self.assertEqual(self.get_prop(obj, 'some-int'), -42) @@ -998,8 +1008,8 @@ class CPropertiesTestBase(object): def test_uint(self): self.assertEqual(self.get_prop(self.obj, 'some_uint'), 0) - self.set_prop(self.obj, 'some-uint', GObject.G_MAXUINT) - self.assertEqual(self.get_prop(self.obj, 'some_uint'), GObject.G_MAXUINT) + self.set_prop(self.obj, 'some-uint', GLib.MAXUINT) + self.assertEqual(self.get_prop(self.obj, 'some_uint'), GLib.MAXUINT) obj = GIMarshallingTests.PropertiesObject(some_uint=42) self.assertEqual(self.get_prop(obj, 'some-uint'), 42) @@ -1011,8 +1021,8 @@ class CPropertiesTestBase(object): def test_long(self): self.assertEqual(self.get_prop(self.obj, 'some_long'), 0) - self.set_prop(self.obj, 'some-long', GObject.G_MAXLONG) - self.assertEqual(self.get_prop(self.obj, 'some_long'), GObject.G_MAXLONG) + self.set_prop(self.obj, 'some-long', GLib.MAXLONG) + self.assertEqual(self.get_prop(self.obj, 'some_long'), GLib.MAXLONG) obj = GIMarshallingTests.PropertiesObject(some_long=-42) self.assertEqual(self.get_prop(obj, 'some-long'), -42) @@ -1024,8 +1034,8 @@ class CPropertiesTestBase(object): def test_ulong(self): self.assertEqual(self.get_prop(self.obj, 'some_ulong'), 0) - self.set_prop(self.obj, 'some-ulong', GObject.G_MAXULONG) - self.assertEqual(self.get_prop(self.obj, 'some_ulong'), GObject.G_MAXULONG) + self.set_prop(self.obj, 'some-ulong', GLib.MAXULONG) + self.assertEqual(self.get_prop(self.obj, 'some_ulong'), GLib.MAXULONG) obj = GIMarshallingTests.PropertiesObject(some_ulong=42) self.assertEqual(self.get_prop(obj, 'some-ulong'), 42) @@ -1037,24 +1047,24 @@ class CPropertiesTestBase(object): def test_int64(self): self.assertEqual(self.get_prop(self.obj, 'some-int64'), 0) - self.set_prop(self.obj, 'some-int64', GObject.G_MAXINT64) - self.assertEqual(self.get_prop(self.obj, 'some-int64'), GObject.G_MAXINT64) + self.set_prop(self.obj, 'some-int64', GLib.MAXINT64) + self.assertEqual(self.get_prop(self.obj, 'some-int64'), GLib.MAXINT64) obj = GIMarshallingTests.PropertiesObject(some_int64=-4200000000000000) self.assertEqual(self.get_prop(obj, 'some-int64'), -4200000000000000) def test_uint64(self): self.assertEqual(self.get_prop(self.obj, 'some-uint64'), 0) - self.set_prop(self.obj, 'some-uint64', GObject.G_MAXUINT64) - self.assertEqual(self.get_prop(self.obj, 'some-uint64'), GObject.G_MAXUINT64) + self.set_prop(self.obj, 'some-uint64', GLib.MAXUINT64) + self.assertEqual(self.get_prop(self.obj, 'some-uint64'), GLib.MAXUINT64) obj = GIMarshallingTests.PropertiesObject(some_uint64=4200000000000000) self.assertEqual(self.get_prop(obj, 'some-uint64'), 4200000000000000) def test_float(self): self.assertEqual(self.get_prop(self.obj, 'some-float'), 0) - self.set_prop(self.obj, 'some-float', GObject.G_MAXFLOAT) - self.assertEqual(self.get_prop(self.obj, 'some-float'), GObject.G_MAXFLOAT) + self.set_prop(self.obj, 'some-float', GLib.MAXFLOAT) + self.assertEqual(self.get_prop(self.obj, 'some-float'), GLib.MAXFLOAT) obj = GIMarshallingTests.PropertiesObject(some_float=42.42) self.assertAlmostEqual(self.get_prop(obj, 'some-float'), 42.42, 4) @@ -1069,8 +1079,8 @@ class CPropertiesTestBase(object): def test_double(self): self.assertEqual(self.get_prop(self.obj, 'some-double'), 0) - self.set_prop(self.obj, 'some-double', GObject.G_MAXDOUBLE) - self.assertEqual(self.get_prop(self.obj, 'some-double'), GObject.G_MAXDOUBLE) + self.set_prop(self.obj, 'some-double', GLib.MAXDOUBLE) + self.assertEqual(self.get_prop(self.obj, 'some-double'), GLib.MAXDOUBLE) obj = GIMarshallingTests.PropertiesObject(some_double=42.42) self.assertAlmostEqual(self.get_prop(obj, 'some-double'), 42.42) @@ -1120,7 +1130,7 @@ class CPropertiesTestBase(object): def test_boxed_glist(self): self.assertEqual(self.get_prop(self.obj, 'some-boxed-glist'), []) - l = [GObject.G_MININT, 42, GObject.G_MAXINT] + l = [GLib.MININT, 42, GLib.MAXINT] self.set_prop(self.obj, 'some-boxed-glist', l) self.assertEqual(self.get_prop(self.obj, 'some-boxed-glist'), l) self.set_prop(self.obj, 'some-boxed-glist', []) @@ -1141,7 +1151,7 @@ class CPropertiesTestBase(object): @unittest.expectedFailure def test_boxed_glist_ctor(self): - l = [GObject.G_MININT, 42, GObject.G_MAXINT] + l = [GLib.MININT, 42, GLib.MAXINT] obj = GIMarshallingTests.PropertiesObject(some_boxed_glist=l) self.assertEqual(self.get_prop(obj, 'some-boxed-glist'), l) diff --git a/tests/test_repository.py b/tests/test_repository.py index 43c7d9e..3d7cf68 100644 --- a/tests/test_repository.py +++ b/tests/test_repository.py @@ -179,6 +179,7 @@ class Test(unittest.TestCase): self.assertTrue(isinstance(info, GIRepository.UnionInfo)) self.assertTrue(isinstance(info.get_fields(), collections.Iterable)) self.assertTrue(isinstance(info.get_methods(), collections.Iterable)) + self.assertTrue(isinstance(info.get_size(), int)) def test_type_info(self): func_info = repo.find_by_name('GIMarshallingTests', 'array_fixed_out_struct') diff --git a/tests/test_signal.py b/tests/test_signal.py index 40cfb4f..74ec745 100644 --- a/tests/test_signal.py +++ b/tests/test_signal.py @@ -500,7 +500,8 @@ class SigPropClass(GObject.GObject): (GObject.TYPE_INT,))} __gproperties__ = { - 'foo': (str, None, None, '', GObject.PARAM_WRITABLE | GObject.PARAM_CONSTRUCT), + 'foo': (str, None, None, '', + GObject.ParamFlags.WRITABLE | GObject.ParamFlags.CONSTRUCT), } signal_emission_failed = False @@ -577,11 +578,11 @@ class _TestCMarshaller: rv = self.obj.emit("test-int64", 102030405) self.assertEqual(rv, 102030405) - rv = self.obj.emit("test-int64", GObject.G_MAXINT64) - self.assertEqual(rv, GObject.G_MAXINT64 - 1) + rv = self.obj.emit("test-int64", GLib.MAXINT64) + self.assertEqual(rv, GLib.MAXINT64 - 1) - rv = self.obj.emit("test-int64", GObject.G_MININT64) - self.assertEqual(rv, GObject.G_MININT64) + rv = self.obj.emit("test-int64", GLib.MININT64) + self.assertEqual(rv, GLib.MININT64) def test_string(self): rv = self.obj.emit("test-string", "str") @@ -634,34 +635,34 @@ class _TestCMarshaller: self.assertAlmostEqual(rv, 1.234, 4) # explicit int64 - v = GObject.Value(GObject.TYPE_INT64, GObject.G_MAXINT64) + v = GObject.Value(GObject.TYPE_INT64, GLib.MAXINT64) rv = self.obj.emit("test-gvalue", v) - self.assertEqual(rv, GObject.G_MAXINT64) + self.assertEqual(rv, GLib.MAXINT64) # explicit uint64 - v = GObject.Value(GObject.TYPE_UINT64, GObject.G_MAXUINT64) + v = GObject.Value(GObject.TYPE_UINT64, GLib.MAXUINT64) rv = self.obj.emit("test-gvalue", v) - self.assertEqual(rv, GObject.G_MAXUINT64) + self.assertEqual(rv, GLib.MAXUINT64) @unittest.expectedFailure # https://bugzilla.gnome.org/show_bug.cgi?id=705291 def test_gvalue_implicit_int64(self): # implicit int64 - rv = self.obj.emit("test-gvalue", GObject.G_MAXINT64) - self.assertEqual(rv, GObject.G_MAXINT64) + rv = self.obj.emit("test-gvalue", GLib.MAXINT64) + self.assertEqual(rv, GLib.MAXINT64) # implicit uint64 - rv = self.obj.emit("test-gvalue", GObject.G_MAXUINT64) - self.assertEqual(rv, GObject.G_MAXUINT64) + rv = self.obj.emit("test-gvalue", GLib.MAXUINT64) + self.assertEqual(rv, GLib.MAXUINT64) def test_gvalue_ret(self): self.assertEqual(self.obj.emit("test-gvalue-ret", GObject.TYPE_INT), - GObject.G_MAXINT) + GLib.MAXINT) self.assertEqual(self.obj.emit("test-gvalue-ret", GObject.TYPE_UINT), - GObject.G_MAXUINT) + GLib.MAXUINT) self.assertEqual(self.obj.emit("test-gvalue-ret", GObject.TYPE_INT64), - GObject.G_MAXINT64) + GLib.MAXINT64) self.assertEqual(self.obj.emit("test-gvalue-ret", GObject.TYPE_UINT64), - GObject.G_MAXUINT64) + GLib.MAXUINT64) self.assertEqual(self.obj.emit("test-gvalue-ret", GObject.TYPE_STRING), "hello") @@ -871,75 +872,75 @@ class _ConnectDataTestBase(object): return callback_args[0] def test_0(self): - obj, value = self.run_connect_test([GObject.G_MAXINT64], user_data=[]) + obj, value = self.run_connect_test([GLib.MAXINT64], user_data=[]) self.assertIsInstance(obj, self.Object) - self.assertEqual(value, GObject.G_MAXINT64) + self.assertEqual(value, GLib.MAXINT64) def test_1(self): - obj, value, data = self.run_connect_test([GObject.G_MAXINT64], + obj, value, data = self.run_connect_test([GLib.MAXINT64], user_data=['mydata']) self.assertIsInstance(obj, self.Object) - self.assertEqual(value, GObject.G_MAXINT64) + self.assertEqual(value, GLib.MAXINT64) self.assertEqual(data, 'mydata') def test_after_0(self): - obj, value = self.run_connect_test([GObject.G_MAXINT64], + obj, value = self.run_connect_test([GLib.MAXINT64], user_data=[], flags=GObject.ConnectFlags.AFTER) self.assertIsInstance(obj, self.Object) - self.assertEqual(value, GObject.G_MAXINT64) + self.assertEqual(value, GLib.MAXINT64) def test_after_1(self): - obj, value, data = self.run_connect_test([GObject.G_MAXINT64], + obj, value, data = self.run_connect_test([GLib.MAXINT64], user_data=['mydata'], flags=GObject.ConnectFlags.AFTER) self.assertIsInstance(obj, self.Object) - self.assertEqual(value, GObject.G_MAXINT64) + self.assertEqual(value, GLib.MAXINT64) self.assertEqual(data, 'mydata') def test_swaped_0(self): # Swapped only works with a single user data argument. with self.assertRaises(ValueError): - self.run_connect_test([GObject.G_MAXINT64], + self.run_connect_test([GLib.MAXINT64], user_data=[], flags=GObject.ConnectFlags.SWAPPED) def test_swaped_1(self): # Notice obj and data are reversed in the return. - data, value, obj = self.run_connect_test([GObject.G_MAXINT64], + data, value, obj = self.run_connect_test([GLib.MAXINT64], user_data=['mydata'], flags=GObject.ConnectFlags.SWAPPED) self.assertIsInstance(obj, self.Object) - self.assertEqual(value, GObject.G_MAXINT64) + self.assertEqual(value, GLib.MAXINT64) self.assertEqual(data, 'mydata') def test_swaped_2(self): # Swapped only works with a single user data argument. with self.assertRaises(ValueError): - self.run_connect_test([GObject.G_MAXINT64], + self.run_connect_test([GLib.MAXINT64], user_data=[1, 2], flags=GObject.ConnectFlags.SWAPPED) def test_after_and_swapped_0(self): # Swapped only works with a single user data argument. with self.assertRaises(ValueError): - self.run_connect_test([GObject.G_MAXINT64], + self.run_connect_test([GLib.MAXINT64], user_data=[], flags=GObject.ConnectFlags.AFTER | GObject.ConnectFlags.SWAPPED) def test_after_and_swapped_1(self): # Notice obj and data are reversed in the return. - data, value, obj = self.run_connect_test([GObject.G_MAXINT64], + data, value, obj = self.run_connect_test([GLib.MAXINT64], user_data=['mydata'], flags=GObject.ConnectFlags.AFTER | GObject.ConnectFlags.SWAPPED) self.assertIsInstance(obj, self.Object) - self.assertEqual(value, GObject.G_MAXINT64) + self.assertEqual(value, GLib.MAXINT64) self.assertEqual(data, 'mydata') def test_after_and_swapped_2(self): # Swapped only works with a single user data argument. with self.assertRaises(ValueError): - self.run_connect_test([GObject.G_MAXINT64], + self.run_connect_test([GLib.MAXINT64], user_data=[], flags=GObject.ConnectFlags.AFTER | GObject.ConnectFlags.SWAPPED) @@ -1129,9 +1130,9 @@ class TestIntrospectedSignals(unittest.TestCase): obj.callback_i = None obj.connect('sig-with-int64-prop', callback) - rv = obj.emit('sig-with-int64-prop', GObject.G_MAXINT64) - self.assertEqual(rv, GObject.G_MAXINT64) - self.assertEqual(obj.callback_i, GObject.G_MAXINT64) + rv = obj.emit('sig-with-int64-prop', GLib.MAXINT64) + self.assertEqual(rv, GLib.MAXINT64) + self.assertEqual(obj.callback_i, GLib.MAXINT64) def test_uint64_param_from_py(self): obj = Regress.TestObj() @@ -1142,9 +1143,9 @@ class TestIntrospectedSignals(unittest.TestCase): obj.callback_i = None obj.connect('sig-with-uint64-prop', callback) - rv = obj.emit('sig-with-uint64-prop', GObject.G_MAXUINT64) - self.assertEqual(rv, GObject.G_MAXUINT64) - self.assertEqual(obj.callback_i, GObject.G_MAXUINT64) + rv = obj.emit('sig-with-uint64-prop', GLib.MAXUINT64) + self.assertEqual(rv, GLib.MAXUINT64) + self.assertEqual(obj.callback_i, GLib.MAXUINT64) def test_int64_param_from_c(self): obj = Regress.TestObj() @@ -1157,7 +1158,7 @@ class TestIntrospectedSignals(unittest.TestCase): obj.connect('sig-with-int64-prop', callback) obj.emit_sig_with_int64() - self.assertEqual(obj.callback_i, GObject.G_MAXINT64) + self.assertEqual(obj.callback_i, GLib.MAXINT64) def test_uint64_param_from_c(self): obj = Regress.TestObj() @@ -1170,7 +1171,7 @@ class TestIntrospectedSignals(unittest.TestCase): obj.connect('sig-with-uint64-prop', callback) obj.emit_sig_with_uint64() - self.assertEqual(obj.callback_i, GObject.G_MAXUINT64) + self.assertEqual(obj.callback_i, GLib.MAXUINT64) def test_intarray_ret(self): obj = Regress.TestObj() @@ -1203,8 +1204,8 @@ class TestIntrospectedSignals(unittest.TestCase): obj.connect('sig-with-array-prop', callback) obj.callback_arr = None - self.assertEqual(obj.emit('sig-with-array-prop', [1, 2, GObject.G_MAXUINT]), None) - self.assertEqual(obj.callback_arr, [1, 2, GObject.G_MAXUINT]) + self.assertEqual(obj.emit('sig-with-array-prop', [1, 2, GLib.MAXUINT]), None) + self.assertEqual(obj.callback_arr, [1, 2, GLib.MAXUINT]) def test_held_struct_ref(self): held_structs = [] @@ -1261,46 +1262,46 @@ class _ConnectObjectTestBase(object): return callback_args[0] def test_0(self): - obj, value = self.run_connect_test([GObject.G_MAXINT64], user_data=[]) + obj, value = self.run_connect_test([GLib.MAXINT64], user_data=[]) self.assertIsInstance(obj, self.SwapObject) - self.assertEqual(value, GObject.G_MAXINT64) + self.assertEqual(value, GLib.MAXINT64) def test_1(self): - obj, value, data = self.run_connect_test([GObject.G_MAXINT64], + obj, value, data = self.run_connect_test([GLib.MAXINT64], user_data=['mydata']) self.assertIsInstance(obj, self.SwapObject) - self.assertEqual(value, GObject.G_MAXINT64) + self.assertEqual(value, GLib.MAXINT64) self.assertEqual(data, 'mydata') def test_2(self): - obj, value, data1, data2 = self.run_connect_test([GObject.G_MAXINT64], + obj, value, data1, data2 = self.run_connect_test([GLib.MAXINT64], user_data=['mydata1', 'mydata2']) self.assertIsInstance(obj, self.SwapObject) - self.assertEqual(value, GObject.G_MAXINT64) + self.assertEqual(value, GLib.MAXINT64) self.assertEqual(data1, 'mydata1') self.assertEqual(data2, 'mydata2') def test_after_0(self): - obj, value = self.run_connect_test([GObject.G_MAXINT64], + obj, value = self.run_connect_test([GLib.MAXINT64], user_data=[], flags=GObject.ConnectFlags.AFTER) self.assertIsInstance(obj, self.SwapObject) - self.assertEqual(value, GObject.G_MAXINT64) + self.assertEqual(value, GLib.MAXINT64) def test_after_1(self): - obj, value, data = self.run_connect_test([GObject.G_MAXINT64], + obj, value, data = self.run_connect_test([GLib.MAXINT64], user_data=['mydata'], flags=GObject.ConnectFlags.AFTER) self.assertIsInstance(obj, self.SwapObject) - self.assertEqual(value, GObject.G_MAXINT64) + self.assertEqual(value, GLib.MAXINT64) self.assertEqual(data, 'mydata') def test_after_2(self): - obj, value, data1, data2 = self.run_connect_test([GObject.G_MAXINT64], + obj, value, data1, data2 = self.run_connect_test([GLib.MAXINT64], user_data=['mydata1', 'mydata2'], flags=GObject.ConnectFlags.AFTER) self.assertIsInstance(obj, self.SwapObject) - self.assertEqual(value, GObject.G_MAXINT64) + self.assertEqual(value, GLib.MAXINT64) self.assertEqual(data1, 'mydata1') self.assertEqual(data2, 'mydata2') diff --git a/tests/test_source.py b/tests/test_source.py index 4c8bcc5..362e5cd 100644 --- a/tests/test_source.py +++ b/tests/test_source.py @@ -4,7 +4,7 @@ import gc import unittest import warnings -from gi.repository import GLib, GObject +from gi.repository import GLib from gi import PyGIDeprecationWarning @@ -138,9 +138,9 @@ class TestSource(unittest.TestCase): self.assertEqual(GLib.source_remove(s), False) # accepts large source IDs (they are unsigned) - self.assertEqual(GLib.source_remove(GObject.G_MAXINT32), False) - self.assertEqual(GLib.source_remove(GObject.G_MAXINT32 + 1), False) - self.assertEqual(GLib.source_remove(GObject.G_MAXUINT32), False) + self.assertEqual(GLib.source_remove(GLib.MAXINT32), False) + self.assertEqual(GLib.source_remove(GLib.MAXINT32 + 1), False) + self.assertEqual(GLib.source_remove(GLib.MAXUINT32), False) finally: GLib.log_set_always_fatal(old_mask) diff --git a/tests/test_subprocess.py b/tests/test_subprocess.py index 720c950..fac54c9 100644 --- a/tests/test_subprocess.py +++ b/tests/test_subprocess.py @@ -149,5 +149,8 @@ class TestProcess(unittest.TestCase): self.assertEqual(out, b'moo!\n') def test_backwards_compat_flags(self): - self.assertEqual(GLib.SpawnFlags.DO_NOT_REAP_CHILD, - GLib.SPAWN_DO_NOT_REAP_CHILD) + with warnings.catch_warnings(): + warnings.simplefilter('ignore', PyGIDeprecationWarning) + + self.assertEqual(GLib.SpawnFlags.DO_NOT_REAP_CHILD, + GLib.SPAWN_DO_NOT_REAP_CHILD) diff --git a/tests/testmodule.py b/tests/testmodule.py index 3da8ed5..c083f62 100644 --- a/tests/testmodule.py +++ b/tests/testmodule.py @@ -7,7 +7,8 @@ class PyGObject(GObject.GObject): 'label': (GObject.TYPE_STRING, 'label property', 'the label of the object', - 'default', GObject.PARAM_READWRITE), + 'default', + GObject.ParamFlags.READABLE | GObject.ParamFlags.WRITABLE), } def __init__(self): -- cgit v1.2.3