From 4c5e97c5fd0dac545978ad19d3703fc146b5d0da Mon Sep 17 00:00:00 2001 From: Matthew Munson Date: Mon, 25 Jun 2018 11:38:34 +0200 Subject: [PATCH 1/3] Added MissingRefsDecl exception, a test for it, and changed an existing unit test to test for this --- MyCapytain/errors.py | 5 +++++ MyCapytain/resources/texts/local/capitains/cts.py | 4 +++- tests/resources/texts/local/commonTests.py | 6 ++---- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/MyCapytain/errors.py b/MyCapytain/errors.py index e542ee9d..c08414f7 100644 --- a/MyCapytain/errors.py +++ b/MyCapytain/errors.py @@ -64,3 +64,8 @@ class UnknownCollection(KeyError, MyCapytainException): class EmptyReference(SyntaxWarning, MyCapytainException): """ Error generated when a duplicate is found in Reference """ + + +class MissingRefsDecl(KeyError, MyCapytainException): + """ A text has no properly encoded refsDecl + """ diff --git a/MyCapytain/resources/texts/local/capitains/cts.py b/MyCapytain/resources/texts/local/capitains/cts.py index 1d78db72..56bcbf25 100644 --- a/MyCapytain/resources/texts/local/capitains/cts.py +++ b/MyCapytain/resources/texts/local/capitains/cts.py @@ -11,7 +11,7 @@ import warnings -from MyCapytain.errors import DuplicateReference, MissingAttribute, RefsDeclError, EmptyReference +from MyCapytain.errors import DuplicateReference, MissingAttribute, RefsDeclError, EmptyReference, MissingRefsDecl from MyCapytain.common.utils import copyNode, passageLoop, normalizeXpath from MyCapytain.common.constants import XPATH_NAMESPACES, RDF_NAMESPACES from MyCapytain.common.reference import URN, Citation, Reference @@ -454,6 +454,8 @@ def __findCRefPattern(self, xml): citation = xml.xpath("//tei:refsDecl[@n='CTS']", namespaces=XPATH_NAMESPACES) if len(citation): self.citation = Citation.ingest(resource=citation[0], xpath=".//tei:cRefPattern") + else: + raise MissingRefsDecl("No reference declaration (refsDecl) found.") def test(self): """ Parse the object and generate the children diff --git a/tests/resources/texts/local/commonTests.py b/tests/resources/texts/local/commonTests.py index b30fe225..973dca38 100644 --- a/tests/resources/texts/local/commonTests.py +++ b/tests/resources/texts/local/commonTests.py @@ -245,10 +245,8 @@ def test_complex_reffs(self): def test_xml_no_refs_Decl(self): """ Test the result of parsing when there is no citation """ - text = self.parse("tests/testing_data/texts/refsDeclButNoCTS.xml") - self.assertEqual( - text.citation.isEmpty(), True, "There should be no citation" - ) + with self.assertRaises(MyCapytain.errors.MissingRefsDecl): + self.parse("tests/testing_data/texts/refsDeclButNoCTS.xml") def test_xml_with_xml_id(self): """ Test that xml:id is Citation xpath works fine in passage retriaval """ From 34b61e5a982f806d9053c99ab389be33fc9bb2d3 Mon Sep 17 00:00:00 2001 From: Matthew Munson Date: Mon, 25 Jun 2018 11:42:59 +0200 Subject: [PATCH 2/3] Changed MissingRefsDecl to a plain Exception --- MyCapytain/errors.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MyCapytain/errors.py b/MyCapytain/errors.py index c08414f7..0c5acf06 100644 --- a/MyCapytain/errors.py +++ b/MyCapytain/errors.py @@ -66,6 +66,6 @@ class EmptyReference(SyntaxWarning, MyCapytainException): """ -class MissingRefsDecl(KeyError, MyCapytainException): +class MissingRefsDecl(Exception, MyCapytainException): """ A text has no properly encoded refsDecl """ From 5539b6749a21fa83e9f475400d5a0b17503aedb8 Mon Sep 17 00:00:00 2001 From: Matthew Munson Date: Mon, 25 Jun 2018 20:18:36 +0200 Subject: [PATCH 3/3] Changed exception when citation scheme too deep to CitationDepthError (#174) * Changed exception when citation scheme too deep to CitationDepthError --- CHANGES.md | 6 ++++++ MyCapytain/__init__.py | 2 +- MyCapytain/errors.py | 5 +++++ MyCapytain/resources/texts/local/capitains/cts.py | 4 ++-- tests/resources/texts/local/commonTests.py | 2 +- 5 files changed, 15 insertions(+), 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 91e41893..6bcb5162 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,9 @@ +### 2018-06-25 2.0.8 @sonofmun + +- Corrected error on the empty references exception from 2.0.7 +- Now raises an exception when there is no refsDecl found (MissingRefsDecl) +- The exception now raised by a citation request that is deeper than the citation scheme is a CitationDepthError + ### 2018-06-22 2.0.7 @sonofmun - Added exception for empty references diff --git a/MyCapytain/__init__.py b/MyCapytain/__init__.py index 85c3e52d..4a7ea86f 100644 --- a/MyCapytain/__init__.py +++ b/MyCapytain/__init__.py @@ -9,4 +9,4 @@ """ -__version__ = "2.0.7" +__version__ = "2.0.8" diff --git a/MyCapytain/errors.py b/MyCapytain/errors.py index 0c5acf06..c6dce044 100644 --- a/MyCapytain/errors.py +++ b/MyCapytain/errors.py @@ -65,6 +65,11 @@ class EmptyReference(SyntaxWarning, MyCapytainException): """ Error generated when a duplicate is found in Reference """ + +class CitationDepthError(UnknownObjectError, MyCapytainException): + """ Error generated when the depth of a requested citation is deeper than the citation scheme of the text + """ + class MissingRefsDecl(Exception, MyCapytainException): """ A text has no properly encoded refsDecl diff --git a/MyCapytain/resources/texts/local/capitains/cts.py b/MyCapytain/resources/texts/local/capitains/cts.py index dfbec400..12a79854 100644 --- a/MyCapytain/resources/texts/local/capitains/cts.py +++ b/MyCapytain/resources/texts/local/capitains/cts.py @@ -11,7 +11,7 @@ import warnings -from MyCapytain.errors import DuplicateReference, MissingAttribute, RefsDeclError, EmptyReference, MissingRefsDecl +from MyCapytain.errors import DuplicateReference, MissingAttribute, RefsDeclError, EmptyReference, CitationDepthError, MissingRefsDecl from MyCapytain.common.utils import copyNode, passageLoop, normalizeXpath from MyCapytain.common.constants import XPATH_NAMESPACES, RDF_NAMESPACES from MyCapytain.common.reference import URN, Citation, Reference @@ -68,7 +68,7 @@ def getTextualNode(self, subreference=None, simple=False): start, end = subreference.start.list, subreference.end.list if len(start) > len(self.citation): - raise ReferenceError("URN is deeper than citation scheme") + raise CitationDepthError("URN is deeper than citation scheme") if simple is True: return self._getSimplePassage(subreference) diff --git a/tests/resources/texts/local/commonTests.py b/tests/resources/texts/local/commonTests.py index 2f250859..98c3fbac 100644 --- a/tests/resources/texts/local/commonTests.py +++ b/tests/resources/texts/local/commonTests.py @@ -430,7 +430,7 @@ def test_type_accepted_reference_validreff(self): def test_citation_length_error(self, simple): """ In range, passage in between could be removed from the original text by error """ - with self.assertRaises(ReferenceError): + with self.assertRaises(MyCapytain.errors.CitationDepthError): self.TEI.getTextualNode(["1", "pr", "2", "5"], simple=simple) def test_ensure_passage_is_not_removed(self):