Fix and move keyword unit test

svn: r22759
This commit is contained in:
Nick Hall 2013-07-28 18:11:35 +00:00
parent 772cf39d7f
commit b3ddf9f83a
2 changed files with 58 additions and 65 deletions

View File

@ -0,0 +1,58 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2007 Donald N. Allingham
#
# 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# $Id$
""" Unittest for testing ... """
import unittest
from ..keyword import (KEYWORDS, get_translation_from_keyword,
get_keyword_from_translation)
class TestCase(unittest.TestCase):
def keyword_test(self, item1, item2):
result = get_translation_from_keyword(item1)
self.assertEqual(result, item2)
def translation_test(self, item1, item2):
result = get_keyword_from_translation(item1)
self.assertEqual(result, item2)
def test_from_keyword(self):
for keyword, code, standard, upper in KEYWORDS:
self.keyword_test(keyword, standard)
def test_from_translation(self):
for keyword, code, standard, upper in KEYWORDS:
self.translation_test(standard, keyword)
def test_from_lower(self):
for keyword, code, standard, upper in KEYWORDS:
self.translation_test(standard.lower(), keyword)
def test_from_upper(self):
for keyword, code, standard, upper in KEYWORDS:
self.translation_test(upper, keyword.upper())
if __name__ == "__main__":
unittest.main()

View File

@ -1,65 +0,0 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2007 Donald N. Allingham
#
# 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# $Id$
""" Unittest for testing ... """
import unittest
from .test import test_util
test_util.path_append_parent()
from gramps.gen.utils.keyword import (KEYWORDS, get_translation_from_keyword,
get_keyword_from_translation)
class TestCase(unittest.TestCase):
count = 1
def __init__(self, *args):
method_name = args[0] % self.count
TestCase.count += 1
self.__dict__[method_name] = lambda: self.helper(*args)
unittest.TestCase.__init__(self, method_name)
def helper(self, *args):
method_name, test_type, item1, item2 = args
if test_type == "keyword":
result = get_translation_from_keyword(item1)
self.assertTrue(result == item2,
"get_translation_from_keyword('%s') returned '%s' rather than '%s'" % (item1, result, item2))
elif test_type == "translation":
result = get_keyword_from_translation(item1)
self.assertTrue(result == item2,
"get_keyword_from_translation('%s') returned '%s' rather than '%s'" % (item1, result, item2))
else:
raise AttributeError("test called incorrectly")
def suite1():
"""
"""
suite = unittest.TestSuite()
for line in KEYWORDS:
keyword, code, standard, upper = line
suite.addTest(TestCase('keyword-%04d', 'keyword', keyword, standard))
suite.addTest(TestCase('translation-%04d', 'translation', standard, keyword))
suite.addTest(TestCase('translation-%04d', 'translation', standard.lower(), keyword))
suite.addTest(TestCase('translation-%04d', 'translation', upper, keyword.upper()))
return suite
if __name__ == "__main__":
unittest.TextTestRunner().run(suite1())