[damned-lies] Fixed po_grep utility
- From: Claude Paroz <claudep src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [damned-lies] Fixed po_grep utility
- Date: Fri, 24 Feb 2017 22:58:56 +0000 (UTC)
commit 224e861ddd6f1a287e605e2aaed2b17b0ee28cbf
Author: Claude Paroz <claude 2xlibre net>
Date: Fri Feb 24 23:55:10 2017 +0100
Fixed po_grep utility
Fixes bug #779179.
stats/tests/tests.py | 22 +++++++++++++++++++---
stats/utils.py | 2 +-
2 files changed, 20 insertions(+), 4 deletions(-)
---
diff --git a/stats/tests/tests.py b/stats/tests/tests.py
index 1a39f42..43cff18 100644
--- a/stats/tests/tests.py
+++ b/stats/tests/tests.py
@@ -5,6 +5,7 @@ import tarfile
import tempfile
from datetime import date
from functools import wraps
+from unittest import skipUnless
from django.conf import settings
from django.contrib.auth.models import User
@@ -30,9 +31,9 @@ def test_scratchdir(test_func):
settings.SCRATCHDIR = os.path.join(tempfile.mkdtemp(), 'scratch')
settings.POTDIR = os.path.join(settings.SCRATCHDIR, "POT")
os.makedirs(settings.POTDIR)
- gnome_hello_tar = tarfile.open(os.path.join(os.path.dirname(os.path.abspath(__file__)),
'gnome-hello.tar.gz'))
- gnome_hello_tar.extractall(os.path.join(settings.SCRATCHDIR, 'git'))
- gnome_hello_tar.close()
+ tar_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'gnome-hello.tar.gz')
+ with tarfile.open(tar_path) as gnome_hello_tar:
+ gnome_hello_tar.extractall(os.path.join(settings.SCRATCHDIR, 'git'))
try:
test_func(self)
finally:
@@ -608,6 +609,21 @@ class UtilsTests(TestCase):
with open(linguas_path) as fh:
self.assertTrue(fh.read().endswith('xx\n'))
+ @skipUnless(utils.has_toolkit, "The Translate Toolkit is required for this test")
+ @test_scratchdir
+ def test_po_grep(self):
+ # This test fails, unless translate-toolkit is patched as presented in
+ # https://github.com/translate/translate/issues/2129
+ # Take it.po, because desktop.in.h strings are not yet translated
+ it_path = os.path.join(settings.SCRATCHDIR, 'git/gnome-hello/po/it.po')
+ temp_file = tempfile.NamedTemporaryFile(delete=False)
+ self.addCleanup(os.remove, temp_file.name)
+ utils.po_grep(it_path, temp_file.name, 'locations|desktop.in.h')
+ with open(temp_file.name, 'r') as fh:
+ content = fh.read()
+ self.assertGreater(len(content), 0)
+ self.assertNotIn('desktop.in.h', content)
+
class OtherTests(TestCase):
def test_release_list(self):
diff --git a/stats/utils.py b/stats/utils.py
index 53e3051..3163644 100644
--- a/stats/utils.py
+++ b/stats/utils.py
@@ -147,7 +147,7 @@ def po_grep(in_file, out_file, filter_):
# Probably bad filter syntax in DB (TODO: log it)
return
grepfilter = pogrep.GrepFilter(filter_str, filter_loc, useregexp=True, invertmatch=True,
keeptranslations=True)
- with open(out_file, "w") as out:
+ with open(out_file, "wb") as out:
pogrep.rungrep(in_file, out, None, grepfilter)
# command-line variant:
"""
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]