2007-12-08 10:32:09 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
|
|
|
# Copyright (C) 2007 Donald N. Allingham
|
2010-10-29 22:58:06 +05:30
|
|
|
# Copyright (C) 2010 Jerome Rapinat
|
2007-12-08 10:32:09 +05:30
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
2016-05-18 15:17:34 +05:30
|
|
|
# This program is distributed in the hope that it will be useful,
|
2007-12-08 10:32:09 +05:30
|
|
|
# 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
|
2014-08-09 07:59:07 +05:30
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2007-12-08 10:32:09 +05:30
|
|
|
#
|
|
|
|
|
|
|
|
""" Unittest for testing POTFILES.in and Makefile contents """
|
|
|
|
|
2012-11-10 16:56:14 +05:30
|
|
|
# PYTHONPATH=/../gramps python po_test.py
|
2010-05-09 22:15:53 +05:30
|
|
|
|
2007-12-08 10:32:09 +05:30
|
|
|
import unittest
|
|
|
|
import os
|
|
|
|
import glob
|
|
|
|
from test import test_util
|
2023-07-31 19:10:59 +05:30
|
|
|
|
2016-05-18 15:17:34 +05:30
|
|
|
test_util.path_append_parent()
|
2007-12-08 10:32:09 +05:30
|
|
|
|
2023-07-31 19:10:59 +05:30
|
|
|
|
2007-12-08 10:32:09 +05:30
|
|
|
def get_potfile(filename):
|
2016-04-19 04:38:21 +05:30
|
|
|
with open(filename, "r") as fp:
|
|
|
|
retvals = []
|
|
|
|
for line in fp:
|
|
|
|
if line and line[0] != "#":
|
|
|
|
retvals.append(line.strip())
|
2007-12-08 10:32:09 +05:30
|
|
|
return retvals
|
|
|
|
|
2023-07-31 19:10:59 +05:30
|
|
|
|
2010-05-09 22:15:53 +05:30
|
|
|
# POTFILES.skip
|
|
|
|
|
|
|
|
excluded_files = get_potfile("../POTFILES.skip")
|
|
|
|
|
2023-07-31 19:10:59 +05:30
|
|
|
|
2007-12-08 10:32:09 +05:30
|
|
|
class TestPOT(unittest.TestCase):
|
|
|
|
potfiles = get_potfile("../POTFILES.in")
|
|
|
|
count = 1
|
2023-07-31 19:10:59 +05:30
|
|
|
|
2007-12-09 02:58:10 +05:30
|
|
|
def __init__(self, method_name, dir, file, searches):
|
2007-12-08 10:32:09 +05:30
|
|
|
method_name = method_name % self.count
|
|
|
|
TestPOT.count += 1
|
2007-12-09 02:58:10 +05:30
|
|
|
self.__dict__[method_name] = lambda: self.helper(dir, file, searches)
|
2007-12-08 10:32:09 +05:30
|
|
|
unittest.TestCase.__init__(self, method_name)
|
|
|
|
|
2007-12-09 02:58:10 +05:30
|
|
|
def helper(self, dir, file, searches):
|
2007-12-08 10:32:09 +05:30
|
|
|
realpath = dir + "/" + file
|
|
|
|
pathfile = realpath[3:]
|
|
|
|
if os.path.exists(realpath):
|
2016-04-19 04:38:21 +05:30
|
|
|
with open(realpath, "r") as fp:
|
|
|
|
lines = fp.read()
|
2007-12-09 02:58:10 +05:30
|
|
|
found = False
|
|
|
|
for search in searches:
|
|
|
|
if search in lines:
|
|
|
|
found = True
|
|
|
|
if found:
|
2007-12-08 10:32:09 +05:30
|
|
|
self.assertFalse(
|
|
|
|
pathfile[3:] not in excluded_files
|
2016-05-18 15:17:34 +05:30
|
|
|
and pathfile[3:] not in self.potfiles,
|
2007-12-08 10:32:09 +05:30
|
|
|
"'%s' is not in POTFILES.in" % (pathfile[3:],),
|
|
|
|
)
|
|
|
|
else:
|
2016-05-18 15:17:34 +05:30
|
|
|
self.assertTrue(True, "'%s' doesn't contain '%s'" % (file, search))
|
2007-12-08 10:32:09 +05:30
|
|
|
else:
|
|
|
|
self.assertTrue(True, "'%s' doesn't exist" % file)
|
|
|
|
|
2023-07-31 19:10:59 +05:30
|
|
|
|
2007-12-08 10:32:09 +05:30
|
|
|
class TestMake(unittest.TestCase):
|
|
|
|
count = 1
|
2023-07-31 19:10:59 +05:30
|
|
|
|
2007-12-08 10:32:09 +05:30
|
|
|
def __init__(self, method_name, dir, file):
|
|
|
|
method_name = method_name % self.count
|
|
|
|
TestMake.count += 1
|
|
|
|
self.__dict__[method_name] = lambda: self.helper(dir, file)
|
|
|
|
unittest.TestCase.__init__(self, method_name)
|
|
|
|
|
|
|
|
def helper(self, dir, file):
|
|
|
|
realpath = dir + "/" + file
|
|
|
|
pathfile = realpath[3:]
|
|
|
|
path, filename = realpath.rsplit("/", 1)
|
|
|
|
makefile = path + "/Makefile.in"
|
|
|
|
if pathfile[3:] in excluded_files:
|
|
|
|
self.assertTrue(True, "exclude '%s'" % pathfile)
|
|
|
|
elif os.path.exists(makefile):
|
2016-04-19 04:38:21 +05:30
|
|
|
with open(makefile, "r") as fp:
|
|
|
|
lines = fp.read()
|
2016-05-18 15:17:34 +05:30
|
|
|
self.assertTrue(
|
|
|
|
filename in lines, "'%s' not in %s/Makefile.in" % (filename, path)
|
2007-12-08 10:32:09 +05:30
|
|
|
)
|
|
|
|
else:
|
|
|
|
self.assertTrue(True, "no makefile in '%s'" % dir)
|
|
|
|
|
2023-07-31 19:10:59 +05:30
|
|
|
|
2007-12-08 20:59:10 +05:30
|
|
|
class TestGetText(unittest.TestCase):
|
|
|
|
count = 1
|
2023-07-31 19:10:59 +05:30
|
|
|
|
2007-12-08 20:59:10 +05:30
|
|
|
def __init__(self, method_name, pofile, searches):
|
|
|
|
method_name = method_name % self.count
|
|
|
|
TestGetText.count += 1
|
|
|
|
self.__dict__[method_name] = lambda: self.helper(pofile, searches)
|
|
|
|
unittest.TestCase.__init__(self, method_name)
|
|
|
|
|
|
|
|
def helper(self, pofile, searches):
|
|
|
|
if not os.path.exists("../../" + pofile):
|
|
|
|
self.assertTrue(False, "'%s' is in POTFILES.in and does not exist" % pofile)
|
2016-04-19 04:38:21 +05:30
|
|
|
with open("../../" + pofile, "r") as fp:
|
|
|
|
lines = fp.read()
|
2007-12-08 20:59:10 +05:30
|
|
|
found = False
|
|
|
|
for search in searches:
|
|
|
|
found = (search in lines) or found
|
2016-05-18 15:17:34 +05:30
|
|
|
self.assertTrue(
|
|
|
|
found,
|
|
|
|
"'%s' is in POTFILES.in but does not contain '%s'" % (pofile, searches),
|
2007-12-08 20:59:10 +05:30
|
|
|
)
|
2023-07-31 19:10:59 +05:30
|
|
|
|
2007-12-08 20:59:10 +05:30
|
|
|
|
2007-12-09 02:58:10 +05:30
|
|
|
class TestDups(unittest.TestCase):
|
|
|
|
potfiles = get_potfile("../POTFILES.in")
|
|
|
|
count = 1
|
2023-07-31 19:10:59 +05:30
|
|
|
|
2007-12-09 02:58:10 +05:30
|
|
|
def __init__(self, method_name, potfile):
|
|
|
|
method_name = method_name % self.count
|
|
|
|
TestPOT.count += 1
|
|
|
|
self.__dict__[method_name] = lambda: self.helper(potfile)
|
|
|
|
unittest.TestCase.__init__(self, method_name)
|
|
|
|
|
|
|
|
def helper(self, potfile):
|
|
|
|
self.assertTrue(
|
|
|
|
self.potfiles.count(potfile) == 1,
|
|
|
|
"'%s' is in POTFILE.in more than once." % potfile,
|
|
|
|
)
|
2023-07-31 19:10:59 +05:30
|
|
|
|
2007-12-09 02:58:10 +05:30
|
|
|
|
2007-12-08 10:32:09 +05:30
|
|
|
def suite1():
|
2007-12-09 02:58:10 +05:30
|
|
|
"""
|
|
|
|
Suite of tests designed to see if that if one of a set of phrases
|
|
|
|
is in a file, then that file better be in POTFILES.in.
|
|
|
|
"""
|
2016-05-18 15:17:34 +05:30
|
|
|
suite = unittest.TestSuite()
|
2007-12-08 10:32:09 +05:30
|
|
|
for dir, subdir, files in os.walk("../../src"):
|
|
|
|
for file in files:
|
|
|
|
if glob.fnmatch.fnmatch(file, "*.py"):
|
2016-05-18 15:17:34 +05:30
|
|
|
suite.addTest(
|
|
|
|
TestPOT(
|
|
|
|
"test_pot_py_%04d",
|
2007-12-09 02:58:10 +05:30
|
|
|
dir,
|
|
|
|
file,
|
|
|
|
["import gettext", "import sgettext"],
|
|
|
|
)
|
2023-07-31 19:10:59 +05:30
|
|
|
)
|
2007-12-08 10:32:09 +05:30
|
|
|
elif glob.fnmatch.fnmatch(file, "*.glade"):
|
2016-05-18 15:17:34 +05:30
|
|
|
suite.addTest(
|
2007-12-09 02:58:10 +05:30
|
|
|
TestPOT("test_pot_glade_%04d", dir, file, ['translatable="yes"'])
|
2023-07-31 19:10:59 +05:30
|
|
|
)
|
2007-12-08 10:32:09 +05:30
|
|
|
if glob.fnmatch.fnmatch(file, "*.py"):
|
|
|
|
suite.addTest(TestMake("test_make_py_%04d", dir, file))
|
|
|
|
elif glob.fnmatch.fnmatch(file, "*.glade"):
|
|
|
|
suite.addTest(TestMake("test_make_glade_%04d", dir, file))
|
|
|
|
return suite
|
|
|
|
|
2023-07-31 19:10:59 +05:30
|
|
|
|
2007-12-08 20:59:10 +05:30
|
|
|
def suite2():
|
2007-12-09 02:58:10 +05:30
|
|
|
"""
|
|
|
|
Suite of tests that check for each file in POTFILES.in, then it
|
|
|
|
should have an import gettext or sgettext.
|
|
|
|
"""
|
2007-12-08 20:59:10 +05:30
|
|
|
suite = unittest.TestSuite()
|
|
|
|
potfiles = get_potfile("../POTFILES.in")
|
|
|
|
for potfile in potfiles:
|
2010-10-29 22:58:06 +05:30
|
|
|
# do not call gettext
|
|
|
|
if glob.fnmatch.fnmatch(potfile, "*.gpr.py"):
|
|
|
|
continue
|
|
|
|
# special case
|
|
|
|
if glob.fnmatch.fnmatch(potfile, "src/plugins/lib/libnarrate.py"):
|
|
|
|
continue
|
2007-12-08 20:59:10 +05:30
|
|
|
if glob.fnmatch.fnmatch(potfile, "*.py"):
|
|
|
|
suite.addTest(
|
|
|
|
TestGetText(
|
|
|
|
"test_gettext_py_%04d",
|
|
|
|
potfile,
|
2012-11-10 16:56:14 +05:30
|
|
|
["import gettext", "from gramps.gen.ggettext", "import sgettext"],
|
2007-12-09 02:58:10 +05:30
|
|
|
)
|
2023-07-31 19:10:59 +05:30
|
|
|
)
|
2007-12-09 02:58:10 +05:30
|
|
|
elif glob.fnmatch.fnmatch(potfile, "*.glade"):
|
2007-12-08 20:59:10 +05:30
|
|
|
suite.addTest(
|
|
|
|
TestGetText("test_gettext_glade_%04d", potfile, ['translatable="yes"'])
|
|
|
|
)
|
|
|
|
return suite
|
|
|
|
|
2023-07-31 19:10:59 +05:30
|
|
|
|
2007-12-09 02:58:10 +05:30
|
|
|
def suite3():
|
|
|
|
"""
|
|
|
|
Looks for duplicates in POTFILES.in.
|
|
|
|
"""
|
|
|
|
suite = unittest.TestSuite()
|
|
|
|
for potfile in set(get_potfile("../POTFILES.in")):
|
|
|
|
if potfile:
|
|
|
|
suite.addTest(TestDups("test_dups_%04d", potfile))
|
|
|
|
return suite
|
|
|
|
|
2023-07-31 19:10:59 +05:30
|
|
|
|
2007-12-08 10:32:09 +05:30
|
|
|
if __name__ == "__main__":
|
|
|
|
unittest.TextTestRunner().run(suite1())
|
2010-10-30 00:05:18 +05:30
|
|
|
unittest.TextTestRunner().run(suite2())
|
2007-12-09 02:58:10 +05:30
|
|
|
unittest.TextTestRunner().run(suite3())
|