Skip to content

Commit

Permalink
Fix a bug where siblings would not be correct at top level [ Fixed #109
Browse files Browse the repository at this point in the history
… ]
  • Loading branch information
PonteIneptique committed Feb 15, 2017
1 parent 09a9e8a commit 177846c
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 7 deletions.
2 changes: 1 addition & 1 deletion MyCapytain/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
"""

__version__ = "2.0.0b4"
__version__ = "2.0.0b6"
12 changes: 7 additions & 5 deletions MyCapytain/resources/texts/locals/tei.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,11 +384,12 @@ def siblingsId(self):
return self.__prevnext__

document_references = list(map(str, self.__text__.getReffs(level=self.depth)))
range_length = len(self.getReffs())

start = str(self.reference.start)
range_length = 1
if self.reference.end is not None:
range_length = len(self.getReffs())

start = document_references.index(start)
start = document_references.index(str(self.reference.start))

if start == 0:
# If the passage is already at the beginning
Expand All @@ -404,7 +405,7 @@ def siblingsId(self):
elif start + range_length > len(document_references):
_next = Reference(document_references[-1])
else:
_next = Reference(document_references[start +1])
_next = Reference(document_references[start + 1])

self.__prevnext__ = (_prev, _next)
return self.__prevnext__
Expand Down Expand Up @@ -593,12 +594,13 @@ def siblingsId(self):
return self.__prevnext__

document_references = list(map(str, self.__text__.getReffs(level=self.depth)))
range_length = len(self.getReffs(level=0))

if self.reference.end:
start, end = str(self.reference.start), str(self.reference.end)
range_length = len(self.getReffs(level=0))
else:
start = end = str(self.reference.start)
range_length = 1

start = document_references.index(start)
end = document_references.index(end)
Expand Down
38 changes: 38 additions & 0 deletions tests/resources/commonTests.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ class CapitainsXmlPassageTests(TestCase):
URN = None
URN_2 = None
TEI = None
FULL_EPIGRAMMATA = None

def __init__(self, *args, **kwargs):
""" Small helper to prevent run while inheriting from TestCase """
Expand Down Expand Up @@ -637,6 +638,43 @@ def test_prev(self, simple):
p = self.TEI.getTextualNode(["2", "pr", "sa"], simple=simple)
self.assertEqual(str(p.prev.reference), "1.39.8")

@call_with_simple
def test_siblingsId(self, simple):
""" Test prev property """
# Normal passage checking
p, n = self.FULL_EPIGRAMMATA.getTextualNode(["2"], simple=simple).siblingsId
self.assertEqual(("1", "3"), (str(p), str(n)), "Middle node should have right siblings")
p, n = self.FULL_EPIGRAMMATA.getTextualNode(["1"], simple=simple).siblingsId
self.assertEqual((None, "2"), (p, str(n)), "First node should have right siblings")
p, n = self.FULL_EPIGRAMMATA.getTextualNode(["14"], simple=simple).siblingsId
self.assertEqual(("13", None), (str(p), n), "Last node should have right siblings")
# Ranges
if simple is False:
# Start
p, n = self.FULL_EPIGRAMMATA.getTextualNode(Reference("1-2"), simple=simple).siblingsId
self.assertEqual((None, "3-4"), (p, str(n)), "First node should have right siblings")
p, n = self.FULL_EPIGRAMMATA.getTextualNode(Reference("1-5"), simple=simple).siblingsId
self.assertEqual((None, "6-10"), (p, str(n)), "First node should have right siblings")
p, n = self.FULL_EPIGRAMMATA.getTextualNode(Reference("1-9"), simple=simple).siblingsId
self.assertEqual((None, "10-14"), (p, str(n)), "First node should have right siblings")
# End
p, n = self.FULL_EPIGRAMMATA.getTextualNode(Reference("12-14"), simple=simple).siblingsId
self.assertEqual(("9-11", None), (str(p), n), "Last node should have right siblings")
p, n = self.FULL_EPIGRAMMATA.getTextualNode(Reference("11-14"), simple=simple).siblingsId
self.assertEqual(("7-10", None), (str(p), n), "Last node should have right siblings")
p, n = self.FULL_EPIGRAMMATA.getTextualNode(Reference("5-14"), simple=simple).siblingsId
self.assertEqual(("1-4", None), (str(p), n), "Should take the rest")
# Middle
p, n = self.FULL_EPIGRAMMATA.getTextualNode(Reference("5-6"), simple=simple).siblingsId
self.assertEqual(("3-4", "7-8"), (str(p), str(n)), "Middle node should have right siblings")
p, n = self.FULL_EPIGRAMMATA.getTextualNode(Reference("5-8"), simple=simple).siblingsId
self.assertEqual(("1-4", "9-12"), (str(p), str(n)), "Middle node should have right siblings")
p, n = self.FULL_EPIGRAMMATA.getTextualNode(Reference("5-10"), simple=simple).siblingsId
self.assertEqual(("1-4", "11-14"), (str(p), str(n)), "Middle node should have right siblings")
# NONE !
p, n = self.FULL_EPIGRAMMATA.getTextualNode(Reference("1-14"), simple=simple).siblingsId
self.assertEqual((None, None), (p, n), "If whole range, nothing !")


class CapitainsXMLRangePassageTests(TestCase):
text = None
Expand Down
5 changes: 4 additions & 1 deletion tests/resources/texts/locals/test_capitains_xml_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ def setUp(self):
self.URN_2 = MyCapytain.common.reference.URN("urn:cts:latinLit:phi1294.phi002.perseus-lat3")
self.text = open("tests/testing_data/texts/sample.xml", "rb")
self.TEI = MyCapytain.resources.texts.locals.tei.Text(resource=self.text)

with open("tests/testing_data/latinLit/data/phi1294/phi002/phi1294.phi002.perseus-lat2.xml", "rb") as f:
self.FULL_EPIGRAMMATA = MyCapytain.resources.texts.locals.tei.Text(resource=f)
assert self.simple is False, "Simple should be False"

def tearDown(self):
Expand All @@ -66,6 +67,8 @@ def setUp(self):
self.URN_2 = MyCapytain.common.reference.URN("urn:cts:latinLit:phi1294.phi002.perseus-lat3")
self.text = open("tests/testing_data/texts/sample.xml", "rb")
self.TEI = MyCapytain.resources.texts.locals.tei.Text(resource=self.text)
with open("tests/testing_data/latinLit/data/phi1294/phi002/phi1294.phi002.perseus-lat2.xml", "rb") as f:
self.FULL_EPIGRAMMATA = MyCapytain.resources.texts.locals.tei.Text(resource=f)

assert self.simple is True, "Simple should be True"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ def setUp(self):
self.URN_2 = MyCapytain.common.reference.URN("urn:cts:latinLit:phi1294.phi002.perseus-lat3")
self.text = open("tests/testing_data/texts/sample.xml", "rb")
self.TEI = MyCapytain.resources.texts.locals.tei.Text(resource=objectifiedParser(self.text))
with open("tests/testing_data/latinLit/data/phi1294/phi002/phi1294.phi002.perseus-lat2.xml", "rb") as f:
self.FULL_EPIGRAMMATA = MyCapytain.resources.texts.locals.tei.Text(resource=objectifiedParser(f))

assert self.simple is False, "Simple should be True"

Expand All @@ -71,6 +73,8 @@ def setUp(self):
self.URN_2 = MyCapytain.common.reference.URN("urn:cts:latinLit:phi1294.phi002.perseus-lat3")
self.text = open("tests/testing_data/texts/sample.xml", "rb")
self.TEI = MyCapytain.resources.texts.locals.tei.Text(resource=objectifiedParser(self.text))
with open("tests/testing_data/latinLit/data/phi1294/phi002/phi1294.phi002.perseus-lat2.xml", "rb") as f:
self.FULL_EPIGRAMMATA = MyCapytain.resources.texts.locals.tei.Text(resource=objectifiedParser(f))

assert self.simple is True, "Simple should be True"

Expand Down

0 comments on commit 177846c

Please sign in to comment.