def _parse_source(ancestry: _IntermediateAncestry, element: Element) -> None: handle = _xpath1(element, './@handle') source = Source(_xpath1(element, './@id'), _xpath1(element, './ns:stitle').text) repository_source_handle = _xpath1(element, './ns:reporef/@hlink') if repository_source_handle is not None: source.contained_by = ancestry.sources[repository_source_handle] _parse_objref(ancestry, source, element) ancestry.sources[handle] = source
def test_source_should_encode_full(self): source = Source('the_source', 'The Source') source.author = 'The Author' source.publisher = 'The Publisher' source.date = Date(2000, 1, 1) source.contained_by = Source('the_containing_source', 'The Containing Source') source.links.add( Link('https://example.com/the-person', 'The Person Online')) source.contains.append( Source('the_contained_source', 'The Contained Source')) source.citations.append( Citation('the_citation', Source('the_source', 'The Source'))) expected = { '$schema': '/schema.json#/definitions/source', '@context': { 'name': 'https://schema.org/name', }, '@type': 'https://schema.org/Thing', 'id': 'the_source', 'name': 'The Source', 'author': 'The Author', 'publisher': 'The Publisher', 'contains': [ '/source/the_contained_source/index.json', ], 'citations': [ '/citation/the_citation/index.json', ], 'containedBy': '/source/the_containing_source/index.json', 'date': { 'year': 2000, 'month': 1, 'day': 1, }, 'links': [ { 'url': 'https://example.com/the-person', 'label': 'The Person Online', }, ], } self.assert_encodes(expected, source, 'source')
def test_clean_should_not_clean_source_with_contains(self) -> None: ancestry = Ancestry() source = Source('S0', 'The Source') ancestry.sources[source.id] = source contains = Source('S1', 'The Source') contains.contained_by = source ancestry.sources[contains.id] = contains clean(ancestry) self.assertEqual(source, ancestry.sources[source.id]) self.assertEqual(source, contains.contained_by) self.assertEqual(contains, ancestry.sources[contains.id])
def _parse_source(ancestry: _IntermediateAncestry, element: Element) -> None: handle = _xpath1(element, './@handle') source = Source(_xpath1(element, './@id'), _xpath1(element, './ns:stitle').text) repository_source_handle = _xpath1(element, './ns:reporef/@hlink') if repository_source_handle is not None: source.contained_by = ancestry.sources[repository_source_handle] # Parse the author. sauthor_element = _xpath1(element, './ns:sauthor') if sauthor_element is not None: source.author = sauthor_element.text # Parse the publication info. spubinfo_element = _xpath1(element, './ns:spubinfo') if spubinfo_element is not None: source.publisher = spubinfo_element.text _parse_objref(ancestry, source, element) _parse_attribute_privacy(source, element) ancestry.sources[handle] = source
def test_contained_by(self) -> None: contained_by_source = Source() sut = Source() self.assertIsNone(sut.contained_by) sut.contained_by = contained_by_source self.assertEquals(contained_by_source, sut.contained_by)
def test_should_remove_contained_by(self) -> None: source = Source('S0', 'The Source') contained_by = Source('S1', 'The Source') source.contained_by = contained_by anonymize_source(source) self.assertIsNone(source.contained_by)