2006-02-03 18:34:12 +00:00
|
|
|
# Copyright (C) 2005 Joe Wreschnig
|
2010-03-05 11:49:54 +00:00
|
|
|
# Copyright (C) 2005-2010 Bastian Kleineidam
|
2005-12-08 17:15:52 +00:00
|
|
|
#
|
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
|
# the Free Software Foundation; either version 2 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 General Public License for more details.
|
|
|
|
|
#
|
2009-07-24 21:58:20 +00:00
|
|
|
# You should have received a copy of the GNU General Public License along
|
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2005-12-17 19:21:40 +00:00
|
|
|
"""
|
|
|
|
|
Test gettext .po files.
|
|
|
|
|
"""
|
2005-12-08 17:15:52 +00:00
|
|
|
|
2006-04-24 20:17:30 +00:00
|
|
|
import unittest
|
2022-01-19 19:31:01 +00:00
|
|
|
import subprocess
|
2005-12-08 17:15:52 +00:00
|
|
|
import glob
|
2010-02-22 07:02:19 +00:00
|
|
|
from tests import need_msgfmt, need_posix
|
2005-12-08 17:15:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
pofiles = None
|
2010-03-13 07:47:12 +00:00
|
|
|
|
2020-05-28 19:29:13 +00:00
|
|
|
|
2020-05-16 19:19:42 +00:00
|
|
|
def get_pofiles():
|
2008-04-27 11:39:21 +00:00
|
|
|
"""Find all .po files in this source."""
|
2005-12-08 17:15:52 +00:00
|
|
|
global pofiles
|
|
|
|
|
if pofiles is None:
|
|
|
|
|
pofiles = []
|
|
|
|
|
pofiles.extend(glob.glob("po/*.po"))
|
2022-01-19 19:31:01 +00:00
|
|
|
pofiles.extend(glob.glob("doc/i18n/locales/**/*.po", recursive=True))
|
2020-06-05 15:59:46 +00:00
|
|
|
if not pofiles:
|
|
|
|
|
raise Exception("No .po files found")
|
2005-12-18 08:13:55 +00:00
|
|
|
return pofiles
|
2005-12-08 17:15:52 +00:00
|
|
|
|
2010-03-13 07:47:12 +00:00
|
|
|
|
2020-05-16 19:19:42 +00:00
|
|
|
class TestPo(unittest.TestCase):
|
2008-04-27 11:39:21 +00:00
|
|
|
"""Test .po file syntax."""
|
2005-12-08 17:15:52 +00:00
|
|
|
|
2010-02-22 07:02:19 +00:00
|
|
|
@need_posix
|
|
|
|
|
@need_msgfmt
|
2020-05-16 19:19:42 +00:00
|
|
|
def test_pos(self):
|
2008-04-27 11:39:21 +00:00
|
|
|
"""Test .po files syntax."""
|
2005-12-18 08:13:55 +00:00
|
|
|
for f in get_pofiles():
|
2022-01-19 19:31:01 +00:00
|
|
|
cp = subprocess.run(["msgfmt", "-c", "-o", "-", f], capture_output=True)
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
cp.returncode, 0,
|
|
|
|
|
msg=f"PO-file syntax error in {f!r}: {str(cp.stderr, 'utf-8')}")
|
2005-12-08 17:15:52 +00:00
|
|
|
|
|
|
|
|
|
2020-05-16 19:19:42 +00:00
|
|
|
class TestGTranslator(unittest.TestCase):
|
2020-05-17 18:48:41 +00:00
|
|
|
"""GTranslator displays a middot · for a space. Unfortunately, it
|
2008-04-27 11:39:21 +00:00
|
|
|
gets copied with copy-and-paste, what a shame."""
|
2005-12-08 17:15:52 +00:00
|
|
|
|
2020-05-16 19:19:42 +00:00
|
|
|
def test_gtranslator(self):
|
2008-04-27 11:39:21 +00:00
|
|
|
"""Test all pofiles for GTranslator brokenness."""
|
2005-12-18 08:13:55 +00:00
|
|
|
for f in get_pofiles():
|
2020-06-09 18:47:24 +00:00
|
|
|
with open(f, encoding="UTF-8") as fd:
|
2005-12-08 17:15:52 +00:00
|
|
|
self.check_file(fd, f)
|
|
|
|
|
|
2020-05-16 19:19:42 +00:00
|
|
|
def check_file(self, fd, f):
|
2008-04-27 11:39:21 +00:00
|
|
|
"""Test for GTranslator broken syntax."""
|
2005-12-08 17:15:52 +00:00
|
|
|
for line in fd:
|
2020-06-05 15:59:46 +00:00
|
|
|
if line.strip().startswith("#"):
|
2005-12-08 17:15:52 +00:00
|
|
|
continue
|
2020-05-28 19:29:13 +00:00
|
|
|
self.assertFalse(
|
2020-06-05 15:59:46 +00:00
|
|
|
"·" in line,
|
2022-11-08 19:21:29 +00:00
|
|
|
f"Broken GTranslator copy/paste in {f!r}:\n{line}",
|
2020-05-28 19:29:13 +00:00
|
|
|
)
|