summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorChristoph Reiter <reiter.christoph@gmail.com>2015-01-24 20:01:00 +0100
committerSimon Feltman <sfeltman@src.gnome.org>2015-01-24 12:12:56 -0800
commitef3bff4e570363e4f383d4cdae9cecd4073b03d8 (patch)
treecff5de23f41cc1524a81547ff324044c033bca99 /tests
parent149c31beced944c72fba6ca6e096c81c1100ea2b (diff)
downloadpygobject-ef3bff4e570363e4f383d4cdae9cecd4073b03d8.tar.gz
Emit ImportWarning when gi.require_version() is not used
gi tries to import the latest version of typelibs which can cause existing code to break when a newer typelib is released. Emit an ImportWarning when gi.require_version() is not used to give developers this awareness so they can future proof their code. https://bugzilla.gnome.org/show_bug.cgi?id=727379
Diffstat (limited to 'tests')
-rw-r--r--tests/compat_test_pygtk.py7
-rw-r--r--tests/test_atoms.py6
-rw-r--r--tests/test_import_machinery.py22
-rw-r--r--tests/test_overrides_gtk.py7
-rw-r--r--tests/test_overrides_pango.py5
-rw-r--r--tests/test_properties.py5
-rw-r--r--tests/test_repository.py10
7 files changed, 55 insertions, 7 deletions
diff --git a/tests/compat_test_pygtk.py b/tests/compat_test_pygtk.py
index e9471204..b2e7a111 100644
--- a/tests/compat_test_pygtk.py
+++ b/tests/compat_test_pygtk.py
@@ -5,13 +5,18 @@ import unittest
import contextlib
import base64
+import gi
from gi.repository import GLib
try:
+ try:
+ gi.require_version("Gtk", "3.0")
+ except ValueError as e:
+ raise ImportError(e)
+ from gi.repository import Gtk
from gi.repository import Pango
from gi.repository import Atk
from gi.repository import Gdk
- from gi.repository import Gtk
(Atk, Gtk, Pango) # pyflakes
import pygtkcompat
diff --git a/tests/test_atoms.py b/tests/test_atoms.py
index 18f8d098..dfd4e365 100644
--- a/tests/test_atoms.py
+++ b/tests/test_atoms.py
@@ -1,9 +1,11 @@
import unittest
try:
- from gi.repository import Atk, Gdk, Gtk
+ import gi
+ gi.require_version('Gtk', '3.0')
+ from gi.repository import Gtk, Atk, Gdk
(Atk, Gdk) # pyflakes
-except:
+except (ValueError, ImportError):
Gdk = None
diff --git a/tests/test_import_machinery.py b/tests/test_import_machinery.py
index 0672aa77..c3d2a0b3 100644
--- a/tests/test_import_machinery.py
+++ b/tests/test_import_machinery.py
@@ -6,6 +6,7 @@ import unittest
import gi.overrides
import gi.module
+import gi.importer
try:
from gi.repository import Regress
@@ -116,3 +117,24 @@ class TestImporter(unittest.TestCase):
self.assertTrue('introspection typelib' not in exception_string)
else:
self.assertTrue('introspection typelib' in exception_string)
+
+ def test__get_all_dependencies(self):
+ get_all_dependencies = gi.importer._get_all_dependencies
+
+ self.assertEqual(
+ get_all_dependencies("Regress"),
+ ['Gio-2.0', 'GObject-2.0', 'GLib-2.0', 'cairo-1.0'])
+
+ def test_require_version_warning(self):
+ check = gi.importer._check_require_version
+
+ # make sure it doesn't fail at least
+ with check("GLib", 1):
+ from gi.repository import GLib
+ GLib
+
+ # make sure the exception propagates
+ with self.assertRaises(ImportError):
+ with check("InvalidGObjectRepositoryModuleName", 1):
+ from gi.repository import InvalidGObjectRepositoryModuleName
+ InvalidGObjectRepositoryModuleName
diff --git a/tests/test_overrides_gtk.py b/tests/test_overrides_gtk.py
index d3351d4b..a57b7daa 100644
--- a/tests/test_overrides_gtk.py
+++ b/tests/test_overrides_gtk.py
@@ -10,15 +10,18 @@ import warnings
from compathelper import _unicode, _bytes
+import gi
import gi.overrides
import gi.types
from gi.repository import GLib, GObject
try:
- from gi.repository import GdkPixbuf, Gdk, Gtk
+ gi.require_version('Gtk', '3.0')
+ gi.require_version('GdkPixbuf', '2.0')
+ from gi.repository import Gtk, GdkPixbuf, Gdk
Gtk # pyflakes
PyGTKDeprecationWarning = Gtk.PyGTKDeprecationWarning
-except ImportError:
+except (ValueError, ImportError):
Gtk = None
PyGTKDeprecationWarning = None
diff --git a/tests/test_overrides_pango.py b/tests/test_overrides_pango.py
index 1e8fe2df..51772138 100644
--- a/tests/test_overrides_pango.py
+++ b/tests/test_overrides_pango.py
@@ -4,11 +4,14 @@
import unittest
try:
+ import gi
+ gi.require_version('Pango', '1.0')
+ gi.require_version('PangoCairo', '1.0')
from gi.repository import Pango
from gi.repository import PangoCairo
Pango
PangoCairo
-except ImportError:
+except (ValueError, ImportError):
Pango = None
PangoCairo = None
diff --git a/tests/test_properties.py b/tests/test_properties.py
index 999bff1c..a147aaef 100644
--- a/tests/test_properties.py
+++ b/tests/test_properties.py
@@ -6,6 +6,7 @@ import struct
import types
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
@@ -22,13 +23,15 @@ from gi.repository.GObject import \
from gi.repository import Gio
from gi.repository import GLib
+gi.require_version('GIMarshallingTests', '1.0')
from gi.repository import GIMarshallingTests
from gi import _propertyhelper as propertyhelper
try:
+ gi.require_version('Regress', '1.0')
from gi.repository import Regress
has_regress = True
-except ImportError:
+except (ValueError, ImportError):
has_regress = False
if sys.version_info < (3, 0):
diff --git a/tests/test_repository.py b/tests/test_repository.py
index b73fbf91..43c7d9e5 100644
--- a/tests/test_repository.py
+++ b/tests/test_repository.py
@@ -23,6 +23,10 @@
import unittest
import collections
+import gi
+
+gi.require_version('GIRepository', '2.0')
+
import gi._gi as GIRepository
from gi.module import repository as repo
from gi.repository import GObject
@@ -49,9 +53,15 @@ def find_child_info(info, getter_name, name):
class Test(unittest.TestCase):
def setUp(self):
+ repo.require('GLib')
repo.require('GObject')
repo.require('GIMarshallingTests')
+ def test_repo_get_dependencies(self):
+ self.assertRaises(TypeError, repo.get_dependencies)
+ self.assertEqual(repo.get_dependencies("GLib"), [])
+ self.assertEqual(repo.get_dependencies("GObject"), ["GLib-2.0"])
+
def test_arg_info(self):
func_info = repo.find_by_name('GIMarshallingTests', 'array_fixed_out_struct')
args = func_info.get_arguments()