[rhel7 2/3] Add a test to look for clickable messages that aren't clickable enough.

David Shea dshea at redhat.com
Thu Jun 4 20:28:31 UTC 2015


(cherry picked from commit ffd481ec9e6f4ec4dd38cec3a524c2cdae2f36c2)

Related: rhbz#1125145
---
 tests/Makefile.am      |  1 +
 tests/gettext/click.py | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 73 insertions(+)
 create mode 100755 tests/gettext/click.py

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 7da8e51..3e1f009 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -57,6 +57,7 @@ dist_check_SCRIPTS = $(srcdir)/glade/*/*.py \
 TESTS = nosetests.sh \
 	pylint/runpylint.sh \
 	cppcheck/runcppcheck.sh \
+	gettext/click.py \
 	gettext/gettext_warnings.sh \
 	gettext/gettext_potfiles.py \
 	gettext/style_guide.py \
diff --git a/tests/gettext/click.py b/tests/gettext/click.py
new file mode 100755
index 0000000..6c3ce24
--- /dev/null
+++ b/tests/gettext/click.py
@@ -0,0 +1,72 @@
+#!/usr/bin/python2
+#
+# Copyright (C) 2015  Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as published
+# by the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+# Author: David Shea <dshea at redhat.com>
+
+import os, re, sys
+
+# Something like looks more or less like an <a> tag
+link_re = re.compile(r'<\s*a(\s|>)')
+
+# Something that looks like a clickable message
+click_re = re.compile(r'\b[Cc]lick for\b')
+
+# Strings to ignore
+ignore_msgs = ['Click for help.']
+
+# Use polib to parse anaconda.pot
+try:
+    import polib
+except ImportError:
+    print("You need to install the python-polib package to read anaconda.pot")
+    # This return code tells the automake test driver that the test setup failed
+    sys.exit(99)
+
+if "top_srcdir" not in os.environ:
+    sys.stderr.write("$top_srcdir must be defined in the test environment\n")
+    sys.exit(99)
+
+if "top_builddir" not in os.environ:
+    sys.stderr.write("$top_srcdir must be defined in the test environment\n")
+    sys.exit(99)
+
+# Update the .pot file with the latest strings
+if os.system('make -C %s anaconda.pot-update' % (os.environ['top_builddir'] + "/po")) != 0:
+    sys.stderr.write("Unable to update anaconda.pot")
+    sys.exit(1)
+
+# Parse anaconda.pot and rearrange the POFile object into a dict of {msgid: POEntry}
+pofile = polib.pofile(os.environ['top_srcdir'] + "/po/anaconda.pot")
+msgs = {e.msgid: e for e in pofile}
+
+success = True
+for msg in msgs.keys():
+    if msg in ignore_msgs:
+        continue
+
+    # Remove underscores to avoid trouble with underline-based accelerators
+    trimmed_msg = msg.replace('_', '')
+
+    # Look for claims of clickability
+    if click_re.search(trimmed_msg):
+        # Look for something to click
+        if not link_re.search(trimmed_msg):
+            print("String at %s appears to be clickable but has nothing to click." %
+                    " ".join("%s:%s" % (o[0], o[1]) for o in msgs[msg].occurrences))
+            success = False
+
+sys.exit(0 if success else 1)
-- 
2.1.0



More information about the anaconda-patches mailing list