diff --git a/gramps/gen/filters/rules/test/event_rules_test.py b/gramps/gen/filters/rules/test/event_rules_test.py index 010706996..98dd227df 100644 --- a/gramps/gen/filters/rules/test/event_rules_test.py +++ b/gramps/gen/filters/rules/test/event_rules_test.py @@ -28,6 +28,7 @@ from ....db.utils import import_as_dict from ....filters import GenericFilterFactory from ....const import DATA_DIR from ....user import User +from ....utils.unittest import localize_date from ..event import ( AllEvents, HasType, HasIdOf, HasGallery, RegExpIdOf, HasCitation, HasNote, @@ -171,7 +172,8 @@ class BaseTest(unittest.TestCase): """ 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([ 'a5af0ed4211095487d2', 'a5af0ed36793c1d3e05', 'a5af0ecfcc16ce7a96a'])) diff --git a/gramps/gen/filters/rules/test/family_rules_test.py b/gramps/gen/filters/rules/test/family_rules_test.py index 7b626e788..7ff0b6e8d 100644 --- a/gramps/gen/filters/rules/test/family_rules_test.py +++ b/gramps/gen/filters/rules/test/family_rules_test.py @@ -28,6 +28,7 @@ from ....db.utils import import_as_dict from ....filters import GenericFilterFactory from ....const import DATA_DIR from ....user import User +from ....utils.unittest import localize_date from ..family import ( AllFamilies, HasRelType, HasGallery, HasIdOf, HasLDS, HasNote, RegExpIdOf, @@ -176,7 +177,8 @@ class BaseTest(unittest.TestCase): """ 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([ 'KSFKQCP4V0YXGM1LR9', '8ZFKQC3FRSHACOJBOU', '3XFKQCE7QUDJ99AVNV', 'OVFKQC51DX0OQUV3JB', '9OUJQCBOHW9UEK9CNV'])) diff --git a/gramps/gen/filters/rules/test/person_rules_test.py b/gramps/gen/filters/rules/test/person_rules_test.py index beb982f22..84f772579 100644 --- a/gramps/gen/filters/rules/test/person_rules_test.py +++ b/gramps/gen/filters/rules/test/person_rules_test.py @@ -32,6 +32,7 @@ from ....db.utils import import_as_dict from ....filters import GenericFilter, CustomFilters from ....const import DATA_DIR from ....user import User +from ....utils.unittest import localize_date from ..person import ( Disconnected, Everyone, FamilyWithIncompleteEvent, HasAddress, @@ -238,7 +239,8 @@ class BaseTest(unittest.TestCase): """ 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) self.assertEqual(len(res), 2) @@ -246,7 +248,8 @@ class BaseTest(unittest.TestCase): """ 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) self.assertEqual(len(res), 2) @@ -254,8 +257,8 @@ class BaseTest(unittest.TestCase): """ Test rule. """ - rule = HasEvent(['Birth', 'between 1600 and 1700', 'akron', - '', '', 1]) + date_str = localize_date('between 1600 and 1700') + rule = HasEvent(['Birth', date_str, 'akron', '', '', 1]) res = self.filter_with_rule(rule) self.assertEqual(len(res), 2) @@ -271,7 +274,8 @@ class BaseTest(unittest.TestCase): """ 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) self.assertEqual(len(res), 4) diff --git a/gramps/gen/utils/unittest.py b/gramps/gen/utils/unittest.py new file mode 100644 index 000000000..f2c89dc26 --- /dev/null +++ b/gramps/gen/utils/unittest.py @@ -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) diff --git a/po/POTFILES.skip b/po/POTFILES.skip index 5237f422e..17747b8bb 100644 --- a/po/POTFILES.skip +++ b/po/POTFILES.skip @@ -280,6 +280,7 @@ gramps/gen/utils/lru.py gramps/gen/utils/maclocale.py gramps/gen/utils/resourcepath.py gramps/gen/utils/thumbnails.py +gramps/gen/utils/unittest.py # # gen.utils.docgen #