From: David Shea dshea@redhat.com
Also add a Makefile to make it easy to run pylint and maybe some other tests. --- .gitignore | 1 + Makefile | 7 +++++++ tests/pylint/runpylint.py | 17 +++++++++++++++++ translatable/__init__.py | 2 +- translatable/test_markup.py | 8 +++----- translated/__init__.py | 6 +++--- 6 files changed, 32 insertions(+), 9 deletions(-) create mode 100644 Makefile create mode 100755 tests/pylint/runpylint.py
diff --git a/.gitignore b/.gitignore index 8d35cb3..acf2e36 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ __pycache__ *.pyc +tests/pylint/.pylint.d diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..ff31c18 --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ +# This Makefile is just for running the tests + +all: + @echo "nothing to build" + +check: + tests/pylint/runpylint.py diff --git a/tests/pylint/runpylint.py b/tests/pylint/runpylint.py new file mode 100755 index 0000000..5807bfd --- /dev/null +++ b/tests/pylint/runpylint.py @@ -0,0 +1,17 @@ +#!/usr/bin/python3 + +import sys +from pocketlint import PocketLintConfig, PocketLinter + +class TranslationCanaryLintConfig(PocketLintConfig): + @property + def disabledOptions(self): + return [ "W9930", # Found interruptible system call %s + "I0011", # Locally disabling %s + ] + +if __name__ == "__main__": + conf = TranslationCanaryLintConfig() + linter = PocketLinter(conf) + rc = linter.run() + sys.exit(rc) diff --git a/translatable/__init__.py b/translatable/__init__.py index 9531aa2..3277ab3 100644 --- a/translatable/__init__.py +++ b/translatable/__init__.py @@ -61,7 +61,7 @@ def testString(poentry): for test in _tests: try: test(poentry) - except Exception as e: + except Exception as e: # pylint: disable=broad-except success = False print("%s failed on %s: %s" % (test.__name__, poentry.msgid, str(e)))
diff --git a/translatable/test_markup.py b/translatable/test_markup.py index 1faa6d6..fed02ed 100644 --- a/translatable/test_markup.py +++ b/translatable/test_markup.py @@ -21,10 +21,6 @@ from pocketlint.pangocheck import is_markup, markup_necessary import xml.etree.ElementTree as ET
-import gi -gi.require_version("GLib", "2.0") -from gi.repository import GLib - def test_markup(poentry): # Unnecessary markup is markup applied to an entire string, such as # _("<b>Bold Text</b>"). This could be instead be translated as @@ -33,6 +29,8 @@ def test_markup(poentry):
if is_markup(poentry.msgid): # Wrap the string in <markup> nodes, parse it, test it - tree = ET.fromstring("<markup>%s</markup>" % GLib.markup_escape_text(poentry.msgid)) + # The markup is unescaped on purpose + # pylint: disable=unescaped-markup + tree = ET.fromstring("<markup>%s</markup>" % poentry.msgid) if not markup_necessary(tree): raise AssertionError("Unnecessary markup") diff --git a/translated/__init__.py b/translated/__init__.py index af0af73..3f167ee 100644 --- a/translated/__init__.py +++ b/translated/__init__.py @@ -70,7 +70,7 @@ def testFile(mofile, prefix=None): # Print any warnings collected for warn in w: print("%s warned on %s: %s" % (test.__name__, moerror, warn.message)) - except Exception as e: + except Exception as e: # pylint: disable=broad-except success = False print("%s failed on %s: %s" % (test.__name__, moerror, str(e)))
@@ -88,8 +88,8 @@ def testArchive(archive): archive_dir = tempfile.mkdtemp(prefix='translation-tests.') try: shutil.unpack_archive(archive, archive_dir) - for dir, _dirnames, paths in os.walk(archive_dir): - for mofile in (os.path.join(dir, path) for path in paths + for dirpath, _dirnames, paths in os.walk(archive_dir): + for mofile in (os.path.join(dirpath, path) for path in paths if path.endswith('.mo') or path.endswith('.gmo')): if not testFile(mofile, prefix=archive_dir + "/"): success = False
anaconda-patches@lists.fedorahosted.org