Skip to content

Commit

Permalink
Merge pull request #196 from Capitains/pr-review
Browse files Browse the repository at this point in the history
* (PR 3.0.0) Comment 6 of @sonofmun review : DtsCitationSet docstring completed
* (PR 3.0.0) Comment 7 of @sonofmun review : Example on JSONLdCollection
* (PR 3.0.0) Comment 8 of @sonofmun review : Better description of EmptyReference
* (PR 3.0.0) Comment 9/10 of @sonofmun review : Used _parse_wrapper in resolvers.cts.local
* (PR 3.0.0) Comment 12 of @sonofmun review : Clean up of _cls_dict in some docstrings
* (PR 3.0.0) Comment 13 of @sonofmun review : Fix docstring for type in prototypes.cts.text.set_metadata...
* (PR 3.0.0) Comment 14 of @sonofmun review : Fix docstring for retrievers and resolvers
* (PR 3.0.0) Comment 16/17 of @sonofmun review : Fix error message in test_citation_dts
* (PR 3.0.0) Comment 18 of @sonofmun review : Fix next/previous reference in test_local of cts
* (PR 3.0.0) Comment 19 of @sonofmun review : correct title of col.1.1.1
* (PR 3.0.0) Comment 20 of @sonofmun review : Remove trailing print
  • Loading branch information
PonteIneptique committed Oct 15, 2019
2 parents 7165528 + 3860683 commit 3ff0f27
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 23 deletions.
3 changes: 2 additions & 1 deletion MyCapytain/common/reference/_dts_1.py
Expand Up @@ -100,7 +100,8 @@ def match(self, passageId):


class DtsCitationSet(BaseCitationSet):
""" Set of citation that are supposed
""" Set of citations following the DTS model (Unlike CTS, one citation
can have two or more children)
"""

Expand Down
7 changes: 5 additions & 2 deletions MyCapytain/errors.py
Expand Up @@ -15,7 +15,10 @@ class MyCapytainException(BaseException):


class JsonLdCollectionMissing(MyCapytainException):
""" Error thrown when a JSON LD has now first ressource
""" Error thrown when a JSON LD contains no principle collection
Raised when a json supposed to contain collection is parsed
but nothing is found
"""


Expand Down Expand Up @@ -68,7 +71,7 @@ class UnknownCollection(KeyError, MyCapytainException):


class EmptyReference(SyntaxWarning, MyCapytainException):
""" Error generated when a CtsReference is wrong
""" Error generated when a CtsReference does not exist or is invalid
"""


Expand Down
4 changes: 2 additions & 2 deletions MyCapytain/resolvers/cts/local.py
Expand Up @@ -286,14 +286,14 @@ def parse(self, resource):
for folder in resource:
cts_files = glob("{base_folder}/data/*/__cts__.xml".format(base_folder=folder))
for cts_file in cts_files:
textgroup, cts_file = self._parse_textgroup(cts_file)
textgroup, cts_file = self._parse_textgroup_wrapper(cts_file)
textgroups.append((textgroup, cts_file))

for textgroup, cts_textgroup_file in textgroups:
cts_work_files = glob("{parent}/*/__cts__.xml".format(parent=os.path.dirname(cts_textgroup_file)))

for cts_work_file in cts_work_files:
_, parsed_texts, directory = self._parse_work(cts_work_file, textgroup)
_, parsed_texts, directory = self._parse_work_wrapper(cts_work_file, textgroup)
texts.extend([(text, directory) for text in parsed_texts])

for text, directory in texts:
Expand Down
4 changes: 3 additions & 1 deletion MyCapytain/resolvers/dts/api_v1.py
Expand Up @@ -70,6 +70,7 @@ def endpoint(self) -> HttpDtsRetriever:
return self._endpoint

def getMetadata(self, objectId: str=None, **filters) -> HttpResolverDtsCollection:
""" Retrieves metadata calling the Collections Endpoint """
req = self.endpoint.get_collection(objectId)
req.raise_for_status()

Expand All @@ -87,6 +88,7 @@ def getReffs(
include_descendants: bool=False,
additional_parameters: Optional[Dict[str, Any]]=None
) -> DtsReferenceSet:
""" Retrieve references by calling the Navigation API """
if not additional_parameters:
additional_parameters = {}

Expand Down Expand Up @@ -151,7 +153,7 @@ def getTextualNode(
prevnext: bool=False,
metadata: bool=False
) -> DtsResolverDocument:
""" Retrieve a text node from the API
""" Retrieve a text node from the API via the Document Endpoint
:param textId: CtsTextMetadata Identifier
:type textId: str
Expand Down
4 changes: 0 additions & 4 deletions MyCapytain/resources/collections/cts.py
Expand Up @@ -257,10 +257,8 @@ def parse(cls, resource, parent=None, _with_children=False):
""" Parse a resource
:param resource: Element rerpresenting a work
:param type: basestring, etree._Element
:param parent: Parent of the object
:type parent: XmlCtsTextgroupMetadata
:param _cls_dict: Dictionary of classes to generate subclasses
"""
xml = xmlparser(resource)
o = cls(urn=xml.get("urn"), parent=parent)
Expand Down Expand Up @@ -307,7 +305,6 @@ def parse(cls, resource, parent=None):
:param resource: Element representing the textgroup
:param parent: Parent of the textgroup
:param _cls_dict: Dictionary of classes to generate subclasses
"""
xml = xmlparser(resource)
o = cls(urn=xml.get("urn"), parent=parent)
Expand All @@ -334,7 +331,6 @@ def parse(cls, resource):
""" Parse a resource
:param resource: Element representing the text inventory
:param _cls_dict: Dictionary of classes to generate subclasses
"""
xml = xmlparser(resource)
o = cls(name=xml.xpath("//ti:TextInventory", namespaces=XPATH_NAMESPACES)[0].get("tiid") or "")
Expand Down
2 changes: 1 addition & 1 deletion MyCapytain/resources/prototypes/cts/text.py
Expand Up @@ -95,7 +95,7 @@ def set_metadata_from_collection(self, text_metadata: CtsTextMetadata):
""" Set the object metadata using its collections recursively
:param text_metadata: Object representing the current text as a collection
:type text_metadata: CtsEditionMetadata or CtsTranslationMetadata
:type text_metadata: CtsTextMetadata
"""
edition, work, textgroup = tuple(([text_metadata] + text_metadata.parents)[:3])

