[PATCH] Add a test for disadvised words.

David Shea dshea at redhat.com
Wed Aug 6 19:00:32 UTC 2014


Also fix an occurrence of username I missed last time because there's an
underscore in the middle of it.
---
 pyanaconda/ui/gui/spokes/source.glade |   2 +-
 tests/Makefile.am                     |   2 +
 tests/gettext/style_guide.py          | 103 ++++++++++++++++++++++++++++++++++
 3 files changed, 106 insertions(+), 1 deletion(-)
 create mode 100755 tests/gettext/style_guide.py

diff --git a/pyanaconda/ui/gui/spokes/source.glade b/pyanaconda/ui/gui/spokes/source.glade
index 248cff6..d3580c3 100644
--- a/pyanaconda/ui/gui/spokes/source.glade
+++ b/pyanaconda/ui/gui/spokes/source.glade
@@ -1202,7 +1202,7 @@
                             <property name="visible">True</property>
                             <property name="can_focus">False</property>
                             <property name="xalign">0</property>
-                            <property name="label" translatable="yes" context="GUI|Software Source">U_sername:</property>
+                            <property name="label" translatable="yes" context="GUI|Software Source">U_ser name:</property>
                             <property name="use_underline">True</property>
                             <property name="mnemonic_widget">repoProxyUsernameEntry</property>
                             <attributes>
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 2803481..086a263 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -48,6 +48,7 @@ dist_check_SCRIPTS = $(srcdir)/glade/*/*.py \
 		     testenv.sh \
 		     gettext/gettext_warnings.sh \
 		     gettext/gettext_potfiles.py \
+		     gettext/style_guide.py \
 		     storage/run_storage_tests.py \
 		     ostree/run_ostree_tests.sh \
 		     $(srcdir)/gui/*.ks \
@@ -62,6 +63,7 @@ TESTS = nosetests.sh \
 	cppcheck/runcppcheck.sh \
 	gettext/gettext_warnings.sh \
 	gettext/gettext_potfiles.py \
+	gettext/style_guide.py \
 	storage/run_storage_tests.py \
 	gui/run_gui_tests.sh \
 	glade/run_glade_tests.sh \
diff --git a/tests/gettext/style_guide.py b/tests/gettext/style_guide.py
new file mode 100755
index 0000000..09ffafa
--- /dev/null
+++ b/tests/gettext/style_guide.py
@@ -0,0 +1,103 @@
+#!/usr/bin/python
+#
+# Copyright (C) 2014  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
+
+# {'bad re': 'suggestion'}
+# All the crazy looking underscores are to catch strings with arbitrary
+# gtk accelerators set. (?i) makes the re case-insensitive
+bad_strings = {'(?i)b_?o_?o_?t_?l_?o_?a_?d_?e_?r': 'boot loader',
+               '(?i)f_?i_?l_?e_?s_?y_?s_?t_?e_?m': 'file system',
+               '(?i)u_?s_?e_?r_?n_?a_?m_?e':       'user name',
+               '[Vv]_?l_?a_?n':                    'VLAN',
+               '(?i)h_?o_?s_?t_?n_?a_?m_?e':       'hostname',
+               'Z_?F_?C_?P':                       'zFCP',
+               'z_?f_?c_?p':                       'zFCP',
+               'B_?T_?R_?F_?S':                    'Btrfs',
+               'b_?t_?r_?f_?s':                    'Btrfs',
+               '[Cc]an not':                       'can not',
+               '(?i)m_?o_?u_?n_?t_?p_?o_?i_?n_?t': 'mount point'}
+
+# Sometimes we need to use a bad string, or it's just too much of a pain to
+# write a more specific regex. List occurrences here.
+# {'filename': {'matched string', occurrences}}
+expected_badness = {'pyanaconda/bootloader.py': {'mountpoint': 1},  # format string specifier
+                    'pyanaconda/kickstart.py':  {'btrfs': 1},       # quoted filesystem type
+                    'pyanaconda/network.py':    {'vlan': 1}}        # format string specifier
+
+# 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}
+
+# Look for each of the bad regexes
+success = True
+for badre in bad_strings.keys():
+    regex = re.compile(badre)
+    for msg in msgs.keys():
+        match = re.search(regex, msg)
+        if match:
+            # If this is something expected, decrement the occurrence count in expected_badness
+            badstr = match.group(0)
+            remainder = []
+            for occur in msgs[msg].occurrences:
+                if occur[0] in expected_badness and badstr in expected_badness[occur[0]]:
+                    expected_badness[occur[0]][badstr] -= 1
+                    if expected_badness[occur[0]][badstr] == 0:
+                        del expected_badness[occur[0]][badstr]
+                    if not expected_badness[occur[0]]:
+                        del expected_badness[occur[0]]
+                else:
+                    remainder.append(occur)
+
+            if remainder:
+                print("Bad string %(bad)s found at %(occurrences)s. Try %(suggestion)s instead." %
+                        {"bad": badstr,
+                         "occurrences": " ".join(("%s:%s" % (o[0], o[1]) for o in remainder)),
+                         "suggestion": bad_strings[badre]})
+                success = False
+
+if expected_badness:
+    for filename in expected_badness.keys():
+        for badstr in expected_badness[filename].keys():
+            print("Did not find %d occurrences of %s in %s" %
+                    (expected_badness[filename][badstr], badstr, filename))
+    success = False
+
+sys.exit(0 if success else 1)
-- 
2.0.0



More information about the anaconda-patches mailing list