Back-port Nick's fix r22772

convert XML to use citations

svn: r22942
This commit is contained in:
Vassilii Khachaturov 2013-08-29 18:53:02 +00:00
parent 18786ae646
commit 3600d3f3c4

View File

@ -85,7 +85,7 @@ class BaseMergeCheck(unittest.TestCase):
<database xmlns="http://gramps-project.org/xml/%s/"> <database xmlns="http://gramps-project.org/xml/%s/">
<header> <header>
<created date="%04d-%02d-%02d" version="%s"/> <created date="%04d-%02d-%02d" version="%s"/>
<researcher/> <researcher>\n </researcher>
</header> </header>
""" % (GRAMPS_XML_VERSION, GRAMPS_XML_VERSION, GRAMPS_XML_VERSION, """ % (GRAMPS_XML_VERSION, GRAMPS_XML_VERSION, GRAMPS_XML_VERSION,
date[0], date[1], date[2], VERSION) date[0], date[1], date[2], VERSION)
@ -104,7 +104,7 @@ class BaseMergeCheck(unittest.TestCase):
:rtype: string :rtype: string
""" """
result = '' result = ''
if type(doctxt) == type('string'): if isinstance(doctxt, basestring):
doc = libxml2.readDoc(doctxt, '', None, libxml2.XML_PARSE_NONET) doc = libxml2.readDoc(doctxt, '', None, libxml2.XML_PARSE_NONET)
elif isinstance(doctxt, libxml2.xmlDoc): elif isinstance(doctxt, libxml2.xmlDoc):
doc = doctxt doc = doctxt
@ -114,14 +114,14 @@ class BaseMergeCheck(unittest.TestCase):
canonical_doc = self.style.applyStylesheet(doc, param) canonical_doc = self.style.applyStylesheet(doc, param)
result = self.style.saveResultToString(canonical_doc) result = self.style.saveResultToString(canonical_doc)
canonical_doc.freeDoc() canonical_doc.freeDoc()
if type(doctxt) == type('string'): if isinstance(doctxt, basestring):
doc.freeDoc() doc.freeDoc()
return result return result
def do_test(self, phoenix_id, titanic_id, input_doc, expect_doc, def do_test(self, phoenix_id, titanic_id, input_doc, expect_doc,
test_error_str='', debug=False): test_error_str='', debug=False):
"""Do the merge and "assert" the result.""" """Do the merge and "assert" the result."""
process = subprocess.Popen('python gramps.py -d .ImportXML ' process = subprocess.Popen('python Gramps.py -d .ImportXML '
'--config=preferences.eprefix:DEFAULT ' '--config=preferences.eprefix:DEFAULT '
'-i - -f gramps -a tool ' '-i - -f gramps -a tool '
'-p "name=climerge,primary=%s,secondary=%s" ' '-p "name=climerge,primary=%s,secondary=%s" '
@ -132,18 +132,18 @@ class BaseMergeCheck(unittest.TestCase):
result_str, err_str = process.communicate(str(input_doc)) result_str, err_str = process.communicate(str(input_doc))
if err_str: if err_str:
if test_error_str: if test_error_str:
self.assert_(test_error_str in err_str) self.assertIn(test_error_str, err_str)
return return
if debug: if debug:
print 'input :', self.canonicalize(input_doc) print('input :', self.canonicalize(input_doc))
print 'result:', self.canonicalize(result_str) print('result:', self.canonicalize(result_str))
print 'expect:', self.canonicalize(expect_doc) print('expect:', self.canonicalize(expect_doc))
self.assertEqual(self.canonicalize(result_str), self.assertEqual(self.canonicalize(result_str),
self.canonicalize(expect_doc)) self.canonicalize(expect_doc))
def do_family_test(self, phoenix_id, titanic_id, father_h, mother_h, def do_family_test(self, phoenix_id, titanic_id, father_h, mother_h,
input_doc, expect_doc, test_error_str='', debug=False): input_doc, expect_doc, test_error_str='', debug=False):
process = subprocess.Popen('python gramps.py -d .ImportXML ' process = subprocess.Popen('python Gramps.py -d .ImportXML '
'--config=preferences.eprefix:DEFAULT ' '--config=preferences.eprefix:DEFAULT '
'-i - -f gramps -a tool ' '-i - -f gramps -a tool '
'-p "name=climerge,primary=%s,secondary=%s,father_h=%s,mother_h=%s" ' '-p "name=climerge,primary=%s,secondary=%s,father_h=%s,mother_h=%s" '
@ -154,18 +154,18 @@ class BaseMergeCheck(unittest.TestCase):
result_str, err_str = process.communicate(str(input_doc)) result_str, err_str = process.communicate(str(input_doc))
if err_str: if err_str:
if test_error_str: if test_error_str:
self.assert_(test_error_str in err_str) self.assertIn(test_error_str, err_str)
return return
if debug: if debug:
print 'input :', self.canonicalize(input_doc) print('input :', self.canonicalize(input_doc))
print 'result:', self.canonicalize(result_str) print('result:', self.canonicalize(result_str))
print 'expect:', self.canonicalize(expect_doc) print('expect:', self.canonicalize(expect_doc))
self.assertEqual(self.canonicalize(result_str), self.assertEqual(self.canonicalize(result_str),
self.canonicalize(expect_doc)) self.canonicalize(expect_doc))
def raw_contains(self, phoenix_id, titanic_id, input_doc, expect_str, def raw_contains(self, phoenix_id, titanic_id, input_doc, expect_str,
test_error_str='', debug=False): test_error_str='', debug=False):
process = subprocess.Popen('python gramps.py -d .ImportXML ' process = subprocess.Popen('python Gramps.py -d .ImportXML '
'--config=preferences.eprefix:DEFAULT ' '--config=preferences.eprefix:DEFAULT '
'-i - -f gramps -a tool ' '-i - -f gramps -a tool '
'-p "name=climerge,primary=%s,secondary=%s" ' '-p "name=climerge,primary=%s,secondary=%s" '
@ -176,14 +176,14 @@ class BaseMergeCheck(unittest.TestCase):
result_str, err_str = process.communicate(str(input_doc)) result_str, err_str = process.communicate(str(input_doc))
if err_str: if err_str:
if test_error_str: if test_error_str:
self.assert_(test_error_str in err_str) self.assertIn(test_error_str, err_str)
return return
if debug: if debug:
print 'input :', self.canonicalize(input_doc) print('input :', self.canonicalize(input_doc))
print 'result:', result_str print('result:', result_str)
print 'expect:', expect_str print('expect:', expect_str)
# should I order/canonicalise things? # should I order/canonicalise things?
self.assert_(expect_str in result_str) self.assertIn(expect_str, result_str)
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# PersonCheck class # PersonCheck class
@ -217,9 +217,7 @@ class PersonCheck(BaseMergeCheck):
</lds_ord> </lds_ord>
<objref hlink="_o0000"/> <objref hlink="_o0000"/>
<noteref hlink="_n0000"/> <noteref hlink="_n0000"/>
<sourceref hlink="_s0000"> <citationref hlink="_c0000"/>
<spage>p.10</spage>
</sourceref>
</person> </person>
<person handle="_i0001" id="I0001"> <person handle="_i0001" id="I0001">
<gender>M</gender> <gender>M</gender>
@ -232,11 +230,21 @@ class PersonCheck(BaseMergeCheck):
</lds_ord> </lds_ord>
<objref hlink="_o0001"/> <objref hlink="_o0001"/>
<noteref hlink="_n0001"/> <noteref hlink="_n0001"/>
<sourceref hlink="_s0001"> <citationref hlink="_c0001"/>
<spage>p.11</spage>
</sourceref>
</person> </person>
</people> </people>
<citations>
<citation handle="_c0000" id="C0000">
<page>p.10</page>
<confidence>2</confidence>
<sourceref hlink="_s0000"/>
</citation>
<citation handle="_c0001" id="C0001">
<page>p.11</page>
<confidence>2</confidence>
<sourceref hlink="_s0001"/>
</citation>
</citations>
<sources> <sources>
<source handle="_s0000" id="S0000"> <source handle="_s0000" id="S0000">
<stitle>Source 0</stitle> <stitle>Source 0</stitle>
@ -297,17 +305,17 @@ class PersonCheck(BaseMergeCheck):
placeobj.freeNode() placeobj.freeNode()
self.do_test('P0000', 'P0001', self.basedoc, expect) self.do_test('P0000', 'P0001', self.basedoc, expect)
def test_source_merge(self): def test_citation_merge(self):
"""Merge two sources""" """Merge two citations"""
with CopiedDoc(self.basedoc) as expect: with CopiedDoc(self.basedoc) as expect:
with XpathContext(expect) as ctxt: with XpathContext(expect) as ctxt:
srcref = ctxt.xpathEval( srcref = ctxt.xpathEval(
"//g:person[@handle='_i0001']/g:sourceref")[0] "//g:person[@handle='_i0001']/g:citationref")[0]
srcref.setProp('hlink', '_s0000') srcref.setProp('hlink', '_c0000')
source = ctxt.xpathEval("//g:source[@handle='_s0001']")[0] citation = ctxt.xpathEval("//g:citation[@handle='_c0001']")[0]
source.unlinkNode() citation.unlinkNode()
source.freeNode() citation.freeNode()
self.do_test('S0000', 'S0001', self.basedoc, expect) self.do_test('C0000', 'C0001', self.basedoc, expect)
def test_media_merge(self): def test_media_merge(self):
"""Merge two media objects""" """Merge two media objects"""
@ -363,7 +371,7 @@ class FamilyCheck(BaseMergeCheck):
</lds_ord> </lds_ord>
<objref hlink="_o0000"/> <objref hlink="_o0000"/>
<noteref hlink="_n0000"/> <noteref hlink="_n0000"/>
<sourceref hlink="_s0000"/> <citationref hlink="_c0000"/>
</family> </family>
<family handle="_f0001" id="F0001"> <family handle="_f0001" id="F0001">
<rel type="Married"/> <rel type="Married"/>
@ -373,9 +381,21 @@ class FamilyCheck(BaseMergeCheck):
</lds_ord> </lds_ord>
<objref hlink="_o0001"/> <objref hlink="_o0001"/>
<noteref hlink="_n0001"/> <noteref hlink="_n0001"/>
<sourceref hlink="_s0001"/> <citationref hlink="_c0001"/>
</family> </family>
</families> </families>
<citations>
<citation handle="_c0000" id="C0000">
<page>p.10</page>
<confidence>2</confidence>
<sourceref hlink="_s0000"/>
</citation>
<citation handle="_c0001" id="C0001">
<page>p.11</page>
<confidence>2</confidence>
<sourceref hlink="_s0001"/>
</citation>
</citations>
<sources> <sources>
<source handle="_s0000" id="S0000"> <source handle="_s0000" id="S0000">
<stitle>Source 0</stitle> <stitle>Source 0</stitle>
@ -436,17 +456,17 @@ class FamilyCheck(BaseMergeCheck):
placeobj.freeNode() placeobj.freeNode()
self.do_test('P0000', 'P0001', self.basedoc, expect) self.do_test('P0000', 'P0001', self.basedoc, expect)
def test_source_merge(self): def test_citation_merge(self):
"""Merge two sources""" """Merge two citations"""
with CopiedDoc(self.basedoc) as expect: with CopiedDoc(self.basedoc) as expect:
with XpathContext(expect) as ctxt: with XpathContext(expect) as ctxt:
srcref = ctxt.xpathEval( citref = ctxt.xpathEval(
"//g:family[@handle='_f0001']/g:sourceref")[0] "//g:family[@handle='_f0001']/g:citationref")[0]
srcref.setProp('hlink', '_s0000') citref.setProp('hlink', '_c0000')
source = ctxt.xpathEval("//g:source[@handle='_s0001']")[0] citation = ctxt.xpathEval("//g:citation[@handle='_c0001']")[0]
source.unlinkNode() citation.unlinkNode()
source.freeNode() citation.freeNode()
self.do_test('S0000', 'S0001', self.basedoc, expect) self.do_test('C0000', 'C0001', self.basedoc, expect)
def test_media_merge(self): def test_media_merge(self):
"""Merge two media objects""" """Merge two media objects"""
@ -489,7 +509,7 @@ class EventCheck(BaseMergeCheck):
<place hlink="_p0000"/> <place hlink="_p0000"/>
<description>Event 0</description> <description>Event 0</description>
<noteref hlink="_n0000"/> <noteref hlink="_n0000"/>
<sourceref hlink="_s0000"/> <citationref hlink="_c0000"/>
<objref hlink="_o0000"/> <objref hlink="_o0000"/>
</event> </event>
<event handle="_e0001" id="E0001"> <event handle="_e0001" id="E0001">
@ -497,10 +517,22 @@ class EventCheck(BaseMergeCheck):
<place hlink="_p0001"/> <place hlink="_p0001"/>
<description>Event 1</description> <description>Event 1</description>
<noteref hlink="_n0001"/> <noteref hlink="_n0001"/>
<sourceref hlink="_s0001"/> <citationref hlink="_c0001"/>
<objref hlink="_o0001"/> <objref hlink="_o0001"/>
</event> </event>
</events> </events>
<citations>
<citation handle="_c0000" id="C0000">
<page>p.10</page>
<confidence>2</confidence>
<sourceref hlink="_s0000"/>
</citation>
<citation handle="_c0001" id="C0001">
<page>p.11</page>
<confidence>2</confidence>
<sourceref hlink="_s0001"/>
</citation>
</citations>
<sources> <sources>
<source handle="_s0000" id="S0000"> <source handle="_s0000" id="S0000">
<stitle>Source 0</stitle> <stitle>Source 0</stitle>
@ -549,17 +581,17 @@ class EventCheck(BaseMergeCheck):
placeobj.freeNode() placeobj.freeNode()
self.do_test('P0000', 'P0001', self.basedoc, expect) self.do_test('P0000', 'P0001', self.basedoc, expect)
def test_source_merge(self): def test_citation_merge(self):
"""Merge two sources""" """Merge two citations"""
with CopiedDoc(self.basedoc) as expect: with CopiedDoc(self.basedoc) as expect:
with XpathContext(expect) as ctxt: with XpathContext(expect) as ctxt:
srcref = ctxt.xpathEval( citref = ctxt.xpathEval(
"//g:event[@handle='_e0001']/g:sourceref")[0] "//g:event[@handle='_e0001']/g:citationref")[0]
srcref.setProp('hlink', '_s0000') citref.setProp('hlink', '_c0000')
source = ctxt.xpathEval("//g:source[@handle='_s0001']")[0] citation = ctxt.xpathEval("//g:citation[@handle='_c0001']")[0]
source.unlinkNode() citation.unlinkNode()
source.freeNode() citation.freeNode()
self.do_test('S0000', 'S0001', self.basedoc, expect) self.do_test('C0000', 'C0001', self.basedoc, expect)
def test_media_merge(self): def test_media_merge(self):
"""Merge two media objects""" """Merge two media objects"""
@ -596,6 +628,18 @@ class PlaceCheck(BaseMergeCheck):
def setUp(self): def setUp(self):
self.base_setup() self.base_setup()
base_str = """ base_str = """
<citations>
<citation handle="_c0000" id="C0000">
<page>p.10</page>
<confidence>2</confidence>
<sourceref hlink="_s0000"/>
</citation>
<citation handle="_c0001" id="C0001">
<page>p.11</page>
<confidence>2</confidence>
<sourceref hlink="_s0001"/>
</citation>
</citations>
<sources> <sources>
<source handle="_s0000" id="S0000"> <source handle="_s0000" id="S0000">
<stitle>Source 0</stitle> <stitle>Source 0</stitle>
@ -609,13 +653,13 @@ class PlaceCheck(BaseMergeCheck):
<ptitle>Place 0</ptitle> <ptitle>Place 0</ptitle>
<objref hlink="_o0000"/> <objref hlink="_o0000"/>
<noteref hlink="_n0000"/> <noteref hlink="_n0000"/>
<sourceref hlink="_s0000"/> <citationref hlink="_c0000"/>
</placeobj> </placeobj>
<placeobj handle="_p0001" id="P0001"> <placeobj handle="_p0001" id="P0001">
<ptitle>Place 1</ptitle> <ptitle>Place 1</ptitle>
<objref hlink="_o0001"/> <objref hlink="_o0001"/>
<noteref hlink="_n0001"/> <noteref hlink="_n0001"/>
<sourceref hlink="_s0001"/> <citationref hlink="_c0001"/>
</placeobj> </placeobj>
</places> </places>
<objects> <objects>
@ -638,17 +682,17 @@ class PlaceCheck(BaseMergeCheck):
self.basedoc = libxml2.readDoc(self.base_str + base_str, '', None, self.basedoc = libxml2.readDoc(self.base_str + base_str, '', None,
libxml2.XML_PARSE_NONET) libxml2.XML_PARSE_NONET)
def test_source_merge(self): def test_citation_merge(self):
"""Merge two sources""" """Merge two citations"""
with CopiedDoc(self.basedoc) as expect: with CopiedDoc(self.basedoc) as expect:
with XpathContext(expect) as ctxt: with XpathContext(expect) as ctxt:
srcref = ctxt.xpathEval( citref = ctxt.xpathEval(
"//g:placeobj[@handle='_p0001']/g:sourceref")[0] "//g:placeobj[@handle='_p0001']/g:citationref")[0]
srcref.setProp('hlink', '_s0000') citref.setProp('hlink', '_c0000')
source = ctxt.xpathEval("//g:source[@handle='_s0001']")[0] citation = ctxt.xpathEval("//g:citation[@handle='_c0001']")[0]
source.unlinkNode() citation.unlinkNode()
source.freeNode() citation.freeNode()
self.do_test('S0000', 'S0001', self.basedoc, expect) self.do_test('C0000', 'C0001', self.basedoc, expect)
def test_media_merge(self): def test_media_merge(self):
"""Merge two media objects""" """Merge two media objects"""
@ -685,6 +729,18 @@ class SourceCheck(BaseMergeCheck):
def setUp(self): def setUp(self):
self.base_setup() self.base_setup()
base_str = """ base_str = """
<citations>
<citation handle="_c0000" id="C0000">
<page>p.10</page>
<confidence>2</confidence>
<sourceref hlink="_s0000"/>
</citation>
<citation handle="_c0001" id="C0001">
<page>p.11</page>
<confidence>2</confidence>
<sourceref hlink="_s0001"/>
</citation>
</citations>
<sources> <sources>
<source handle="_s0000" id="S0000"> <source handle="_s0000" id="S0000">
<stitle>Source 0</stitle> <stitle>Source 0</stitle>
@ -729,7 +785,7 @@ class SourceCheck(BaseMergeCheck):
self.basedoc = libxml2.readDoc(self.base_str + base_str, '', None, self.basedoc = libxml2.readDoc(self.base_str + base_str, '', None,
libxml2.XML_PARSE_NONET) libxml2.XML_PARSE_NONET)
#def test_source_merge(self): SEE special cases. #def test_citation_merge(self): SEE special cases.
def test_repo_merge(self): def test_repo_merge(self):
"""Merge two repositories""" """Merge two repositories"""
@ -781,6 +837,18 @@ class RepoCheck(BaseMergeCheck):
def setUp(self): def setUp(self):
self.base_setup() self.base_setup()
base_str = """ base_str = """
<citations>
<citation handle="_c0000" id="C0000">
<page>p.10</page>
<confidence>2</confidence>
<sourceref hlink="_s0000"/>
</citation>
<citation handle="_c0001" id="C0001">
<page>p.11</page>
<confidence>2</confidence>
<sourceref hlink="_s0001"/>
</citation>
</citations>
<sources> <sources>
<source handle="_s0000" id="S0000"> <source handle="_s0000" id="S0000">
<stitle>Source 0</stitle> <stitle>Source 0</stitle>
@ -795,7 +863,7 @@ class RepoCheck(BaseMergeCheck):
<type>Library</type> <type>Library</type>
<address> <address>
<city>Amsterdam</city> <city>Amsterdam</city>
<sourceref hlink="_s0000"/> <citationref hlink="_c0000"/>
</address> </address>
<noteref hlink="_n0000"/> <noteref hlink="_n0000"/>
</repository> </repository>
@ -804,7 +872,7 @@ class RepoCheck(BaseMergeCheck):
<type>Library</type> <type>Library</type>
<address> <address>
<city>Rotterdam</city> <city>Rotterdam</city>
<sourceref hlink="_s0001"/> <citationref hlink="_c0001"/>
</address> </address>
<noteref hlink="_n0001"/> <noteref hlink="_n0001"/>
</repository> </repository>
@ -821,17 +889,17 @@ class RepoCheck(BaseMergeCheck):
self.basedoc = libxml2.readDoc(self.base_str + base_str, '', None, self.basedoc = libxml2.readDoc(self.base_str + base_str, '', None,
libxml2.XML_PARSE_NONET) libxml2.XML_PARSE_NONET)
def test_source_merge(self): def test_citation_merge(self):
"""Merge two sources""" """Merge two citations"""
with CopiedDoc(self.basedoc) as expect: with CopiedDoc(self.basedoc) as expect:
with XpathContext(expect) as ctxt: with XpathContext(expect) as ctxt:
srcref = ctxt.xpathEval( citref = ctxt.xpathEval(
"//g:repository[@handle='_r0001']/g:address/g:sourceref")[0] "//g:repository[@handle='_r0001']/g:address/g:citationref")[0]
srcref.setProp('hlink', '_s0000') citref.setProp('hlink', '_c0000')
source = ctxt.xpathEval("//g:source[@handle='_s0001']")[0] citation = ctxt.xpathEval("//g:citation[@handle='_c0001']")[0]
source.unlinkNode() citation.unlinkNode()
source.freeNode() citation.freeNode()
self.do_test('S0000', 'S0001', self.basedoc, expect) self.do_test('C0000', 'C0001', self.basedoc, expect)
def test_note_merge(self): def test_note_merge(self):
"""Merge two notes""" """Merge two notes"""
@ -856,6 +924,18 @@ class MediaCheck(BaseMergeCheck):
def setUp(self): def setUp(self):
self.base_setup() self.base_setup()
base_str = """ base_str = """
<citations>
<citation handle="_c0000" id="C0000">
<page>p.10</page>
<confidence>2</confidence>
<sourceref hlink="_s0000"/>
</citation>
<citation handle="_c0001" id="C0001">
<page>p.11</page>
<confidence>2</confidence>
<sourceref hlink="_s0001"/>
</citation>
</citations>
<sources> <sources>
<source handle="_s0000" id="S0000"> <source handle="_s0000" id="S0000">
<stitle>Source 0</stitle> <stitle>Source 0</stitle>
@ -868,12 +948,12 @@ class MediaCheck(BaseMergeCheck):
<object handle="_o0000" id="O0000"> <object handle="_o0000" id="O0000">
<file src="image0.jpg" mime="image/jpeg" description="Image 0"/> <file src="image0.jpg" mime="image/jpeg" description="Image 0"/>
<noteref hlink="_n0000"/> <noteref hlink="_n0000"/>
<sourceref hlink="_s0000"/> <citationref hlink="_c0000"/>
</object> </object>
<object handle="_o0001" id="O0001"> <object handle="_o0001" id="O0001">
<file src="image1.jpg" mime="image/jpeg" description="Image 1"/> <file src="image1.jpg" mime="image/jpeg" description="Image 1"/>
<noteref hlink="_n0001"/> <noteref hlink="_n0001"/>
<sourceref hlink="_s0001"/> <citationref hlink="_c0001"/>
</object> </object>
</objects> </objects>
<notes> <notes>
@ -888,17 +968,17 @@ class MediaCheck(BaseMergeCheck):
self.basedoc = libxml2.readDoc(self.base_str + base_str, '', None, self.basedoc = libxml2.readDoc(self.base_str + base_str, '', None,
libxml2.XML_PARSE_NONET) libxml2.XML_PARSE_NONET)
def test_source_merge(self): def test_citation_merge(self):
"""Merge two sources""" """Merge two citations"""
with CopiedDoc(self.basedoc) as expect: with CopiedDoc(self.basedoc) as expect:
with XpathContext(expect) as ctxt: with XpathContext(expect) as ctxt:
srcref = ctxt.xpathEval( citref = ctxt.xpathEval(
"//g:object[@handle='_o0001']/g:sourceref")[0] "//g:object[@handle='_o0001']/g:citationref")[0]
srcref.setProp('hlink', '_s0000') citref.setProp('hlink', '_c0000')
source = ctxt.xpathEval("//g:source[@handle='_s0001']")[0] citation = ctxt.xpathEval("//g:citation[@handle='_c0001']")[0]
source.unlinkNode() citation.unlinkNode()
source.freeNode() citation.freeNode()
self.do_test('S0000', 'S0001', self.basedoc, expect) self.do_test('C0000', 'C0001', self.basedoc, expect)
def test_note_merge(self): def test_note_merge(self):
"""Merge two notes""" """Merge two notes"""
@ -918,28 +998,49 @@ class MediaCheck(BaseMergeCheck):
# #
#========================================================================= #=========================================================================
#-------------------------------------------------------------------------
#
# SourceSourceCheck class
#
#-------------------------------------------------------------------------
class SourceSourceCheck(BaseMergeCheck): class SourceSourceCheck(BaseMergeCheck):
def setUp(self): def setUp(self):
self.base_setup() self.base_setup()
base_str = """ base_str = """
<citations>
<citation handle="_c0000" id="C0000">
<page>p.10</page>
<confidence>2</confidence>
<objref hlink="_o0000">
<citationref hlink="_c0002"/>
</objref>
<sourceref hlink="_s0000"/>
</citation>
<citation handle="_c0001" id="C0001">
<page>p.11</page>
<confidence>2</confidence>
<objref hlink="_o0001">
<citationref hlink="_c0003"/>
</objref>
<sourceref hlink="_s0000"/>
</citation>
<citation handle="_c0002" id="C0002">
<page>p.12</page>
<confidence>2</confidence>
<sourceref hlink="_s0001"/>
</citation>
<citation handle="_c0003" id="C0003">
<page>p.13</page>
<confidence>2</confidence>
<sourceref hlink="_s0001"/>
</citation>
</citations>
<sources> <sources>
<source handle="_s0000" id="S0000"> <source handle="_s0000" id="S0000">
<stitle>Source 0</stitle> <stitle>Source 0</stitle>
<objref hlink="_o0000">
<sourceref hlink="_s0002"/>
</objref>
</source> </source>
<source handle="_s0001" id="S0001"> <source handle="_s0001" id="S0001">
<stitle>Source 1</stitle> <stitle>Source 1</stitle>
<objref hlink="_o0001">
<sourceref hlink="_s0003"/>
</objref>
</source>
<source handle="_s0002" id="S0002">
<stitle>Source 2</stitle>
</source>
<source handle="_s0003" id="S0003">
<stitle>Source 3</stitle>
</source> </source>
</sources> </sources>
<objects> <objects>
@ -954,43 +1055,46 @@ class SourceSourceCheck(BaseMergeCheck):
self.basedoc = libxml2.readDoc(self.base_str + base_str, '', None, self.basedoc = libxml2.readDoc(self.base_str + base_str, '', None,
libxml2.XML_PARSE_NONET) libxml2.XML_PARSE_NONET)
def test_source_merge(self): def test_citation_merge(self):
with CopiedDoc(self.basedoc) as expect: with CopiedDoc(self.basedoc) as expect:
with XpathContext(expect) as ctxt: with XpathContext(expect) as ctxt:
srcrefs = ctxt.xpathEval( citrefs = ctxt.xpathEval(
"//g:source[@handle='_s0001']/g:objref/g:sourceref") "//g:citation[@handle='_c0001']/g:objref/g:citationref")
srcrefs[0].setProp('hlink', '_s0002') citrefs[0].setProp('hlink', '_c0002')
sources = ctxt.xpathEval("//g:source[@handle='_s0003']") citations = ctxt.xpathEval("//g:citation[@handle='_c0003']")
sources[0].unlinkNode() citations[0].unlinkNode()
sources[0].freeNode() citations[0].freeNode()
self.do_test('S0002', 'S0003', self.basedoc, expect) self.do_test('C0002', 'C0003', self.basedoc, expect)
def test_source_cross_merge(self): def test_citation_cross_merge(self):
with XpathContext(self.basedoc) as input_ctxt: with XpathContext(self.basedoc) as input_ctxt:
input_srcrefs = input_ctxt.xpathEval( input_citrefs = input_ctxt.xpathEval(
"//g:source/g:objref/g:sourceref") "//g:citation/g:objref/g:citationref")
input_srcrefs[0].setProp('hlink', '_s0001') input_citrefs[0].setProp('hlink', '_c0001')
input_srcrefs[1].setProp('hlink', '_s0000') input_citrefs[1].setProp('hlink', '_c0000')
rmsrc = input_ctxt.xpathEval("//g:source[@handle='_s0002']") rmcit = input_ctxt.xpathEval("//g:citation[@handle='_c0002']")
rmsrc[0].unlinkNode() rmcit[0].unlinkNode()
rmsrc[0].freeNode() rmcit[0].freeNode()
rmsrc = input_ctxt.xpathEval("//g:source[@handle='_s0003']") rmcit = input_ctxt.xpathEval("//g:citation[@handle='_c0003']")
rmcit[0].unlinkNode()
rmcit[0].freeNode()
rmsrc = input_ctxt.xpathEval("//g:source[@handle='_s0001']")
rmsrc[0].unlinkNode() rmsrc[0].unlinkNode()
rmsrc[0].freeNode() rmsrc[0].freeNode()
with CopiedDoc(self.basedoc) as expect: with CopiedDoc(self.basedoc) as expect:
with XpathContext(expect) as ctxt: with XpathContext(expect) as ctxt:
srcrefs = ctxt.xpathEval( citrefs = ctxt.xpathEval(
"//g:source[@handle='_s0000']/g:objref/g:sourceref") "//g:citation[@handle='_c0000']/g:objref/g:citationref")
srcrefs[0].setProp('hlink', '_s0000') citrefs[0].setProp('hlink', '_c0000')
# add objref # add objref
objref = ctxt.xpathEval("//g:source[@handle='_s0000']/g:objref") objref = ctxt.xpathEval("//g:citation[@handle='_c0000']/g:objref")
objref2 = ctxt.xpathEval("//g:source[@handle='_s0001']/g:objref") objref2 = ctxt.xpathEval("//g:citation[@handle='_c0001']/g:objref")
objref[0].addNextSibling(objref2[0]) objref[0].addNextSibling(objref2[0])
# remove source # remove citation
sources = ctxt.xpathEval("//g:source[@handle='_s0001']") citations = ctxt.xpathEval("//g:citation[@handle='_c0001']")
sources[0].unlinkNode() citations[0].unlinkNode()
sources[0].freeNode() citations[0].freeNode()
self.do_test('S0000', 'S0001', self.basedoc, expect) self.do_test('C0000', 'C0001', self.basedoc, expect)
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -1029,9 +1133,9 @@ class BirthCheck(BaseMergeCheck):
</database>""" </database>"""
self.basedoc = libxml2.readDoc(self.base_str + base_str, '', None, self.basedoc = libxml2.readDoc(self.base_str + base_str, '', None,
libxml2.XML_PARSE_NONET) libxml2.XML_PARSE_NONET)
surname = gen.lib.Surname() surname = Surname()
surname.set_surname(u"Person 0") surname.set_surname("Person 0")
name = gen.lib.Name() name = Name()
name.add_surname(surname) name.add_surname(surname)
self.expect_str = "person: i0000 ('i0000', 'I0000', 1, %s, [], " % str( self.expect_str = "person: i0000 ('i0000', 'I0000', 1, %s, [], " % str(
name.serialize()) name.serialize())
@ -1195,7 +1299,7 @@ class PersonPersonCheck(BaseMergeCheck):
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# ParentFamilyPesronCheck class # ParentFamilyPersonCheck class
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class ParentFamilyPersonCheck(BaseMergeCheck): class ParentFamilyPersonCheck(BaseMergeCheck):
@ -2118,9 +2222,9 @@ class FamilyMergeCheck(BaseMergeCheck):
if __name__ == "__main__": if __name__ == "__main__":
if not os.path.isdir(os.path.join(USER_PLUGINS, 'CliMerge')): if not os.path.isdir(os.path.join(USER_PLUGINS, 'CliMerge')):
print >> sys.stderr, 'This program needs the third party "CliMerge" plugin.' print('This program needs the third party "CliMerge" plugin.', file=sys.stderr)
sys.exit(1) sys.exit(1)
if not os.path.isdir(os.path.join(USER_PLUGINS, 'ExportRaw')): if not os.path.isdir(os.path.join(USER_PLUGINS, 'ExportRaw')):
print >> sys.stderr, 'This program needs the third party "ExportRaw" plugin.' print('This program needs the third party "ExportRaw" plugin.', file=sys.stderr)
sys.exit(1) sys.exit(1)
unittest.main() unittest.main()