7212: convert invalid date to text on .gw import

Add a failing test demonstrating the feature to be implemented...
This commit is contained in:
Vassilii Khachaturov 2013-11-27 17:54:44 +02:00
parent 3af50b0bea
commit 1ac0e2a0bc
2 changed files with 45 additions and 3 deletions

View File

@ -106,9 +106,10 @@ def importData(database, filename, user):
class GeneWebParser(object): class GeneWebParser(object):
def __init__(self, dbase, file): def __init__(self, dbase, file):
self.db = dbase self.db = dbase
self.f = open(file, "rU") if file: # Unit tests can create the parser w/o underlying file
self.filename = file self.f = open(file, "rU")
self.encoding = 'iso-8859-1' self.filename = file
self.encoding = 'iso-8859-1'
def get_next_line(self): def get_next_line(self):
self.lineno += 1 self.lineno += 1

View File

@ -0,0 +1,41 @@
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2013 Vassilii Khachaturov
#
# 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
#
"""
Unit test of the GeneWebParser
"""
from __future__ import print_function
import unittest
from ..importgeneweb import GeneWebParser
from ....gen.lib.date import Date
class ParseDateTest(unittest.TestCase):
def setUp(self):
self.parse = GeneWebParser(dbase=None, file=None).parse_date
def test_regular_date_parsed_dmy(self):
d = self.parse("28/2/1876")
self.assertEqual(d.get_dmy(), (28, 2, 1876))
def test_invalid_date_stays_verbatim_text(self):
text = "29/2/1875"
d = self.parse(text)
self.assertEqual(d.get_modifier(), Date.MOD_TEXTONLY)
self.assertEqual(d.get_text(), text)