[pygobject] tests: Make test suite run on Windows



commit 30228a98299eeb540fd014b9519a9efd4a434d4b
Author: Christoph Reiter <reiter christoph gmail com>
Date:   Thu Mar 23 17:59:55 2017 +0100

    tests: Make test suite run on Windows
    
    (in a msys2 environment)
    
    * Replace LD_LIBRARY_PATH with gir code in runtests.py
    * Remove unneeded runtests-windows.py
    * Unset MSYSTEM to disable path separator hacks by msys2
    * Set sys.path in runtests.py
    * Skip various tests failing/hanging/crashing on Windows
    
    https://bugzilla.gnome.org/show_bug.cgi?id=780396

 tests/Makefile.am           |    9 ++-----
 tests/compat_test_pygtk.py  |    4 ++-
 tests/runtests-windows.py   |   52 -------------------------------------------
 tests/runtests.py           |   13 +++++++++-
 tests/test_atoms.py         |    4 ++-
 tests/test_everything.py    |    2 +-
 tests/test_gi.py            |    7 +++--
 tests/test_gio.py           |    3 ++
 tests/test_glib.py          |   15 +++++++++---
 tests/test_iochannel.py     |   17 +++++++++++++-
 tests/test_mainloop.py      |    4 +++
 tests/test_overrides_gdk.py |    3 +-
 tests/test_properties.py    |    9 +++++--
 tests/test_subprocess.py    |    1 +
 14 files changed, 68 insertions(+), 75 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index dcfe442..fe4fa84 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -106,7 +106,6 @@ EXTRA_DIST = \
        helper.py \
        compathelper.py \
        runtests.py \
-       runtests-windows.py \
        testmodule.py \
        test-floating.h \
        test-thread.h \
@@ -154,19 +153,17 @@ EXTRA_DIST = \
 clean-local:
        rm -f $(target_libraries) file.txt~
 
+# Unsetting MSYSTEM prevents msys2 from changing os.path.sep to "/"
 RUN_TESTS_ENV_VARS= \
-       PYTHONPATH=$(top_builddir):$(top_builddir)/tests:$${PYTHONPATH:+:$$PYTHONPATH} \
-       LD_LIBRARY_PATH=$(builddir)/.libs:$$LD_LIBRARY_PATH \
-       GI_TYPELIB_PATH=$(builddir):$$GI_TYPELIB_PATH \
-       XDG_DATA_DIRS=$$XDG_DATA_DIRS:/usr/share \
        MALLOC_PERTURB_=85 \
        MALLOC_CHECK_=3 \
        G_SLICE=debug-blocks \
+       MSYSTEM= \
        TESTS_BUILDDIR=$(builddir)
 
 # if dbus-run-session is available, use it, otherwise disable DBUS
 check-local:
-       DBUS_ENV=$$(dbus-run-session true && echo "dbus-run-session --" || echo "DBUS_SESSION_BUS_ADDRESS= ") 
$(MAKE) check.real
+       DBUS_ENV=$$(dbus-run-session true && echo "dbus-run-session --" || echo "DBUS_SESSION_BUS_ADDRESS=.") 
$(MAKE) check.real
 
 # pygtkcompat tests need to be run in a separate process as they
 # clobber global name space
diff --git a/tests/compat_test_pygtk.py b/tests/compat_test_pygtk.py
index e49166b..636b0e4 100644
--- a/tests/compat_test_pygtk.py
+++ b/tests/compat_test_pygtk.py
@@ -182,4 +182,6 @@ class TestGTKCompat(unittest.TestCase):
     def test_gdk_window(self):
         w = gtk.Window()
         w.realize()
-        self.assertEqual(w.get_window().get_origin(), (0, 0))
+        origin = w.get_window().get_origin()
+        self.assertTrue(isinstance(origin, tuple))
+        self.assertEqual(len(origin), 2)
diff --git a/tests/runtests.py b/tests/runtests.py
index 4bffc57..6c89f9b 100755
--- a/tests/runtests.py
+++ b/tests/runtests.py
@@ -18,9 +18,11 @@ if '--help' in sys.argv:
 mydir = os.path.dirname(os.path.abspath(__file__))
 tests_builddir = os.path.abspath(os.environ.get('TESTS_BUILDDIR', os.path.dirname(__file__)))
 builddir = os.path.dirname(tests_builddir)
