Fix unit tests requiring English locale

This commit is contained in:
Nick Hall 2022-02-26 21:02:56 +00:00
parent d627d5648a
commit 2a9525c942
5 changed files with 62 additions and 7 deletions

View File

@ -28,6 +28,7 @@ from ....db.utils import import_as_dict
from ....filters import GenericFilterFactory from ....filters import GenericFilterFactory
from ....const import DATA_DIR from ....const import DATA_DIR
from ....user import User from ....user import User
from ....utils.unittest import localize_date
from ..event import ( from ..event import (
AllEvents, HasType, HasIdOf, HasGallery, RegExpIdOf, HasCitation, HasNote, AllEvents, HasType, HasIdOf, HasGallery, RegExpIdOf, HasCitation, HasNote,
@ -171,7 +172,8 @@ class BaseTest(unittest.TestCase):
""" """
Test HasData rule. Test HasData rule.
""" """
rule = HasData(['Burial', 'before 1800', 'USA', '']) date_str = localize_date('before 1800')
rule = HasData(['Burial', date_str, 'USA', ''])
self.assertEqual(self.filter_with_rule(rule), set([ self.assertEqual(self.filter_with_rule(rule), set([
'a5af0ed4211095487d2', 'a5af0ed36793c1d3e05', 'a5af0ed4211095487d2', 'a5af0ed36793c1d3e05',
'a5af0ecfcc16ce7a96a'])) 'a5af0ecfcc16ce7a96a']))

View File

@ -28,6 +28,7 @@ from ....db.utils import import_as_dict
from ....filters import GenericFilterFactory from ....filters import GenericFilterFactory
from ....const import DATA_DIR from ....const import DATA_DIR
from ....user import User from ....user import User
from ....utils.unittest import localize_date
from ..family import ( from ..family import (
AllFamilies, HasRelType, HasGallery, HasIdOf, HasLDS, HasNote, RegExpIdOf, AllFamilies, HasRelType, HasGallery, HasIdOf, HasLDS, HasNote, RegExpIdOf,
@ -176,7 +177,8 @@ class BaseTest(unittest.TestCase):
""" """
Test HasEvent rule. Test HasEvent rule.
""" """
rule = HasEvent(['Marriage', 'before 1900', 'USA', '', 'Garner']) date_str = localize_date('before 1900')
rule = HasEvent(['Marriage', date_str, 'USA', '', 'Garner'])
self.assertEqual(self.filter_with_rule(rule), set([ self.assertEqual(self.filter_with_rule(rule), set([
'KSFKQCP4V0YXGM1LR9', '8ZFKQC3FRSHACOJBOU', '3XFKQCE7QUDJ99AVNV', 'KSFKQCP4V0YXGM1LR9', '8ZFKQC3FRSHACOJBOU', '3XFKQCE7QUDJ99AVNV',
'OVFKQC51DX0OQUV3JB', '9OUJQCBOHW9UEK9CNV'])) 'OVFKQC51DX0OQUV3JB', '9OUJQCBOHW9UEK9CNV']))

View File

@ -32,6 +32,7 @@ from ....db.utils import import_as_dict
from ....filters import GenericFilter, CustomFilters from ....filters import GenericFilter, CustomFilters
from ....const import DATA_DIR from ....const import DATA_DIR
from ....user import User from ....user import User
from ....utils.unittest import localize_date
from ..person import ( from ..person import (
Disconnected, Everyone, FamilyWithIncompleteEvent, HasAddress, Disconnected, Everyone, FamilyWithIncompleteEvent, HasAddress,
@ -238,7 +239,8 @@ class BaseTest(unittest.TestCase):
""" """
Test rule. Test rule.
""" """
rule = HasBirth(['between 1600 and 1700', 'akron', '']) date_str = localize_date('between 1600 and 1700')
rule = HasBirth([date_str, 'akron', ''])
res = self.filter_with_rule(rule) res = self.filter_with_rule(rule)
self.assertEqual(len(res), 2) self.assertEqual(len(res), 2)
@ -246,7 +248,8 @@ class BaseTest(unittest.TestCase):
""" """
Test HasDeath rule. Test HasDeath rule.
""" """
rule = HasDeath(['between 1600 and 1700', 'ashtabula', '']) date_str = localize_date('between 1600 and 1700')
rule = HasDeath([date_str, 'ashtabula', ''])
res = self.filter_with_rule(rule) res = self.filter_with_rule(rule)
self.assertEqual(len(res), 2) self.assertEqual(len(res), 2)
@ -254,8 +257,8 @@ class BaseTest(unittest.TestCase):
""" """
Test rule. Test rule.
""" """
rule = HasEvent(['Birth', 'between 1600 and 1700', 'akron', date_str = localize_date('between 1600 and 1700')
'', '', 1]) rule = HasEvent(['Birth', date_str, 'akron', '', '', 1])
res = self.filter_with_rule(rule) res = self.filter_with_rule(rule)
self.assertEqual(len(res), 2) self.assertEqual(len(res), 2)
@ -271,7 +274,8 @@ class BaseTest(unittest.TestCase):
""" """
Test rule. Test rule.
""" """
rule = HasFamilyEvent(['Marriage', 'after 1900', 'craw', '']) date_str = localize_date('after 1900')
rule = HasFamilyEvent(['Marriage', date_str, 'craw', ''])
res = self.filter_with_rule(rule) res = self.filter_with_rule(rule)
self.assertEqual(len(res), 4) self.assertEqual(len(res), 4)

View File

@ -0,0 +1,46 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2022 Nick Hall
#
# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
"""
Utilities used in unit tests.
"""
#-------------------------------------------------------------------------
#
# Gramps classes
#
#-------------------------------------------------------------------------
from ..utils.grampslocale import GrampsLocale
#-------------------------------------------------------------------------
#
# Unit test utilities
#
#-------------------------------------------------------------------------
parser = GrampsLocale(lang='en').date_parser
displayer = GrampsLocale().date_displayer
def localize_date(date_str):
"""
Translate a date into the current locale.
"""
date = parser.parse(date_str)
return displayer.display(date)

View File

@ -280,6 +280,7 @@ gramps/gen/utils/lru.py
gramps/gen/utils/maclocale.py gramps/gen/utils/maclocale.py
gramps/gen/utils/resourcepath.py gramps/gen/utils/resourcepath.py
gramps/gen/utils/thumbnails.py gramps/gen/utils/thumbnails.py
gramps/gen/utils/unittest.py
# #
# gen.utils.docgen # gen.utils.docgen
# #