Blob Blame History Raw
From 4d1f0b36c43780586f5d0c2622eb92d068ebe281 Mon Sep 17 00:00:00 2001
From: fujiwarat <takao.fujiwara1@gmail.com>
Date: Sun, 21 Mar 2021 15:25:41 +0900
Subject: [PATCH] tests: Output info to stderr instead of StringIO

---
 tests/anthytest.py | 51 ++++++++++++++++++++++++++++++----------------
 1 file changed, 33 insertions(+), 18 deletions(-)

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

From 84f080278a7351a26df441429bd58e5931944c32 Mon Sep 17 00:00:00 2001
From: fujiwarat <takao.fujiwara1@gmail.com>
Date: Tue, 27 Apr 2021 19:56:07 +0900
Subject: [PATCH] Fix covscan result

- Fix double quote not to re-splitting elements
- Fix deprecated GObject private
- Fix section variable initialization
- Fix dlg variable condition assignment
---
 engine/python2/ibus-engine-anthy.in | 4 ++--
 engine/python3/ibus-engine-anthy.in | 4 ++--
 gir/anthygcontext.c                 | 4 ++--
 setup/python2/ibus-setup-anthy.in   | 4 ++--
 setup/python2/main.py               | 8 +++++---
 setup/python3/ibus-setup-anthy.in   | 4 ++--
 setup/python3/main.py               | 6 ++++--
 7 files changed, 19 insertions(+), 15 deletions(-)

diff --git a/engine/python2/ibus-engine-anthy.in b/engine/python2/ibus-engine-anthy.in
index f663165..07b99fe 100644
--- a/engine/python2/ibus-engine-anthy.in
+++ b/engine/python2/ibus-engine-anthy.in
@@ -5,7 +5,7 @@
 # ibus-anthy - The Anthy engine for IBus
 #
 # Copyright (c) 2007-2008 Peng Huang <shawn.p.huang@gmail.com>
-# Copyright (c) 2010-2016 Takao Fujiwara <takao.fujiwara1@gmail.com>
+# Copyright (c) 2010-2021 Takao Fujiwara <takao.fujiwara1@gmail.com>
 # Copyright (c) 2007-2016 Red Hat, Inc.
 #
 # This program is free software; you can redistribute it and/or modify
@@ -25,4 +25,4 @@
 export IBUS_PREFIX=@prefix@
 export IBUS_ANTHY_PKGDATADIR=@datarootdir@/@PACKAGE@
 export LIBEXECDIR=@libexecdir@
-exec @ENV_IBUS_ENGINE@ @PYTHON@ @datarootdir@/@PACKAGE@/engine/main.py $@
+exec @ENV_IBUS_ENGINE@ @PYTHON@ @datarootdir@/@PACKAGE@/engine/main.py "$@"
diff --git a/engine/python3/ibus-engine-anthy.in b/engine/python3/ibus-engine-anthy.in
index f663165..07b99fe 100644
--- a/engine/python3/ibus-engine-anthy.in
+++ b/engine/python3/ibus-engine-anthy.in
@@ -5,7 +5,7 @@
 # ibus-anthy - The Anthy engine for IBus
 #
 # Copyright (c) 2007-2008 Peng Huang <shawn.p.huang@gmail.com>
-# Copyright (c) 2010-2016 Takao Fujiwara <takao.fujiwara1@gmail.com>
+# Copyright (c) 2010-2021 Takao Fujiwara <takao.fujiwara1@gmail.com>
 # Copyright (c) 2007-2016 Red Hat, Inc.
 #
 # This program is free software; you can redistribute it and/or modify
@@ -25,4 +25,4 @@
 export IBUS_PREFIX=@prefix@
 export IBUS_ANTHY_PKGDATADIR=@datarootdir@/@PACKAGE@
 export LIBEXECDIR=@libexecdir@
