diff options
author | DongHun Kwak <dh0128.kwak@samsung.com> | 2017-07-12 08:39:52 +0900 |
---|---|---|
committer | DongHun Kwak <dh0128.kwak@samsung.com> | 2017-07-12 08:39:56 +0900 |
commit | e07365f4dc795d095792cf947463f36cbf5e3e81 (patch) | |
tree | e0a41526f9551cc8ac5877098f905d8422d0a934 /tests | |
parent | dacff02c31708d5a702fbbeb7f386be1bbb8918e (diff) | |
download | pygobject2-e07365f4dc795d095792cf947463f36cbf5e3e81.tar.gz pygobject2-e07365f4dc795d095792cf947463f36cbf5e3e81.tar.bz2 pygobject2-e07365f4dc795d095792cf947463f36cbf5e3e81.zip |
Imported Upstream version 3.11.2
Change-Id: I8f6e5a4eb6b3139ed997f6421e264e1675663e36
Signed-off-by: DongHun Kwak <dh0128.kwak@samsung.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile.in | 197 | ||||
-rw-r--r-- | tests/test_gi.py | 85 | ||||
-rw-r--r-- | tests/test_overrides_gdk.py | 17 | ||||
-rw-r--r-- | tests/test_overrides_gtk.py | 209 |
4 files changed, 291 insertions, 217 deletions
diff --git a/tests/Makefile.in b/tests/Makefile.in index fc936c6..b034f67 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -1,8 +1,9 @@ -# Makefile.in generated by automake 1.13.3 from Makefile.am. +# Makefile.in generated by automake 1.11.6 from Makefile.am. # @configure_input@ -# Copyright (C) 1994-2013 Free Software Foundation, Inc. - +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software +# Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. @@ -14,51 +15,23 @@ @SET_MAKE@ VPATH = @srcdir@ -am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)' -am__make_running_with_option = \ - case $${target_option-} in \ - ?) ;; \ - *) echo "am__make_running_with_option: internal error: invalid" \ - "target option '$${target_option-}' specified" >&2; \ - exit 1;; \ - esac; \ - has_opt=no; \ - sane_makeflags=$$MAKEFLAGS; \ - if $(am__is_gnu_make); then \ - sane_makeflags=$$MFLAGS; \ - else \ +am__make_dryrun = \ + { \ + am__dry=no; \ case $$MAKEFLAGS in \ *\\[\ \ ]*) \ - bs=\\; \ - sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ - | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ - esac; \ - fi; \ - skip_next=no; \ - strip_trailopt () \ - { \ - flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ - }; \ - for flg in $$sane_makeflags; do \ - test $$skip_next = yes && { skip_next=no; continue; }; \ - case $$flg in \ - *=*|--*) continue;; \ - -*I) strip_trailopt 'I'; skip_next=yes;; \ - -*I?*) strip_trailopt 'I';; \ - -*O) strip_trailopt 'O'; skip_next=yes;; \ - -*O?*) strip_trailopt 'O';; \ - -*l) strip_trailopt 'l'; skip_next=yes;; \ - -*l?*) strip_trailopt 'l';; \ - -[dEDm]) skip_next=yes;; \ - -[JT]) skip_next=yes;; \ - esac; \ - case $$flg in \ - *$$target_option*) has_opt=yes; break;; \ + echo 'am--echo: ; @echo "AM" OK' | $(MAKE) -f - 2>/dev/null \ + | grep '^AM OK$$' >/dev/null || am__dry=yes;; \ + *) \ + for am__flg in $$MAKEFLAGS; do \ + case $$am__flg in \ + *=*|--*) ;; \ + *n*) am__dry=yes; break;; \ + esac; \ + done;; \ esac; \ - done; \ - test $$has_opt = yes -am__make_dryrun = (target_option=n; $(am__make_running_with_option)) -am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) + test $$am__dry = yes; \ + } pkgdatadir = $(datadir)/@PACKAGE@ pkgincludedir = $(includedir)/@PACKAGE@ pkglibdir = $(libdir)/@PACKAGE@ @@ -82,8 +55,7 @@ host_triplet = @host@ @ENABLE_CAIRO_TRUE@am__append_1 = libregress.la @ENABLE_CAIRO_TRUE@am__append_2 = Regress-1.0.typelib subdir = tests -DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \ - $(top_srcdir)/depcomp +DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/as-ac-expand.m4 \ $(top_srcdir)/m4/jhflags.m4 $(top_srcdir)/m4/libtool.m4 \ @@ -104,7 +76,6 @@ libgimarshallingtests_la_OBJECTS = \ AM_V_lt = $(am__v_lt_@AM_V@) am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) am__v_lt_0 = --silent -am__v_lt_1 = libgimarshallingtests_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \ $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \ $(libgimarshallingtests_la_CFLAGS) $(CFLAGS) \ @@ -126,18 +97,6 @@ testhelper_la_OBJECTS = $(am_testhelper_la_OBJECTS) testhelper_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(testhelper_la_CFLAGS) \ $(CFLAGS) $(testhelper_la_LDFLAGS) $(LDFLAGS) -o $@ -AM_V_P = $(am__v_P_@AM_V@) -am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) -am__v_P_0 = false -am__v_P_1 = : -AM_V_GEN = $(am__v_GEN_@AM_V@) -am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@) -am__v_GEN_0 = @echo " GEN " $@; -am__v_GEN_1 = -AM_V_at = $(am__v_at_@AM_V@) -am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) -am__v_at_0 = @ -am__v_at_1 = DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) depcomp = $(SHELL) $(top_srcdir)/depcomp am__depfiles_maybe = depfiles @@ -150,16 +109,20 @@ LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(AM_CFLAGS) $(CFLAGS) AM_V_CC = $(am__v_CC_@AM_V@) am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@) -am__v_CC_0 = @echo " CC " $@; -am__v_CC_1 = +am__v_CC_0 = @echo " CC " $@; +AM_V_at = $(am__v_at_@AM_V@) +am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) +am__v_at_0 = @ CCLD = $(CC) LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(AM_LDFLAGS) $(LDFLAGS) -o $@ AM_V_CCLD = $(am__v_CCLD_@AM_V@) am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@) -am__v_CCLD_0 = @echo " CCLD " $@; -am__v_CCLD_1 = +am__v_CCLD_0 = @echo " CCLD " $@; +AM_V_GEN = $(am__v_GEN_@AM_V@) +am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@) +am__v_GEN_0 = @echo " GEN " $@; SOURCES = $(nodist_libgimarshallingtests_la_SOURCES) \ $(nodist_libregress_la_SOURCES) $(testhelper_la_SOURCES) DIST_SOURCES = $(testhelper_la_SOURCES) @@ -168,23 +131,6 @@ am__can_run_installinfo = \ n|no|NO) false;; \ *) (install-info --version) >/dev/null 2>&1;; \ esac -am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) -# Read a list of newline-separated strings from the standard input, -# and print each of them once, without duplicates. Input order is -# *not* preserved. -am__uniquify_input = $(AWK) '\ - BEGIN { nonempty = 0; } \ - { items[$$0] = 1; nonempty = 1; } \ - END { if (nonempty) { for (i in items) print i; }; } \ -' -# Make sure the list of sources is unique. This is necessary because, -# e.g., the same source file might be shared among _SOURCES variables -# for different programs/libraries. -am__define_uniq_tagged_files = \ - list='$(am__tagged_files)'; \ - unique=`for i in $$list; do \ - if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ - done | $(am__uniquify_input)` ETAGS = etags CTAGS = ctags DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) @@ -465,15 +411,12 @@ $(am__aclocal_m4_deps): clean-checkLTLIBRARIES: -test -z "$(check_LTLIBRARIES)" || rm -f $(check_LTLIBRARIES) - @list='$(check_LTLIBRARIES)'; \ - locs=`for p in $$list; do echo $$p; done | \ - sed 's|^[^/]*$$|.|; s|/[^/]*$$||; s|$$|/so_locations|' | \ - sort -u`; \ - test -z "$$locs" || { \ - echo rm -f $${locs}; \ - rm -f $${locs}; \ - } - + @list='$(check_LTLIBRARIES)'; for p in $$list; do \ + dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ + test "$$dir" != "$$p" || dir=.; \ + echo "rm -f \"$${dir}/so_locations\""; \ + rm -f "$${dir}/so_locations"; \ + done @ENABLE_CAIRO_FALSE@libregress.la: $(libregress_la_OBJECTS) $(libregress_la_DEPENDENCIES) $(EXTRA_libregress_la_DEPENDENCIES) @ENABLE_CAIRO_FALSE@ $(AM_V_CCLD)$(libregress_la_LINK) $(am_libregress_la_rpath) $(libregress_la_OBJECTS) $(libregress_la_LIBADD) $(LIBS) @@ -559,15 +502,26 @@ mostlyclean-libtool: clean-libtool: -rm -rf .libs _libs -ID: $(am__tagged_files) - $(am__define_uniq_tagged_files); mkid -fID $$unique -tags: tags-am -TAGS: tags - -tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) set x; \ here=`pwd`; \ - $(am__define_uniq_tagged_files); \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ shift; \ if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ test -n "$$unique" || unique=$$empty_fix; \ @@ -579,11 +533,15 @@ tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) $$unique; \ fi; \ fi -ctags: ctags-am - -CTAGS: ctags -ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) - $(am__define_uniq_tagged_files); \ +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in files) print i; }; }'`; \ test -z "$(CTAGS_ARGS)$$unique" \ || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ $$unique @@ -592,21 +550,6 @@ GTAGS: here=`$(am__cd) $(top_builddir) && pwd` \ && $(am__cd) $(top_srcdir) \ && gtags -i $(GTAGS_ARGS) "$$here" -cscopelist: cscopelist-am - -cscopelist-am: $(am__tagged_files) - list='$(am__tagged_files)'; \ - case "$(srcdir)" in \ - [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ - *) sdir=$(subdir)/$(srcdir) ;; \ - esac; \ - for i in $$list; do \ - if test -f "$$i"; then \ - echo "$(subdir)/$$i"; \ - else \ - echo "$$sdir/$$i"; \ - fi; \ - done >> $(top_builddir)/cscope.files distclean-tags: -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags @@ -751,19 +694,19 @@ uninstall-am: .MAKE: check-am install-am install-strip -.PHONY: CTAGS GTAGS TAGS all all-am check check-am check-local clean \ +.PHONY: CTAGS GTAGS all all-am check check-am check-local clean \ clean-checkLTLIBRARIES clean-generic clean-libtool clean-local \ - cscopelist-am ctags ctags-am distclean distclean-compile \ - distclean-generic distclean-libtool distclean-tags distdir dvi \ - dvi-am html html-am info info-am install install-am \ - install-data install-data-am install-dvi install-dvi-am \ - install-exec install-exec-am install-html install-html-am \ - install-info install-info-am install-man install-pdf \ - install-pdf-am install-ps install-ps-am install-strip \ - installcheck installcheck-am installdirs maintainer-clean \ + ctags distclean distclean-compile distclean-generic \ + distclean-libtool distclean-tags distdir dvi dvi-am html \ + html-am info info-am install install-am install-data \ + install-data-am install-dvi install-dvi-am install-exec \ + install-exec-am install-html install-html-am install-info \ + install-info-am install-man install-pdf install-pdf-am \ + install-ps install-ps-am install-strip installcheck \ + installcheck-am installdirs maintainer-clean \ maintainer-clean-generic mostlyclean mostlyclean-compile \ mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ - tags tags-am uninstall uninstall-am + tags uninstall uninstall-am # This is a hack to make sure a shared library is built diff --git a/tests/test_gi.py b/tests/test_gi.py index 43c226e..f7a7bc6 100644 --- a/tests/test_gi.py +++ b/tests/test_gi.py @@ -16,6 +16,8 @@ import warnings from io import StringIO, BytesIO import gi +import gi.overrides +from gi import PyGIDeprecationWarning from gi.repository import GObject, GLib, Gio from gi.repository import GIMarshallingTests @@ -2907,6 +2909,16 @@ class TestPropertiesObject(unittest.TestCase): self.assertTrue('some_double' in props) self.assertTrue('some_variant' in props) + def test_param_spec_dir(self): + attrs = dir(GIMarshallingTests.PropertiesObject.props.some_float) + self.assertTrue('name' in attrs) + self.assertTrue('nick' in attrs) + self.assertTrue('blurb' in attrs) + self.assertTrue('flags' in attrs) + self.assertTrue('default_value' in attrs) + self.assertTrue('minimum' in attrs) + self.assertTrue('maximum' in attrs) + class TestKeywords(unittest.TestCase): def test_method(self): @@ -2990,3 +3002,76 @@ class TestDeprecation(unittest.TestCase): warnings.simplefilter('always') d.set_time(1) self.assertTrue(issubclass(warn[0].category, DeprecationWarning)) + + def test_deprecated_init_no_keywords(self): + def init(self, **kwargs): + self.assertDictEqual(kwargs, {'a': 1, 'b': 2, 'c': 3}) + + fn = gi.overrides.deprecated_init(init, arg_names=('a', 'b', 'c')) + with warnings.catch_warnings(record=True) as warn: + warnings.simplefilter('always') + fn(self, 1, 2, 3) + self.assertEqual(len(warn), 1) + self.assertTrue(issubclass(warn[0].category, PyGIDeprecationWarning)) + self.assertRegexpMatches(str(warn[0].message), + '.*keywords.*a, b, c.*') + + def test_deprecated_init_no_keywords_out_of_order(self): + def init(self, **kwargs): + self.assertDictEqual(kwargs, {'a': 1, 'b': 2, 'c': 3}) + + fn = gi.overrides.deprecated_init(init, arg_names=('b', 'a', 'c')) + with warnings.catch_warnings(record=True) as warn: + warnings.simplefilter('always') + fn(self, 2, 1, 3) + self.assertEqual(len(warn), 1) + self.assertTrue(issubclass(warn[0].category, PyGIDeprecationWarning)) + self.assertRegexpMatches(str(warn[0].message), + '.*keywords.*b, a, c.*') + + def test_deprecated_init_ignored_keyword(self): + def init(self, **kwargs): + self.assertDictEqual(kwargs, {'a': 1, 'c': 3}) + + fn = gi.overrides.deprecated_init(init, + arg_names=('a', 'b', 'c'), + ignore=('b',)) + with warnings.catch_warnings(record=True) as warn: + warnings.simplefilter('always') + fn(self, 1, 2, 3) + self.assertEqual(len(warn), 1) + self.assertTrue(issubclass(warn[0].category, PyGIDeprecationWarning)) + self.assertRegexpMatches(str(warn[0].message), + '.*keywords.*a, b, c.*') + + def test_deprecated_init_with_aliases(self): + def init(self, **kwargs): + self.assertDictEqual(kwargs, {'a': 1, 'b': 2, 'c': 3}) + + fn = gi.overrides.deprecated_init(init, + arg_names=('a', 'b', 'c'), + deprecated_aliases={'b': 'bb', 'c': 'cc'}) + with warnings.catch_warnings(record=True) as warn: + warnings.simplefilter('always') + + fn(self, a=1, bb=2, cc=3) + self.assertEqual(len(warn), 1) + self.assertTrue(issubclass(warn[0].category, PyGIDeprecationWarning)) + self.assertRegexpMatches(str(warn[0].message), + '.*keyword.*"bb, cc".*deprecated.*"b, c" respectively') + + def test_deprecated_init_with_defaults(self): + def init(self, **kwargs): + self.assertDictEqual(kwargs, {'a': 1, 'b': 2, 'c': 3}) + + fn = gi.overrides.deprecated_init(init, + arg_names=('a', 'b', 'c'), + deprecated_defaults={'b': 2, 'c': 3}) + with warnings.catch_warnings(record=True) as warn: + warnings.simplefilter('always') + fn(self, a=1) + self.assertEqual(len(warn), 1) + self.assertTrue(issubclass(warn[0].category, PyGIDeprecationWarning)) + self.assertRegexpMatches(str(warn[0].message), + '.*relying on deprecated non-standard defaults.*' + 'explicitly use: b=2, c=3') diff --git a/tests/test_overrides_gdk.py b/tests/test_overrides_gdk.py index 46f0a38..648597e 100644 --- a/tests/test_overrides_gdk.py +++ b/tests/test_overrides_gdk.py @@ -2,8 +2,10 @@ # vim: tabstop=4 shiftwidth=4 expandtab import unittest +import warnings import gi.overrides +from gi import PyGIDeprecationWarning try: from gi.repository import Gdk, GdkPixbuf, Gtk @@ -111,11 +113,18 @@ class TestGdk(unittest.TestCase): 5, 10) - c = Gdk.Cursor(display, - test_pixbuf, - y=0, x=0) + with warnings.catch_warnings(record=True) as warn: + warnings.simplefilter('always') + c = Gdk.Cursor(display, + test_pixbuf, + y=0, x=0) + self.assertNotEqual(c, None) + + self.assertEqual(len(warn), 1) + self.assertTrue(issubclass(warn[0].category, PyGIDeprecationWarning)) + self.assertRegexpMatches(str(warn[0].message), + '.*new_from_pixbuf.*') - self.assertNotEqual(c, None) self.assertRaises(ValueError, Gdk.Cursor, 1, 2, 3) def test_flags(self): diff --git a/tests/test_overrides_gtk.py b/tests/test_overrides_gtk.py index fd97908..4ace879 100644 --- a/tests/test_overrides_gtk.py +++ b/tests/test_overrides_gtk.py @@ -6,6 +6,7 @@ import contextlib import unittest import time import sys +import warnings from compathelper import _unicode, _bytes @@ -16,8 +17,10 @@ from gi.repository import GLib, GObject try: from gi.repository import GdkPixbuf, Gdk, Gtk Gtk # pyflakes + PyGTKDeprecationWarning = Gtk.PyGTKDeprecationWarning except ImportError: Gtk = None + PyGTKDeprecationWarning = None @contextlib.contextmanager @@ -73,16 +76,14 @@ class TestGtk(unittest.TestCase): def test_actions(self): self.assertEqual(Gtk.Action, gi.overrides.Gtk.Action) - self.assertRaises(TypeError, Gtk.Action) - action = Gtk.Action("test", "Test", "Test Action", Gtk.STOCK_COPY) + action = Gtk.Action(name="test", label="Test", tooltip="Test Action", stock_id=Gtk.STOCK_COPY) self.assertEqual(action.get_name(), "test") self.assertEqual(action.get_label(), "Test") self.assertEqual(action.get_tooltip(), "Test Action") self.assertEqual(action.get_stock_id(), Gtk.STOCK_COPY) self.assertEqual(Gtk.RadioAction, gi.overrides.Gtk.RadioAction) - self.assertRaises(TypeError, Gtk.RadioAction) - action = Gtk.RadioAction("test", "Test", "Test Action", Gtk.STOCK_COPY, 1) + action = Gtk.RadioAction(name="test", label="Test", tooltip="Test Action", stock_id=Gtk.STOCK_COPY, value=1) self.assertEqual(action.get_name(), "test") self.assertEqual(action.get_label(), "Test") self.assertEqual(action.get_tooltip(), "Test Action") @@ -91,7 +92,6 @@ class TestGtk(unittest.TestCase): def test_actiongroup(self): self.assertEqual(Gtk.ActionGroup, gi.overrides.Gtk.ActionGroup) - self.assertRaises(TypeError, Gtk.ActionGroup) action_group = Gtk.ActionGroup(name='TestActionGroup') callback_data = "callback data" @@ -165,10 +165,6 @@ class TestGtk(unittest.TestCase): w = Gtk.Window(type=Gtk.WindowType.POPUP) self.assertEqual(w.get_property('type'), Gtk.WindowType.POPUP) - # pygtk compatible positional argument - w = Gtk.Window(Gtk.WindowType.POPUP) - self.assertEqual(w.get_property('type'), Gtk.WindowType.POPUP) - class TestWindow(Gtk.Window): __gtype_name__ = "TestWindow" @@ -192,26 +188,80 @@ class TestGtk(unittest.TestCase): self.assertEqual(builder.get_object('testpop').get_property('type'), Gtk.WindowType.POPUP) - def test_dialogs(self): + def test_dialog_classes(self): self.assertEqual(Gtk.Dialog, gi.overrides.Gtk.Dialog) - self.assertEqual(Gtk.AboutDialog, gi.overrides.Gtk.AboutDialog) - self.assertEqual(Gtk.MessageDialog, gi.overrides.Gtk.MessageDialog) self.assertEqual(Gtk.ColorSelectionDialog, gi.overrides.Gtk.ColorSelectionDialog) self.assertEqual(Gtk.FileChooserDialog, gi.overrides.Gtk.FileChooserDialog) self.assertEqual(Gtk.FontSelectionDialog, gi.overrides.Gtk.FontSelectionDialog) self.assertEqual(Gtk.RecentChooserDialog, gi.overrides.Gtk.RecentChooserDialog) - # Gtk.Dialog - dialog = Gtk.Dialog(title='Foo', - flags=Gtk.DialogFlags.MODAL, - buttons=('test-button1', 1)) + def test_dialog_base(self): + dialog = Gtk.Dialog(title='Foo', modal=True) self.assertTrue(isinstance(dialog, Gtk.Dialog)) self.assertTrue(isinstance(dialog, Gtk.Window)) - - dialog.add_buttons('test-button2', 2, Gtk.STOCK_CLOSE, Gtk.ResponseType.CLOSE) - self.assertEqual('Foo', dialog.get_title()) self.assertTrue(dialog.get_modal()) + + def test_dialog_deprecations(self): + with warnings.catch_warnings(record=True) as warn: + warnings.simplefilter('always') + dialog = Gtk.Dialog(title='Foo', flags=Gtk.DialogFlags.MODAL) + self.assertTrue(dialog.get_modal()) + self.assertEqual(len(warn), 1) + self.assertTrue(issubclass(warn[0].category, PyGTKDeprecationWarning)) + self.assertRegexpMatches(str(warn[0].message), + '.*flags.*modal.*') + + with warnings.catch_warnings(record=True) as warn: + warnings.simplefilter('always') + dialog = Gtk.Dialog(title='Foo', flags=Gtk.DialogFlags.DESTROY_WITH_PARENT) + self.assertTrue(dialog.get_destroy_with_parent()) + self.assertEqual(len(warn), 1) + self.assertTrue(issubclass(warn[0].category, PyGTKDeprecationWarning)) + self.assertRegexpMatches(str(warn[0].message), + '.*flags.*destroy_with_parent.*') + + def test_dialog_deprecation_stacklevels(self): + # Test warning levels are setup to give the correct filename for + # deprecations in different classes in the inheritance hierarchy. + + # Base class + self.assertEqual(Gtk.Dialog, gi.overrides.Gtk.Dialog) + with warnings.catch_warnings(record=True) as warn: + warnings.simplefilter('always') + Gtk.Dialog(flags=Gtk.DialogFlags.MODAL) + self.assertEqual(len(warn), 1) + self.assertRegexpMatches(warn[0].filename, '.*test_overrides_gtk.*') + + # Validate overridden base with overridden sub-class. + self.assertEqual(Gtk.MessageDialog, gi.overrides.Gtk.MessageDialog) + with warnings.catch_warnings(record=True) as warn: + warnings.simplefilter('always') + Gtk.MessageDialog(flags=Gtk.DialogFlags.MODAL) + self.assertEqual(len(warn), 1) + self.assertRegexpMatches(warn[0].filename, '.*test_overrides_gtk.*') + + # Validate overridden base with non-overridden sub-class. + self.assertEqual(Gtk.AboutDialog, gi.repository.Gtk.AboutDialog) + with warnings.catch_warnings(record=True) as warn: + warnings.simplefilter('always') + Gtk.AboutDialog(flags=Gtk.DialogFlags.MODAL) + self.assertEqual(len(warn), 1) + self.assertRegexpMatches(warn[0].filename, '.*test_overrides_gtk.*') + + def test_dialog_add_buttons(self): + # The overloaded "buttons" keyword gives a warning when attempting + # to use it for adding buttons as was available in PyGTK. + with warnings.catch_warnings(record=True) as warn: + warnings.simplefilter('always') + dialog = Gtk.Dialog(title='Foo', modal=True, + buttons=('test-button1', 1)) + self.assertEqual(len(warn), 1) + self.assertTrue(issubclass(warn[0].category, PyGTKDeprecationWarning)) + self.assertRegexpMatches(str(warn[0].message), + '.*ButtonsType.*add_buttons.*') + + dialog.add_buttons('test-button2', 2, Gtk.STOCK_CLOSE, Gtk.ResponseType.CLOSE) button = dialog.get_widget_for_response(1) self.assertEqual('test-button1', button.get_label()) button = dialog.get_widget_for_response(2) @@ -219,16 +269,20 @@ class TestGtk(unittest.TestCase): button = dialog.get_widget_for_response(Gtk.ResponseType.CLOSE) self.assertEqual(Gtk.STOCK_CLOSE, button.get_label()) - # Gtk.AboutDialog + def test_about_dialog(self): dialog = Gtk.AboutDialog() self.assertTrue(isinstance(dialog, Gtk.Dialog)) self.assertTrue(isinstance(dialog, Gtk.Window)) - # Gtk.MessageDialog + # AboutDialog is not sub-classed in overrides, make sure + # the mro still injects the base class "add_buttons" override. + self.assertTrue(hasattr(dialog, 'add_buttons')) + + def test_message_dialog(self): dialog = Gtk.MessageDialog(title='message dialog test', - flags=Gtk.DialogFlags.MODAL, + modal=True, buttons=Gtk.ButtonsType.OK, - message_format='dude!') + text='dude!') self.assertTrue(isinstance(dialog, Gtk.Dialog)) self.assertTrue(isinstance(dialog, Gtk.Window)) @@ -245,58 +299,53 @@ class TestGtk(unittest.TestCase): self.assertEqual(dialog.get_property('secondary-text'), '2nd markup') self.assertTrue(dialog.get_property('secondary-use-markup')) - # Gtk.ColorSelectionDialog - dialog = Gtk.ColorSelectionDialog("color selection dialog test") + def test_color_selection_dialog(self): + dialog = Gtk.ColorSelectionDialog(title="color selection dialog test") self.assertTrue(isinstance(dialog, Gtk.Dialog)) self.assertTrue(isinstance(dialog, Gtk.Window)) self.assertEqual('color selection dialog test', dialog.get_title()) - # Gtk.FileChooserDialog + def test_file_chooser_dialog(self): # might cause a GVFS warning, do not break on this old_mask = GLib.log_set_always_fatal( GLib.LogLevelFlags.LEVEL_CRITICAL | GLib.LogLevelFlags.LEVEL_ERROR) try: dialog = Gtk.FileChooserDialog(title='file chooser dialog test', - buttons=('test-button1', 1), action=Gtk.FileChooserAction.SAVE) finally: GLib.log_set_always_fatal(old_mask) self.assertTrue(isinstance(dialog, Gtk.Dialog)) self.assertTrue(isinstance(dialog, Gtk.Window)) - - dialog.add_buttons('test-button2', 2, Gtk.STOCK_CLOSE, Gtk.ResponseType.CLOSE) self.assertEqual('file chooser dialog test', dialog.get_title()) - button = dialog.get_widget_for_response(1) - self.assertEqual('test-button1', button.get_label()) - button = dialog.get_widget_for_response(2) - self.assertEqual('test-button2', button.get_label()) - button = dialog.get_widget_for_response(Gtk.ResponseType.CLOSE) - self.assertEqual(Gtk.STOCK_CLOSE, button.get_label()) + action = dialog.get_property('action') self.assertEqual(Gtk.FileChooserAction.SAVE, action) - # Gtk.FontSelectionDialog - dialog = Gtk.ColorSelectionDialog("font selection dialog test") + def test_file_chooser_dialog_default_action(self): + # might cause a GVFS warning, do not break on this + old_mask = GLib.log_set_always_fatal( + GLib.LogLevelFlags.LEVEL_CRITICAL | GLib.LogLevelFlags.LEVEL_ERROR) + try: + dialog = Gtk.FileChooserDialog(title='file chooser dialog test') + finally: + GLib.log_set_always_fatal(old_mask) + + action = dialog.get_property('action') + self.assertEqual(Gtk.FileChooserAction.OPEN, action) + + def test_font_selection_dialog(self): + dialog = Gtk.FontSelectionDialog(title="font selection dialog test") self.assertTrue(isinstance(dialog, Gtk.Dialog)) self.assertTrue(isinstance(dialog, Gtk.Window)) self.assertEqual('font selection dialog test', dialog.get_title()) - # Gtk.RecentChooserDialog + def test_recent_chooser_dialog(self): test_manager = Gtk.RecentManager() dialog = Gtk.RecentChooserDialog(title='recent chooser dialog test', - buttons=('test-button1', 1), - manager=test_manager) + recent_manager=test_manager) self.assertTrue(isinstance(dialog, Gtk.Dialog)) self.assertTrue(isinstance(dialog, Gtk.Window)) - - dialog.add_buttons('test-button2', 2, Gtk.STOCK_CLOSE, Gtk.ResponseType.CLOSE) self.assertEqual('recent chooser dialog test', dialog.get_title()) - button = dialog.get_widget_for_response(1) - self.assertEqual('test-button1', button.get_label()) - button = dialog.get_widget_for_response(2) - self.assertEqual('test-button2', button.get_label()) - button = dialog.get_widget_for_response(Gtk.ResponseType.CLOSE) - self.assertEqual(Gtk.STOCK_CLOSE, button.get_label()) class TestClass(GObject.GObject): __gtype_name__ = "GIOverrideTreeAPITest" @@ -319,7 +368,7 @@ class TestGtk(unittest.TestCase): self.assertTrue(isinstance(button, Gtk.Button)) self.assertTrue(isinstance(button, Gtk.Container)) self.assertTrue(isinstance(button, Gtk.Widget)) - button = Gtk.Button(stock=Gtk.STOCK_CLOSE) + button = Gtk.Button.new_from_stock(Gtk.STOCK_CLOSE) self.assertEqual(Gtk.STOCK_CLOSE, button.get_label()) self.assertTrue(button.get_use_stock()) self.assertTrue(button.get_use_underline()) @@ -331,8 +380,7 @@ class TestGtk(unittest.TestCase): self.assertTrue(button.get_use_underline()) # test Gtk.LinkButton - self.assertRaises(TypeError, Gtk.LinkButton) - button = Gtk.LinkButton('http://www.Gtk.org', 'Gtk') + button = Gtk.LinkButton(uri='http://www.Gtk.org', label='Gtk') self.assertTrue(isinstance(button, Gtk.Button)) self.assertTrue(isinstance(button, Gtk.Container)) self.assertTrue(isinstance(button, Gtk.Widget)) @@ -392,25 +440,21 @@ class TestGtk(unittest.TestCase): self.assertEqual(adjustment.get_page_size(), page_size) def test_adjustment(self): - adjustment = Gtk.Adjustment(1, 0, 6, 4, 5, 3) - self.adjustment_check(adjustment, 1, 0, 6, 4, 5, 3) + adjustment = Gtk.Adjustment(value=1, lower=0, upper=6, step_increment=4, page_increment=5, page_size=3) + self.adjustment_check(adjustment, value=1, lower=0, upper=6, step_increment=4, page_increment=5, page_size=3) - adjustment = Gtk.Adjustment(1, 0, 6, 4, 5) - self.adjustment_check(adjustment, 1, 0, 6, 4, 5) + adjustment = Gtk.Adjustment(value=1, lower=0, upper=6, step_increment=4, page_increment=5) + self.adjustment_check(adjustment, value=1, lower=0, upper=6, step_increment=4, page_increment=5) - adjustment = Gtk.Adjustment(1, 0, 6, 4) - self.adjustment_check(adjustment, 1, 0, 6, 4) + adjustment = Gtk.Adjustment(value=1, lower=0, upper=6, step_increment=4) + self.adjustment_check(adjustment, value=1, lower=0, upper=6, step_increment=4) - adjustment = Gtk.Adjustment(1, 0, 6) - self.adjustment_check(adjustment, 1, 0, 6) + adjustment = Gtk.Adjustment(value=1, lower=0, upper=6) + self.adjustment_check(adjustment, value=1, lower=0, upper=6) adjustment = Gtk.Adjustment() self.adjustment_check(adjustment) - adjustment = Gtk.Adjustment(value=1, lower=0, upper=6, - step_increment=4, page_increment=5, page_size=3) - self.adjustment_check(adjustment, 1, 0, 6, 4, 5, 3) - def test_table(self): table = Gtk.Table() self.assertTrue(isinstance(table, Gtk.Table)) @@ -418,17 +462,11 @@ class TestGtk(unittest.TestCase): self.assertTrue(isinstance(table, Gtk.Widget)) self.assertEqual(table.get_size(), (1, 1)) self.assertEqual(table.get_homogeneous(), False) - table = Gtk.Table(2, 3) + + table = Gtk.Table(n_rows=2, n_columns=3) self.assertEqual(table.get_size(), (2, 3)) self.assertEqual(table.get_homogeneous(), False) - table = Gtk.Table(2, 3, True) - self.assertEqual(table.get_size(), (2, 3)) - self.assertEqual(table.get_homogeneous(), True) - # Test PyGTK interface - table = Gtk.Table(rows=3, columns=2) - self.assertEqual(table.get_size(), (3, 2)) - # Test using the actual property names table = Gtk.Table(n_rows=2, n_columns=3, homogeneous=True) self.assertEqual(table.get_size(), (2, 3)) self.assertEqual(table.get_homogeneous(), True) @@ -522,7 +560,6 @@ class TestGtk(unittest.TestCase): Gdk.DragAction.DEFAULT | Gdk.DragAction.MOVE) def test_scrollbar(self): - # PyGTK compat adjustment = Gtk.Adjustment() hscrollbar = Gtk.HScrollbar() @@ -530,8 +567,8 @@ class TestGtk(unittest.TestCase): self.assertNotEqual(hscrollbar.props.adjustment, adjustment) self.assertNotEqual(vscrollbar.props.adjustment, adjustment) - hscrollbar = Gtk.HScrollbar(adjustment) - vscrollbar = Gtk.VScrollbar(adjustment) + hscrollbar = Gtk.HScrollbar(adjustment=adjustment) + vscrollbar = Gtk.VScrollbar(adjustment=adjustment) self.assertEqual(hscrollbar.props.adjustment, adjustment) self.assertEqual(vscrollbar.props.adjustment, adjustment) @@ -541,7 +578,7 @@ class TestGtk(unittest.TestCase): self.assertEqual(iconview.props.model, None) model = Gtk.ListStore(str) - iconview = Gtk.IconView(model) + iconview = Gtk.IconView(model=model) self.assertEqual(iconview.props.model, model) def test_toolbutton(self): @@ -549,7 +586,7 @@ class TestGtk(unittest.TestCase): button = Gtk.ToolButton() self.assertEqual(button.props.stock_id, None) - button = Gtk.ToolButton('gtk-new') + button = Gtk.ToolButton(stock_id='gtk-new') self.assertEqual(button.props.stock_id, 'gtk-new') icon = Gtk.Image.new_from_stock(Gtk.STOCK_OPEN, Gtk.IconSize.SMALL_TOOLBAR) @@ -559,13 +596,11 @@ class TestGtk(unittest.TestCase): self.assertEqual(button.props.icon_widget, icon) def test_iconset(self): - # PyGTK compat Gtk.IconSet() pixbuf = GdkPixbuf.Pixbuf() - Gtk.IconSet(pixbuf) + Gtk.IconSet.new_from_pixbuf(pixbuf) def test_viewport(self): - # PyGTK compat vadjustment = Gtk.Adjustment() hadjustment = Gtk.Adjustment() @@ -758,9 +793,8 @@ class TestBuilder(unittest.TestCase): class TestTreeModel(unittest.TestCase): def test_tree_model_sort(self): self.assertEqual(Gtk.TreeModelSort, gi.overrides.Gtk.TreeModelSort) - self.assertRaises(TypeError, Gtk.TreeModelSort) model = Gtk.TreeStore(int, bool) - model_sort = Gtk.TreeModelSort(model) + model_sort = Gtk.TreeModelSort(model=model) self.assertEqual(model_sort.get_model(), model) def test_tree_store(self): @@ -1565,10 +1599,13 @@ class TestTreeView(unittest.TestCase): def test_tree_view_column(self): cell = Gtk.CellRendererText() - Gtk.TreeViewColumn(title='This is just a test', - cell_renderer=cell, - text=0, - style=2) + col = Gtk.TreeViewColumn(title='This is just a test', + cell_renderer=cell, + text=0, + style=2) + + # Regression test for: https://bugzilla.gnome.org/show_bug.cgi?id=711173 + col.set_cell_data_func(cell, None, None) def test_tree_view_add_column_with_attributes(self): model = Gtk.ListStore(str, str, str) @@ -1577,7 +1614,7 @@ class TestTreeView(unittest.TestCase): model.append(['cell13', 'cell11', 'cell12']) model.append(['cell23', 'cell21', 'cell22']) - tree = Gtk.TreeView(model) + tree = Gtk.TreeView(model=model) cell1 = Gtk.CellRendererText() cell2 = Gtk.CellRendererText() cell3 = Gtk.CellRendererText() |