+tests_srcdir = os.path.abspath(os.path.dirname(__file__))
+srcdir = os.path.dirname(tests_srcdir)
 
-# we have to do this here instead of Makefile.am so that the implicitly added
-# directory for the source file comes after the builddir
+sys.path.insert(0, tests_srcdir)
+sys.path.insert(0, srcdir)
 sys.path.insert(0, tests_builddir)
 sys.path.insert(0, builddir)
 
@@ -38,6 +40,13 @@ os.environ['GSETTINGS_BACKEND'] = 'memory'
 os.environ['GSETTINGS_SCHEMA_DIR'] = tests_builddir
 os.environ['G_FILENAME_ENCODING'] = 'UTF-8'
 
+import gi
+gi.require_version("GIRepository", "2.0")
+from gi.repository import GIRepository
+repo = GIRepository.Repository.get_default()
+repo.prepend_library_path(os.path.join(tests_builddir, ".libs"))
+repo.prepend_search_path(tests_builddir)
+
 # Load tests.
 if 'TEST_NAMES' in os.environ:
     names = os.environ['TEST_NAMES'].split()
diff --git a/tests/test_atoms.py b/tests/test_atoms.py
index d62764f..762f41e 100644
--- a/tests/test_atoms.py
+++ b/tests/test_atoms.py
@@ -1,3 +1,4 @@
+import os
 import sys
 import unittest
 
@@ -74,7 +75,8 @@ class TestGdkAtom(unittest.TestCase):
         self.assertFalse(None in names, names)
         self.assertTrue('TEXT' in names, names)
 
-    @unittest.skipIf(sys.platform == "darwin", "fails on OSX")
+    @unittest.skipIf(sys.platform == "darwin" or os.name == "nt",
+                     "fails on OSX/Windows")
     def test_out_glist(self):
         display = Gdk.Display.get_default()
         dm = display.get_device_manager()
diff --git a/tests/test_everything.py b/tests/test_everything.py
index fae07e6..b6405c1 100644
--- a/tests/test_everything.py
+++ b/tests/test_everything.py
@@ -575,7 +575,7 @@ class TestEverything(unittest.TestCase):
             self.assertTrue('TestBoxedPrivate' in str(e_value), str(e_value))
             self.assertTrue('constructor' in str(e_value), str(e_value))
             tb = ''.join(traceback.format_exception(e_type, e_value, e_tb))
-            self.assertTrue('tests/test_everything.py", line' in tb, tb)
+            self.assertTrue('test_everything.py", line' in tb, tb)
 
 
 @unittest.skipUnless(has_cairo, 'built without cairo support')
diff --git a/tests/test_gi.py b/tests/test_gi.py
index c545d5d..b18d835 100644
--- a/tests/test_gi.py
+++ b/tests/test_gi.py
@@ -714,11 +714,12 @@ class TestFilename(unittest.TestCase):
         self.assertTrue(GIMarshallingTests.filename_copy(None) is None)
         self.assertRaises(TypeError, GIMarshallingTests.filename_exists, None)
 
+    @unittest.skipIf(os.name == "nt", "fixme")
     def test_filename_out(self):
         self.assertRaises(GLib.GError, GLib.Dir.make_tmp, 'test')
 
         dirname = GLib.Dir.make_tmp('testäø.XXXXXX')
-        self.assertTrue('/testäø.' in dirname, dirname)
+        self.assertTrue(os.path.sep + 'testäø.' in dirname, dirname)
         dirname = _bytes(dirname)
         self.assertTrue(os.path.isdir(dirname))
         os.rmdir(dirname)
