7197: readjust sanity date wrt newyear/slash

Attempt to fix the failing
 DateHandlerTest.test_invalid_month_with_ny
(see 7197:32625). Tests still fail, investigation shows
there's a problem in Date.set setting Julian+Mar25 date even if the
date validation check is disabled by inserting a return before
the validation block, i.e., before this line
        if modifier != Date.MOD_TEXTONLY:
which seems to be the root cause of the remaining failing tests.

To investigate, add the return and try
LC_ALL=en_GB.utf8 LANG=en_GB.utf8 GRAMPS_RESOURCES=$PWD \
 python -m unittest -v \
 gramps.gen.lib.test.date_test.MatchDateTest.test_match
This commit is contained in:
Vassilii Khachaturov 2013-11-14 22:45:42 +02:00
parent 93ca90f3b8
commit baae6ac615

View File

@ -1635,6 +1635,14 @@ class Date(object):
if modifier != Date.MOD_TEXTONLY: if modifier != Date.MOD_TEXTONLY:
sanity = Date(self) sanity = Date(self)
sanity.convert_calendar(self.calendar, known_valid = False) sanity.convert_calendar(self.calendar, known_valid = False)
# convert_calendar resets slash and new year, restore these as needed
if sanity.get_slash() != self.get_slash():
sanity.set_slash(self.get_slash())
if self.is_compound() and sanity.get_slash2() != self.get_slash2():
sanity.set_slash2(self.get_slash2())
if sanity.get_new_year() != self.get_new_year():
sanity.set_new_year(self.get_new_year())
sanity._adjust_newyear()
# We don't do the roundtrip conversion on self, becaue # We don't do the roundtrip conversion on self, becaue
# it would remove uncertainty on day/month expressed with zeros # it would remove uncertainty on day/month expressed with zeros
@ -1642,17 +1650,16 @@ class Date(object):
# Did the roundtrip change the date value?! # Did the roundtrip change the date value?!
if sanity.dateval != value: if sanity.dateval != value:
try: try:
if sanity.get_new_year() != self.get_new_year():
# convert_calendar resets the new year, so the date value will differ.
# Just check the sort value matches then.
if self.sortval != sanity.sortval:
raise DateError("Invalid date value {}".format(value))
else:
# Maybe it is OK because of undetermined value adjustment? # Maybe it is OK because of undetermined value adjustment?
zl = zip(sanity.dateval, value) zl = zip(sanity.dateval, value)
# Loop over all values present, whether compound or not # Loop over all values present, whether compound or not
for d,m,y,sl in zip(*[iter(zl)]*4): for d,m,y,sl in zip(*[iter(zl)]*4):
# each of d,m,y,sl is a pair from dateval and value, to compare # each of d,m,y,sl is a pair from dateval and value, to compare
adjusted,original = sl
if adjusted != original:
raise DateError("Invalid date value {}".
format(value))
for adjusted,original in d,m: for adjusted,original in d,m:
if adjusted != original and not(original == 0 and adjusted == 1): if adjusted != original and not(original == 0 and adjusted == 1):
raise DateError("Invalid day/month {} passed in value {}". raise DateError("Invalid day/month {} passed in value {}".
@ -1664,7 +1671,6 @@ class Date(object):
raise DateError("Invalid year {} passed in value {}". raise DateError("Invalid year {} passed in value {}".
format(original, value)) format(original, value))
# ignore slash difference
except DateError: except DateError:
log.debug("Sanity check failed - self: {}, sanity: {}".format( log.debug("Sanity check failed - self: {}, sanity: {}".format(
self.to_struct(), sanity.to_struct())) self.to_struct(), sanity.to_struct()))