84497af
From 4d1f0b36c43780586f5d0c2622eb92d068ebe281 Mon Sep 17 00:00:00 2001
84497af
From: fujiwarat <takao.fujiwara1@gmail.com>
84497af
Date: Sun, 21 Mar 2021 15:25:41 +0900
84497af
Subject: [PATCH] tests: Output info to stderr instead of StringIO
84497af
84497af
---
84497af
 tests/anthytest.py | 51 ++++++++++++++++++++++++++++++----------------
84497af
 1 file changed, 33 insertions(+), 18 deletions(-)
84497af
84497af
diff --git a/tests/anthytest.py b/tests/anthytest.py
84497af
index bff3078..1d18d19 100755
84497af
--- a/tests/anthytest.py
84497af
+++ b/tests/anthytest.py
84497af
@@ -28,17 +28,31 @@ TAP_MODULE_PYCOTAP = list(range(3))
84497af
 
84497af
 tap_module = TAP_MODULE_NONE
84497af
 
84497af
+# Need to flush the output against Gtk.main()
84497af
+def printflush(sentence):
84497af
+    try:
84497af
+        print(sentence, flush=True)
84497af
+    except IOError:
84497af
+        pass
84497af
+
84497af
+def printerr(sentence):
84497af
+    try:
84497af
+        print(sentence, flush=True, file=sys.stderr)
84497af
+    except IOError:
84497af
+        pass
84497af
+
84497af
 try:
84497af
     from tap import TAPTestRunner
84497af
     tap_module = TAP_MODULE_TAPPY
84497af
-    print('Load tappy')
84497af
+    printflush('## Load tappy')
84497af
 except ModuleNotFoundError:
84497af
     try:
84497af
         from pycotap import TAPTestRunner
84497af
+        from pycotap import LogMode
84497af
         tap_module = TAP_MODULE_PYCOTAP
84497af
-        print('Load pycotap')
84497af
+        printflush('## Load pycotap')
84497af
     except ModuleNotFoundError as err:
84497af
-        print('Ignore tap module: %s' % str(err))
84497af
+        printflush('## Ignore tap module: %s' % str(err))
84497af
 
84497af
 PY3K = sys.version_info >= (3, 0)
84497af
 DONE_EXIT = True
84497af
@@ -55,18 +69,6 @@ sys.path.append('/usr/share/ibus-anthy/engine')
84497af
 
84497af
 from anthycases import TestCases
84497af
 
84497af
-# Need to flush the output against Gtk.main()
84497af
-def printflush(sentence):
84497af
-    try:
84497af
-        print(sentence, flush=True)
84497af
-    except IOError:
84497af
-        pass
84497af
-
84497af
-def printerr(sentence):
84497af
-    try:
84497af
-        print(sentence, flush=True, file=sys.stderr)
84497af
-    except IOError:
84497af
-        pass
84497af
 
84497af
 @unittest.skipIf(Gdk.Display.open('') == None, 'Display cannot be open.')
84497af
 class AnthyTest(unittest.TestCase):
84497af
@@ -83,8 +85,10 @@ class AnthyTest(unittest.TestCase):
84497af
         self.__test_index = 0
84497af
         self.__conversion_index = 0
84497af
         self.__commit_done = False
84497af
+        self.__engine = None
84497af
 
84497af
     def register_ibus_engine(self):
84497af
+        printflush('## Registering engine')
84497af
         self.__bus = IBus.Bus()
84497af
         if not self.__bus.is_connected():
84497af
             self.fail('ibus-daemon is not running')
84497af
@@ -144,6 +148,7 @@ class AnthyTest(unittest.TestCase):
84497af
 
84497af
     def __create_engine_cb(self, factory, engine_name):
84497af
         if engine_name == 'testanthy':
84497af
+            printflush('## Creating engine')
84497af
             try:
84497af
                 import engine
84497af
             except ModuleNotFoundError as e:
84497af
@@ -176,14 +181,20 @@ class AnthyTest(unittest.TestCase):
84497af
         window = Gtk.Window(type = Gtk.WindowType.TOPLEVEL)
84497af
         self.__entry = entry = Gtk.Entry()
84497af
         window.connect('destroy', Gtk.main_quit)
84497af
+        entry.connect('map', self.__entry_map_cb)
84497af
         entry.connect('focus-in-event', self.__entry_focus_in_event_cb)
84497af
         entry.connect('preedit-changed', self.__entry_preedit_changed_cb)
84497af
         buffer = entry.get_buffer()
84497af
         buffer.connect('inserted-text', self.__buffer_inserted_text_cb)
84497af
         window.add(entry)
84497af
         window.show_all()
84497af
+        printflush('## Build window')
84497af
+
84497af
+    def __entry_map_cb(self, entry):
84497af
+        printflush('## Map window')
84497af
 
84497af
     def __entry_focus_in_event_cb(self, entry, event):
84497af
+        printflush('## Get focus')
84497af
         if self.__test_index == len(TestCases['tests']):
84497af
             if DONE_EXIT:
84497af
                 Gtk.main_quit()
84497af
@@ -231,11 +242,11 @@ class AnthyTest(unittest.TestCase):
84497af
                 schema = "org.freedesktop.ibus.engine.anthy.common");
84497af
         result = settings.get_int('input-mode')
84497af
         if result != 0:
84497af
-            printflush('Enable hiragana %d' % result)
84497af
+            printflush('## Enable hiragana %d' % result)
84497af
             key = TestCases['init']
84497af
             self.__typing(key[0], key[1], key[2])
84497af
         else:
84497af
-            printflush('Already hiragana')
84497af
+            printflush('## Already hiragana')
84497af
 
84497af
     def __main_test(self):
84497af
         self.__conversion_index = 0
84497af
@@ -371,7 +382,11 @@ def main():
84497af
 
84497af
     if args.tap:
84497af
         loader = unittest.TestLoader()
84497af
-        runner = TAPTestRunner()
84497af
+        if tap_module == TAP_MODULE_PYCOTAP:
84497af
+            # Log should be in stderr instead of StringIO
84497af
+            runner = TAPTestRunner(test_output_log=LogMode.LogToError)
84497af
+        else:
84497af
+            runner = TAPTestRunner()
84497af
         if tap_module == TAP_MODULE_TAPPY:
84497af
             runner.set_stream(True)
84497af
         unittest.main(testRunner=runner, testLoader=loader)
84497af
-- 
84497af
2.28.0
84497af