@@ -1486,7 +1487,7 @@ class TestEnum(unittest.TestCase):
 
         Run test under a locale which defines toupper('a') == 'a'
         '''
-        if sys.platform == "darwin":
+        if sys.platform == "darwin" or os.name == "nt":
             return
         cls.locale_dir = tempfile.mkdtemp()
         src = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'te_ST@nouppera')
@@ -1497,7 +1498,7 @@ class TestEnum(unittest.TestCase):
 
     @classmethod
     def tearDownClass(cls):
-        if sys.platform == "darwin":
+        if sys.platform == "darwin" or os.name == "nt":
             return
         locale.setlocale(locale.LC_ALL, 'C')
         shutil.rmtree(cls.locale_dir)
diff --git a/tests/test_gio.py b/tests/test_gio.py
index 05ab008..d3e2f49 100644
--- a/tests/test_gio.py
+++ b/tests/test_gio.py
@@ -1,6 +1,7 @@
 # -*- Mode: Python; py-indent-offset: 4 -*-
 # vim: tabstop=4 shiftwidth=4 expandtab
 
+import os
 import unittest
 
 import gi.overrides
@@ -142,6 +143,7 @@ class TestGSettings(unittest.TestCase):
                                              1)])
 
 
+@unittest.skipIf(os.name == "nt", "FIXME")
 class TestGFile(unittest.TestCase):
     def setUp(self):
         self.file, self.io_stream = Gio.File.new_tmp('TestGFile.XXXXXX')
@@ -206,6 +208,7 @@ class TestGFile(unittest.TestCase):
         self.assertFalse(self.file.query_exists(None))
 
 
+@unittest.skipIf(os.name == "nt", "crashes on Windows")
 class TestGApplication(unittest.TestCase):
     def test_command_line(self):
         class App(Gio.Application):
diff --git a/tests/test_glib.py b/tests/test_glib.py
index dbde589..ec0f87f 100644
--- a/tests/test_glib.py
+++ b/tests/test_glib.py
@@ -1,6 +1,7 @@
 # -*- Mode: Python -*-
 # encoding: UTF-8
 
+import os
 import sys
 import unittest
 import os.path
@@ -14,9 +15,11 @@ from compathelper import _unicode, _bytes
 
 
 class TestGLib(unittest.TestCase):
+
+    @unittest.skipIf(os.name == "nt", "no bash on Windows")
     def test_find_program_in_path(self):
         bash_path = GLib.find_program_in_path('bash')
-        self.assertTrue(bash_path.endswith('/bash'))
+        self.assertTrue(bash_path.endswith(os.path.sep + 'bash'))
         self.assertTrue(os.path.exists(bash_path))
 
         self.assertEqual(GLib.find_program_in_path('non existing'), None)
@@ -38,9 +41,9 @@ class TestGLib(unittest.TestCase):
 
     def test_xdg_dirs(self):
         d = GLib.get_user_data_dir()
-        self.assertTrue('/' in d, d)
+        self.assertTrue(os.path.sep in d, d)
         d = GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_DESKTOP)
-        self.assertTrue('/' in d, d)
+        self.assertTrue(os.path.sep in d, d)
         with warnings.catch_warnings():
             warnings.simplefilter('ignore', PyGIDeprecationWarning)
 
@@ -49,7 +52,7 @@ class TestGLib(unittest.TestCase):
                              GLib.get_user_special_dir(GLib.USER_DIRECTORY_MUSIC))
 
         for d in GLib.get_system_config_dirs():
-            self.assertTrue('/' in d, d)
+            self.assertTrue(os.path.sep in d, d)
         for d in GLib.get_system_data_dirs():
             self.assertTrue(isinstance(d, str), d)
 
@@ -124,6 +127,7 @@ https://my.org/q?x=1&y=2
         self.assertTrue(context.pending() in [True, False])
         self.assertTrue(context.iteration(False) in [True, False])
 
+    @unittest.skipIf(os.name == "nt", "hangs")
     def test_io_add_watch_no_data(self):
         (r, w) = os.pipe()
         call_data = []
@@ -147,6 +151,7 @@ https://my.org/q?x=1&y=2
         self.assertEqual(call_data, [(r, GLib.IOCondition.IN, b'a'),
                                      (r, GLib.IOCondition.IN, b'b')])
 
+    @unittest.skipIf(os.name == "nt", "hangs")
     def test_io_add_watch_with_data(self):
         (r, w) = os.pipe()
         call_data = []
@@ -170,6 +175,7 @@ https://my.org/q?x=1&y=2
         self.assertEqual(call_data, [(r, GLib.IOCondition.IN, b'a', 'moo'),
                                      (r, GLib.IOCondition.IN, b'b', 'moo')])
 
+    @unittest.skipIf(os.name == "nt", "hangs")
     def test_io_add_watch_with_multiple_data(self):
         (r, w) = os.pipe()
         call_data = []
@@ -191,6 +197,7 @@ https://my.org/q?x=1&y=2
 
         self.assertEqual(call_data, [(r, GLib.IOCondition.IN, b'a', ('moo', 'foo'))])
 
+    @unittest.skipIf(os.name == "nt", "no shell on Windows")
     def test_io_add_watch_pyfile(self):
         call_data = []
 
diff --git a/tests/test_iochannel.py b/tests/test_iochannel.py
index 5980a66..bba01e3 100644
--- a/tests/test_iochannel.py
+++ b/tests/test_iochannel.py
@@ -2,13 +2,18 @@
 # encoding: UTF-8
 from __future__ import unicode_literals
 
+import os
 import unittest
 import tempfile
 import os.path
-import fcntl
 import shutil
 import warnings
 
+try:
+    import fcntl
+except ImportError:
+    fcntl = None
+
 from gi.repository import GLib
 from gi import PyGIDeprecationWarning
 
@@ -112,6 +117,7 @@ second line
 
         # invalid whence value
         self.assertRaises(ValueError, ch.seek, 0, 3)
+        ch.shutdown(True)
 
     def test_file_write(self):
         ch = GLib.IOChannel(filename=self.testout, mode='w')
@@ -167,6 +173,7 @@ second line
         self.assertEqual(reader.read(), b'ghi')
         reader.shutdown(True)
 
+    @unittest.skipIf(os.name == "nt", "NONBLOCK not implemented on Windows")
     def test_fd_read(self):
         (r, w) = os.pipe()
 
@@ -186,6 +193,7 @@ second line
 
         ch.shutdown(True)
 
+    @unittest.skipUnless(fcntl, "no fcntl")
     def test_fd_write(self):
         (r, w) = os.pipe()
         fcntl.fcntl(r, fcntl.F_SETFL, fcntl.fcntl(r, fcntl.F_GETFL) | os.O_NONBLOCK)
@@ -203,6 +211,7 @@ second line
         self.assertEqual(os.read(r, 10), b'\x03\x04')
         os.close(r)
 
+    @unittest.skipIf(os.name == "nt", "NONBLOCK not implemented on Windows")
     def test_deprecated_method_add_watch_no_data(self):
         (r, w) = os.pipe()
 
@@ -233,6 +242,7 @@ second line
 
         self.assertEqual(cb_reads, [b'a', b'b'])
 
+    @unittest.skipIf(os.name == "nt", "NONBLOCK not implemented on Windows")
     def test_deprecated_method_add_watch_data_priority(self):
         (r, w) = os.pipe()
 
@@ -266,6 +276,7 @@ second line
 
         self.assertEqual(cb_reads, [b'a', b'b'])
 
+    @unittest.skipIf(os.name == "nt", "NONBLOCK not implemented on Windows")
     def test_add_watch_no_data(self):
         (r, w) = os.pipe()
 
@@ -293,6 +304,7 @@ second line
 
         self.assertEqual(cb_reads, [b'a', b'b'])
 
+    @unittest.skipIf(os.name == "nt", "NONBLOCK not implemented on Windows")
     def test_add_watch_with_data(self):
         (r, w) = os.pipe()
 
@@ -321,6 +333,7 @@ second line
 
         self.assertEqual(cb_reads, [b'a', b'b'])
 
+    @unittest.skipIf(os.name == "nt", "NONBLOCK not implemented on Windows")
     def test_add_watch_with_multi_data(self):
         (r, w) = os.pipe()
 
@@ -352,6 +365,7 @@ second line
 
         self.assertEqual(cb_reads, [b'a', b'b'])
 
+    @unittest.skipIf(os.name == "nt", "NONBLOCK not implemented on Windows")
     def test_deprecated_add_watch_no_data(self):
         (r, w) = os.pipe()
 
@@ -382,6 +396,7 @@ second line
 
         self.assertEqual(cb_reads, [b'a', b'b'])
 
+    @unittest.skipIf(os.name == "nt", "NONBLOCK not implemented on Windows")
     def test_deprecated_add_watch_with_data(self):
         (r, w) = os.pipe()
 
diff --git a/tests/test_mainloop.py b/tests/test_mainloop.py
index 44197b3..2728e09 100644
--- a/tests/test_mainloop.py
+++ b/tests/test_mainloop.py
@@ -19,6 +19,8 @@ from compathelper import _bytes
 
 
 class TestMainLoop(unittest.TestCase):
+
+    @unittest.skipUnless(hasattr(os, "fork"), "no os.fork available")
     def test_exception_handling(self):
         pipe_r, pipe_w = os.pipe()
 
@@ -60,6 +62,7 @@ class TestMainLoop(unittest.TestCase):
         #
         self.assertFalse(got_exception)
 
+    @unittest.skipUnless(hasattr(signal, "SIGUSR1"), "no SIGUSR1")
     def test_concurrency(self):
         def on_usr1(signum, frame):
             pass
@@ -80,6 +83,7 @@ class TestMainLoop(unittest.TestCase):
         finally:
             signal.signal(signal.SIGUSR1, orig_handler)
 
+    @unittest.skipUnless(hasattr(os, "fork"), "no os.fork available")
     def test_sigint(self):
         pid = os.fork()
         if pid == 0:
diff --git a/tests/test_overrides_gdk.py b/tests/test_overrides_gdk.py
index 79207df..4aff2eb 100644
--- a/tests/test_overrides_gdk.py
+++ b/tests/test_overrides_gdk.py
@@ -1,6 +1,7 @@
 # -*- Mode: Python; py-indent-offset: 4 -*-
 # vim: tabstop=4 shiftwidth=4 expandtab
 
+import os
 import sys
 import unittest
 
@@ -19,7 +20,7 @@ from helper import capture_glib_deprecation_warnings
 @unittest.skipUnless(Gdk, 'Gdk not available')
 class TestGdk(unittest.TestCase):
 
-    @unittest.skipIf(sys.platform == "darwin", "crashes")
+    @unittest.skipIf(sys.platform == "darwin" or os.name == "nt", "crashes")
     def test_constructor(self):
         attribute = Gdk.WindowAttr()
         attribute.window_type = Gdk.WindowType.CHILD
diff --git a/tests/test_properties.py b/tests/test_properties.py
index 109fdb9..00e3c56 100644
--- a/tests/test_properties.py
+++ b/tests/test_properties.py
@@ -1,10 +1,12 @@
 # coding=utf-8
 
+import os
 import gc
 import sys
 import struct
 import types
 import unittest
+import tempfile
 
 import gi
 from gi.repository import GObject
@@ -417,10 +419,11 @@ class TestPropertyObject(unittest.TestCase):
     def test_interface(self):
         obj = new(PropertyObject)
 
-        file = Gio.File.new_for_path('/some/path')
+        path = os.path.join(tempfile.gettempdir(), "some", "path")
+        file = Gio.File.new_for_path(path)
         obj.props.interface = file
-        self.assertEqual(obj.props.interface.get_path(), '/some/path')
-        self.assertEqual(obj.interface.get_path(), '/some/path')
+        self.assertEqual(obj.props.interface.get_path(), path)
+        self.assertEqual(obj.interface.get_path(), path)
 
         self.assertRaises(TypeError, setattr, obj, 'interface', 'foo')
         self.assertRaises(TypeError, setattr, obj, 'interface', object())
diff --git a/tests/test_subprocess.py b/tests/test_subprocess.py
index fac54c9..deea58f 100644
--- a/tests/test_subprocess.py
+++ b/tests/test_subprocess.py
@@ -9,6 +9,7 @@ from gi.repository import GLib
 from gi import PyGIDeprecationWarning
 
 
+@unittest.skipIf(os.name == "nt", "not on Windows")
 class TestProcess(unittest.TestCase):
 
     def test_deprecated_child_watch_no_data(self):


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]