linkchecker/tests/test_po.py
calvin 3eac1be9ab Require and use Python 2.5
Use Python 2.5 features and get rid of old compat code. Also some
code cleanups have been made.


git-svn-id: https://linkchecker.svn.sourceforge.net/svnroot/linkchecker/trunk/linkchecker@3737 e7d03fd6-7b0d-0410-9947-9c21f3af8025
2008-04-27 11:39:21 +00:00

74 lines
2.3 KiB
Python

# -*- coding: iso-8859-1 -*-
# Copyright (C) 2005 Joe Wreschnig
# Copyright (C) 2005-2008 Bastian Kleineidam
#
# 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.
#
# 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., 675 Mass Ave, Cambridge, MA 02139, USA.
"""
Test gettext .po files.
"""
import unittest
import os
import glob
from tests import make_suite
pofiles = None
def get_pofiles ():
"""Find all .po files in this source."""
global pofiles
if pofiles is None:
pofiles = []
pofiles.extend(glob.glob("po/*.po"))
pofiles.extend(glob.glob("doc/*.po"))
return pofiles
class TestPo (unittest.TestCase):
"""Test .po file syntax."""
needed_resources = ['posix', 'msgfmt']
def test_pos (self):
"""Test .po files syntax."""
for f in get_pofiles():
ret = os.system("msgfmt -c -o - %s > /dev/null" % f)
self.assertEquals(ret, 0, msg="PO-file syntax error in %r" % f)
class TestGTranslator (unittest.TestCase):
"""GTranslator displays a middot · for a space. Unfortunately, it
gets copied with copy-and-paste, what a shame."""
def test_gtranslator (self):
"""Test all pofiles for GTranslator brokenness."""
for f in get_pofiles():
fd = file(f)
try:
self.check_file(fd, f)
finally:
fd.close()
def check_file (self, fd, f):
"""Test for GTranslator broken syntax."""
for line in fd:
if line.strip().startswith("#"):
continue
self.failIf("\xc2\xb7" in line,
"Broken GTranslator copy/paste in %r:\n%r" % (f, line))
def test_suite ():
"""Build and return a TestSuite."""
prefix = __name__.split(".")[-1]
return make_suite(prefix, globals())