-exec @ENV_IBUS_ENGINE@ @PYTHON@ @datarootdir@/@PACKAGE@/engine/main.py $@
+exec @ENV_IBUS_ENGINE@ @PYTHON@ @datarootdir@/@PACKAGE@/engine/main.py "$@"
diff --git a/gir/anthygcontext.c b/gir/anthygcontext.c
index b342579..7698d4d 100644
--- a/gir/anthygcontext.c
+++ b/gir/anthygcontext.c
@@ -1,7 +1,7 @@
 /* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
 /* vim:set et sts=4: */
 /* ibus-anthy - The Anthy engine for IBus
- * Copyright (c) 2012-2019 Takao Fujiwara <takao.fujiwara1@gmail.com>
+ * Copyright (c) 2012-2021 Takao Fujiwara <takao.fujiwara1@gmail.com>
  * Copyright (c) 2012 Peng Huang <shawn.p.huang@gmail.com>
  * Copyright (c) 2012-2013 Red Hat, Inc.
  *
@@ -29,7 +29,7 @@ extern int anthy_do_set_personality (const char *id);
 #include "anthygcontext.h"
 
 #define ANTHY_GCONTEXT_GET_PRIVATE(o)   \
-   (G_TYPE_INSTANCE_GET_PRIVATE ((o), ANTHY_TYPE_GCONTEXT, AnthyGContextPrivate))
+    ((AnthyGContextPrivate *)anthy_gcontext_get_instance_private (o))
 
 struct _AnthyGContextPrivate {
     anthy_context_t context;
diff --git a/setup/python2/ibus-setup-anthy.in b/setup/python2/ibus-setup-anthy.in
index b936d2c..81c9dfc 100644
--- a/setup/python2/ibus-setup-anthy.in
+++ b/setup/python2/ibus-setup-anthy.in
@@ -4,7 +4,7 @@
 # ibus-tmpl - The Input Bus template project
 #
 # Copyright (c) 2007-2008 Peng Huang <shawn.p.huang@gmail.com>
-# Copyright (c) 2010-2016 Takao Fujiwara <takao.fujiwara1@gmail.com>
+# Copyright (c) 2010-2021 Takao Fujiwara <takao.fujiwara1@gmail.com>
 # Copyright (c) 2007-2016 Red Hat, Inc.
 #
 # This program is free software; you can redistribute it and/or modify
@@ -22,4 +22,4 @@
 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
 export IBUS_LOCALEDIR=@localedir@
-exec @PYTHON@ @prefix@/share/ibus-anthy/setup/main.py $@
+exec @PYTHON@ @prefix@/share/ibus-anthy/setup/main.py "$@"
diff --git a/setup/python2/main.py b/setup/python2/main.py
index 4e6b15b..f870ee5 100644
--- a/setup/python2/main.py
+++ b/setup/python2/main.py
@@ -4,7 +4,7 @@
 #
 # Copyright (c) 2007-2008 Peng Huang <shawn.p.huang@gmail.com>
 # Copyright (c) 2009 Hideaki ABE <abe.sendai@gmail.com>
-# Copyright (c) 2010-2019 Takao Fujiwara <takao.fujiwara1@gmail.com>
+# Copyright (c) 2010-2021 Takao Fujiwara <takao.fujiwara1@gmail.com>
 # Copyright (c) 2007-2019 Red Hat, Inc.
 #
 # This program is free software; you can redistribute it and/or modify
@@ -1253,7 +1253,7 @@ class AnthySetup(object):
         model_combobox = combobox.get_model()
         method = model_combobox[id][1]
         type = user_data
-        section_base = None
+        section = None
         key = input.get_text()
         value = output.get_text()
         left_text = left.get_text()
@@ -1308,7 +1308,7 @@ class AnthySetup(object):
         l, i = tv.get_selection().get_selected()
         type = l[i][0]
         key = l[i][1]
-        section_base = None
+        section = None
         if type == 'romaji':
             section = 'romaji-typing-rule'
         elif type == 'kana':
@@ -1379,6 +1379,7 @@ class AnthySetup(object):
     def on_btn_dict_add_clicked(self, widget):
         file = None
         id = None
+        dlg = None
 
         if Gtk.Buildable.get_name(widget) == 'dict:btn_add':
             dlg = Gtk.FileChooserDialog(title=_("Open Dictionary File"),
@@ -1394,6 +1395,7 @@ class AnthySetup(object):
                      _("_OK"), Gtk.ResponseType.OK)
             dlg.add_buttons(*buttons)
 
+        assert(dlg != None), 'Button name is undefined.'
         vbox = self.__builder.get_object('dict:add_extra_vbox')
         if Gtk.Buildable.get_name(widget) == 'dict:btn_add':
             # Need to init for the second time
diff --git a/setup/python3/ibus-setup-anthy.in b/setup/python3/ibus-setup-anthy.in
index b936d2c..81c9dfc 100644
--- a/setup/python3/ibus-setup-anthy.in
+++ b/setup/python3/ibus-setup-anthy.in
@@ -4,7 +4,7 @@
 # ibus-tmpl - The Input Bus template project
 #
 # Copyright (c) 2007-2008 Peng Huang <shawn.p.huang@gmail.com>
-# Copyright (c) 2010-2016 Takao Fujiwara <takao.fujiwara1@gmail.com>
+# Copyright (c) 2010-2021 Takao Fujiwara <takao.fujiwara1@gmail.com>
 # Copyright (c) 2007-2016 Red Hat, Inc.
 #
 # This program is free software; you can redistribute it and/or modify
@@ -22,4 +22,4 @@
 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
 export IBUS_LOCALEDIR=@localedir@
-exec @PYTHON@ @prefix@/share/ibus-anthy/setup/main.py $@
+exec @PYTHON@ @prefix@/share/ibus-anthy/setup/main.py "$@"
diff --git a/setup/python3/main.py b/setup/python3/main.py
index 7e16093..6641f7f 100644
--- a/setup/python3/main.py
+++ b/setup/python3/main.py
@@ -1246,7 +1246,7 @@ class AnthySetup(object):
         model_combobox = combobox.get_model()
         method = model_combobox[id][1]
         type = user_data
-        section_base = None
+        section = None
         key = input.get_text()
         value = output.get_text()
         left_text = left.get_text()
@@ -1301,7 +1301,7 @@ class AnthySetup(object):
         l, i = tv.get_selection().get_selected()
         type = l[i][0]
         key = l[i][1]
-        section_base = None
+        section = None
         if type == 'romaji':
             section = 'romaji-typing-rule'
         elif type == 'kana':
@@ -1372,6 +1372,7 @@ class AnthySetup(object):
     def on_btn_dict_add_clicked(self, widget):
         file = None
         id = None
+        dlg = None
 
         if Gtk.Buildable.get_name(widget) == 'dict:btn_add':
             dlg = Gtk.FileChooserDialog(title=_("Open Dictionary File"),
@@ -1387,6 +1388,7 @@ class AnthySetup(object):
                      _("_OK"), Gtk.ResponseType.OK)
             dlg.add_buttons(*buttons)
 
+        assert (dlg != None), 'Button name is undefined.'
         vbox = self.__builder.get_object('dict:add_extra_vbox')
         if Gtk.Buildable.get_name(widget) == 'dict:btn_add':
             # Need to init for the second time
-- 
2.28.0