summaryrefslogtreecommitdiff
path: root/tests/test_ossig.py
diff options
context:
space:
mode:
authorMikhail Fludkov <misha@pexip.com>2018-02-08 12:49:01 +0100
committerMikhail Fludkov <misha@pexip.com>2018-02-08 12:49:01 +0100
commit7bc20fe2d1225bebb2f4ec1faabf6a70e4e5a4e7 (patch)
treea98a3ff2011cf663c0c7af1a03c3a3e916101639 /tests/test_ossig.py
parentd371fd77d33c2987cc450bd68ce4ee4835e09bd8 (diff)
downloadpygobject-7bc20fe2d1225bebb2f4ec1faabf6a70e4e5a4e7.tar.gz
tests: Make tests run without Gtk/Gdk installed
Python evaluates the code inside @unittest.skipIf decorator during import time. Because Gtk is not installed it crashes while evaluating 'Gtk._version' where Gtk=None.
Diffstat (limited to 'tests/test_ossig.py')
-rw-r--r--tests/test_ossig.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/tests/test_ossig.py b/tests/test_ossig.py
index bf218b82..0b6eea65 100644
--- a/tests/test_ossig.py
+++ b/tests/test_ossig.py
@@ -20,7 +20,11 @@ import unittest
import threading
from contextlib import contextmanager
-from gi.repository import Gtk, Gio, GLib
+try:
+ from gi.repository import Gtk
+except ImportError:
+ Gtk = None
+from gi.repository import Gio, GLib
from gi._ossighelper import wakeup_on_signal, register_sigint_fallback
@@ -83,7 +87,7 @@ class TestOverridesWakeupOnAlarm(unittest.TestCase):
app.connect("activate", lambda *args: None)
app.run()
- @unittest.skipIf(os.name == "nt", "not on Windows")
+ @unittest.skipIf(Gtk is None or os.name == "nt", "not on Windows")
def test_gtk_main(self):
signal.signal(signal.SIGALRM, lambda *args: Gtk.main_quit())
GLib.idle_add(signal.setitimer, signal.ITIMER_REAL, 0.001)
@@ -91,7 +95,7 @@ class TestOverridesWakeupOnAlarm(unittest.TestCase):
with self._run_with_timeout(2000, Gtk.main_quit):
Gtk.main()
- @unittest.skipIf(os.name == "nt", "not on Windows")
+ @unittest.skipIf(Gtk is None or os.name == "nt", "not on Windows")
def test_gtk_dialog_run(self):
w = Gtk.Window()
d = Gtk.Dialog(transient_for=w)