Expand Down
2 changes: 1 addition & 1 deletion MyCapytain/retrievers/dts/__init__.py
Expand Up @@ -158,7 +158,7 @@ def get_navigation(
def get_document(
self,
collection_id, ref=None, mimetype="application/tei+xml, application/xml"):
""" Make a navigation request on the DTS API
""" Make a document request on the DTS API
:param collection_id: Id of the collection
:param ref: If ref is a tuple, it is treated as a range. String or int are treated as single ref
Expand Down
6 changes: 3 additions & 3 deletions tests/common/test_reference/test_citation_dts.py
Expand Up @@ -112,14 +112,14 @@ def test_ingest_simple_line(self):
cite = DtsCitationSet.ingest(_context(_ex_2))
children = {c.name: c for c in cite}

self.assertEqual(2, cite.depth, "There should be 3 levels of citation")
self.assertEqual(2, len(cite), "There should be 5 children")
self.assertEqual(2, cite.depth, "There should be 2 levels of citation")
self.assertEqual(2, len(cite), "There should be 2 children")

self.assertEqual(list(cite[-1]), [children["line"]], "Last level should contain line only")
self.assertEqual(list(cite[-1]), list(cite[1]), "-1 level == level 1")

self.assertCountEqual(list(cite[-2]), [children["poem"]], "-2 level == level 0")
self.assertCountEqual(list(cite[-2]), list(cite[0]), "-32 level == level 0")
self.assertCountEqual(list(cite[-2]), list(cite[0]), "-2 level == level 0")

self.assertIsInstance(cite, DtsCitationSet, "Root should be a DtsCitationSet")
self.assertEqual([type(child) for child in cite.children], [DtsCitation], "Children should be DtsCitation")
Expand Down
12 changes: 6 additions & 6 deletions tests/resolvers/cts/test_local.py
Expand Up @@ -544,11 +544,11 @@ def test_getSiblings(self):
)
self.assertEqual(
previous, CtsReference("1.pr"),
"Previous should be well computed"
"Previous reference should be well computed"
)
self.assertEqual(
nextious, CtsReference("1.2"),
"Previous should be well computed"
"Next reference should be well computed"
)

def test_getSiblings_nextOnly(self):
Expand All @@ -558,11 +558,11 @@ def test_getSiblings_nextOnly(self):
)
self.assertEqual(
previous, None,
"Previous Should not exist"
"Previous reference should not exist"
)
self.assertEqual(
nextious, CtsReference("1.1"),
"Next should be well computed"
"Next reference should be well computed"
)

def test_getSiblings_prevOnly(self):
Expand All @@ -572,11 +572,11 @@ def test_getSiblings_prevOnly(self):
)
self.assertEqual(
previous, CtsReference("14.222"),
"Previous should be well computed"
"Previous reference should be well computed"
)
self.assertEqual(
nextious, None,
"Next should not exist"
"Next reference should not exist"
)

def test_getReffs_full(self):
Expand Down
Expand Up @@ -7,5 +7,5 @@
"@id": "/coll1_1_1",
"@type": "Resource",
"totalItems": 0,
"title": "Collection 1.2.1"
"title": "Collection 1.1.1"
}
2 changes: 1 addition & 1 deletion tests/resolvers/dts/api_v1/test_metadata.py
Expand Up @@ -254,7 +254,7 @@ def add_mock(mocks, id_):
"Collections should be retrieved automatically"
)
history = [history.url for history in mock_set.request_history]
print(history)

self.assertNotIn(
self.root_uri+"/collections?id=%2Fcoll1_2_2_1",
history,
Expand Down

0 comments on commit 3ff0f27

Please sign in to comment.