def derive(cls, person: Person, derivable_event: Event, reference_event_type_types: Set[Type[EventType]]) -> bool: if not reference_event_type_types: return False reference_events = _get_reference_events(person, reference_event_type_types) reference_events_dates = cls._get_events_dates(reference_events) reference_events_dates = filter(lambda x: x[1].comparable, reference_events_dates) if derivable_event.date is not None: reference_events_dates = filter( lambda x: cls._compare(derivable_event.date, x[1]), reference_events_dates) reference_events_dates = cls._sort(reference_events_dates) try: reference_event, reference_date = reference_events_dates[0] except IndexError: return False if derivable_event.date is None: derivable_event.date = DateRange() cls._set(derivable_event, DerivedDate.derive(reference_date)) derivable_event.citations.append(*reference_event.citations) return True
async def test_with_date(self): event = Event(Birth()) event.date = Date(1970) expected = '1970' async with self._render(data={ 'event': event, }) as (actual, _): self.assertEqual(expected, actual)
async def test_with_date_and_place(self): event = Event(Birth()) event.date = Date(1970) event.place = Place('P0', [PlaceName('The Place')]) expected = '1970 in <address><a href="/place/P0/index.html"><span>The Place</span></a></address>' async with self._render(data={ 'event': event, }) as (actual, _): self.assertEqual(expected, actual)
async def test_embedded(self): event = Event(Birth()) event.date = Date(1970) event.place = Place('P0', [PlaceName('The Place')]) event.citations.append(Citation(Source('The Source'))) expected = '1970 in <address><span>The Place</span></address>' async with self._render(data={ 'event': event, 'embedded': True, }) as (actual, _): self.assertEqual(expected, actual)
def _parse_event(ancestry: _IntermediateAncestry, element: Element): handle = str(_xpath1(element, './@handle')) gramps_type = _xpath1(element, './ns:type') event = Event(_xpath1(element, './@id'), _EVENT_TYPE_MAP[gramps_type.text]) event.date = _parse_date(element) # Parse the event place. place_handle = _xpath1(element, './ns:place/@hlink') if place_handle: event.place = ancestry.places[place_handle] _parse_objref(ancestry, event, element) citation_handles = _xpath(element, './ns:citationref/@hlink') for citation_handle in citation_handles: event.citations.add(ancestry.citations[citation_handle]) ancestry.events[handle] = event
def test_date(self) -> None: sut = Event(Mock(EventType)) self.assertIsNone(sut.date) date = Mock(Date) sut.date = date self.assertEquals(date, sut.date)
def test_date(self): sut = Event('1', Event.Type.BIRTH) self.assertIsNone(sut.date) date = Mock(Date) sut.date = date self.assertEquals(date, sut.date)