From ffa6b33db84961226889d658f9a47ea67d899bc5 Mon Sep 17 00:00:00 2001 From: Vassilii Khachaturov Date: Thu, 22 Aug 2013 22:45:17 +0000 Subject: [PATCH] 7009: endless exception loop starting w/o DISPLAY Reapplied my fix to has_display from gramps40. svn: r22910 --- gramps/gen/constfunc.py | 10 +++---- gramps/gen/test/constfunc_test.py | 46 +++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 gramps/gen/test/constfunc_test.py diff --git a/gramps/gen/constfunc.py b/gramps/gen/constfunc.py index 08b851f05..202eaa5d1 100644 --- a/gramps/gen/constfunc.py +++ b/gramps/gen/constfunc.py @@ -132,15 +132,15 @@ def has_display(): temp, sys.argv = sys.argv, sys.argv[:1] try: from gi.repository import Gtk + from gi.repository import Gdk except: return False + try: - test = Gtk.init_check(temp) + test = Gtk.init_check(temp) and \ + Gdk.Display.get_default() sys.argv = temp - if test: - return True - else: - return False + return bool(test) except: sys.argv = temp return False diff --git a/gramps/gen/test/constfunc_test.py b/gramps/gen/test/constfunc_test.py new file mode 100644 index 000000000..0959dffa8 --- /dev/null +++ b/gramps/gen/test/constfunc_test.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2013 Vassilii Khachaturov +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# + +# $Id$ + +""" Unittest for constfunc.py """ + +from __future__ import print_function + +import unittest +from .. import constfunc + +from os import environ as env + +class Test_has_display(unittest.TestCase): + def setUp(self): + self.has = constfunc.has_display() + self.display_nonempty = env.has_key('DISPLAY') and bool(env['DISPLAY']) + + @unittest.skipUnless(constfunc.lin(), "Written for Linux only...") + def test_consistent_with_DISPLAY_env(self): + assert self.has == self.display_nonempty, \ + "has_display(): {}, $DISPLAY: {}".format( + self.has, env['DISPLAY'] if env.has_key('DISPLAY') \ + else "(unset)") + +if __name__ == "__main__": + unittest.main()