[apparmor] [patch] Add a test to check for hotkey conflicts
Christian Boltz
apparmor at cboltz.de
Sun Apr 3 16:05:03 UTC 2016
Hello,
this test builds and installs the apparmor-utils translations into a
tempdir, and then checks if there's any hotkey conflict in one of the
languages. This is based on a manually maintained list of "buttons" that
are displayed at the same time.
To make things a bit easier to test, add CMD_CANCEL to ui.py CMDS[].
Also replace hardcoded usage of '(Y)es', '(N)o' and '(C)ancel' with
CMDS['CMD_YES'], CMDS['CMD_NO'] and CMDS['CMD_CANCEL'].
Note: you'lll get hotkey conflicts for the german translations. I fixed
them on lp already, so importing the latest translations should help ;-)
[ 77-check-hotkey-conflicts.diff ]
--- utils/apparmor/ui.py 2014-11-17 20:18:13.810933000 +0100
+++ utils/apparmor/ui.py 2016-04-03 16:21:17.013134733 +0200
@@ -77,8 +77,8 @@
default = default.lower()
ans = None
if UI_mode == 'text':
- yes = _('(Y)es')
- no = _('(N)o')
+ yes = CMDS['CMD_YES']
+ no = CMDS['CMD_NO']
yeskey = get_translated_hotkey(yes).lower()
nokey = get_translated_hotkey(no).lower()
ans = 'XXXINVALIDXXX'
@@ -121,9 +121,9 @@
default = default.lower()
ans = None
if UI_mode == 'text':
- yes = _('(Y)es')
- no = _('(N)o')
- cancel = _('(C)ancel')
+ yes = CMDS['CMD_YES']
+ no = CMDS['CMD_NO']
+ cancel = CMDS['CMD_CANCEL']
yeskey = get_translated_hotkey(yes).lower()
nokey = get_translated_hotkey(no).lower()
@@ -274,6 +274,7 @@
'CMD_ASK_LATER': _('Ask Me (L)ater'),
'CMD_YES': _('(Y)es'),
'CMD_NO': _('(N)o'),
+ 'CMD_CANCEL': _('(C)ancel'),
'CMD_ALL_NET': _('Allow All (N)etwork'),
'CMD_NET_FAMILY': _('Allow Network Fa(m)ily'),
'CMD_OVERWRITE': _('(O)verwrite Profile'),
--- utils/test/test-translations.py 2016-04-03 18:00:50.303549877 +0200
+++ utils/test/test-translations.py 2016-04-03 18:00:03.555820261 +0200
@@ -0,0 +1,67 @@
+#! /usr/bin/env python
+# ------------------------------------------------------------------
+#
+# Copyright (C) 2016 Christian Boltz <apparmor at cboltz.de>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of version 2 of the GNU General Public
+# License published by the Free Software Foundation.
+#
+# ------------------------------------------------------------------
+
+import unittest
+from common_test import AATest, setup_all_loops
+
+import gettext
+import os
+import subprocess
+
+from apparmor.ui import CMDS, get_translated_hotkey
+
+class TestHotkeyConflicts(AATest):
+ # check if there are any hotkey conflicts in one of the apparmor-utils translations
+ tests = [
+ (['CMD_ALLOW', 'CMD_DENY', 'CMD_IGNORE_ENTRY', 'CMD_GLOB', 'CMD_GLOBEXT', 'CMD_NEW', 'CMD_AUDIT_OFF', 'CMD_ABORT', 'CMD_FINISHED'], True), # aa.py available_buttons() with CMD_AUDIT_OFF
+ (['CMD_ALLOW', 'CMD_DENY', 'CMD_IGNORE_ENTRY', 'CMD_GLOB', 'CMD_GLOBEXT', 'CMD_NEW', 'CMD_AUDIT_NEW', 'CMD_ABORT', 'CMD_FINISHED'], True), # aa.py available_buttons() with CMD_AUDIT_NEW
+ (['CMD_SAVE_CHANGES', 'CMD_SAVE_SELECTED', 'CMD_VIEW_CHANGES', 'CMD_VIEW_CHANGES_CLEAN', 'CMD_ABORT'], True), # aa.py save_profiles()
+ (['CMD_VIEW_PROFILE', 'CMD_USE_PROFILE', 'CMD_CREATE_PROFILE', 'CMD_ABORT', 'CMD_FINISHED'], True), # aa.py get_profile()
+ (['CMD_UPLOAD_CHANGES', 'CMD_VIEW_CHANGES', 'CMD_ASK_LATER', 'CMD_ASK_NEVER', 'CMD_ABORT'], True), # aa.py console_select_and_upload_profiles()
+ (['CMD_ix', 'CMD_pix', 'CMD_cix', 'CMD_nix', 'CMD_EXEC_IX_OFF', 'CMD_ux', 'CMD_DENY', 'CMD_ABORT', 'CMD_FINISHED'], True), # aa.py build_x_functions() with exec_toggle
+ (['CMD_ix', 'CMD_cx', 'CMD_px', 'CMD_nx', 'CMD_ux', 'CMD_EXEC_IX_ON', 'CMD_DENY', 'CMD_ABORT', 'CMD_FINISHED'], True), # aa.py build_x_functions() without exec_toggle
+ (['CMD_ADDHAT', 'CMD_USEDEFAULT', 'CMD_DENY', 'CMD_ABORT', 'CMD_FINISHED'], True), # aa.py handle_children()
+ (['CMD_YES', 'CMD_NO', 'CMD_CANCEL'], True), # ui.py UI_YesNo() and UI_YesNoCancel
+ ]
+
+ def _run_test(self, params, expected):
+ self.createTmpdir()
+
+ subprocess.call("make -C ../po >/dev/null", shell=True)
+ subprocess.call("DESTDIR=%s NAME=apparmor-utils make -C ../po install >/dev/null" % self.tmpdir, shell=True)
+
+ self.localedir = '%s/usr/share/locale' % self.tmpdir
+
+ self.languages = os.listdir(self.localedir)
+
+ # make sure we found all translations
+ if len(self.languages) < 15:
+ raise Exception('None or not all languages found, only %s' % self.languages)
+
+ self.languages.append('C') # we also want to detect hotkey conflicts in the untranslated english strings
+
+ for language in self.languages:
+ t = gettext.translation('apparmor-utils', fallback=True, localedir=self.localedir, languages=[language])
+
+ keys = dict()
+ for key in params:
+ text = t.gettext(CMDS[key])
+ hotkey = get_translated_hotkey(text)
+
+ if keys.get(hotkey):
+ raise Exception("Hotkey conflict: '%s' and '%s' in language %s" % (keys[hotkey], text, language))
+ else:
+ keys[hotkey] = text
+
+
+setup_all_loops(__name__)
+if __name__ == '__main__':
+ unittest.main(verbosity=2)
Regards,
Christian Boltz
--
PATH="${HOME}/Oktoberfest 2003:$PATH"
configure '--prefix=Auf geht\'s'
[Ralf Corsepius in suse-programming]
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part.
URL: <https://lists.ubuntu.com/archives/apparmor/attachments/20160403/756da955/attachment.pgp>
More information about the AppArmor
mailing list