diff --git a/CHANGES.md b/CHANGES.md index aade3e7a..3b28d901 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,4 +1,5 @@ ### 2018-07-27 2.0.9 @sonofmun + - Removed a random print statement that had been used for debugging empty references ### 2018-06-25 2.0.8 @sonofmun diff --git a/MyCapytain/errors.py b/MyCapytain/errors.py index 4a5b3e33..82bf5389 100644 --- a/MyCapytain/errors.py +++ b/MyCapytain/errors.py @@ -66,7 +66,12 @@ 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 f870d077..eeb62e21 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, CitationDepthError +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 @@ -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 ee8018c8..98c3fbac 100644 --- a/tests/resources/texts/local/commonTests.py +++ b/tests/resources/texts/local/commonTests.py @@ -247,10 +247,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 """