Skip to content

Commit

Permalink
Corrected problem with non-existent text (#131)
Browse files Browse the repository at this point in the history
* Corrected problem with non-existent text

Such a text that was present in the metadata but did not exist would cause a call to the text resolver to fail

Added a warning message if the file does not exist and testing for this new functionality in unit tests

* Bumped version and added text to CHANGES.md

* Corrected typo

* Update CHANGES.md
  • Loading branch information
sonofmun authored May 15, 2017
1 parent 6eeb135 commit fbd6643
Show file tree
Hide file tree
Showing 9 changed files with 60,816 additions and 4 deletions.
6 changes: 5 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### 2017-04-06 2.0.1rc1 @sonofmun

Corrected bug with the `CtsCapitainsLocalResolver.__getText__` that it would stop if a text was mentioned in the metadata but the file did not exist

### 2017-04-06 2.0.0rc1 @ponteineptique

- Simplified Metadata object and its relation to other items. Metadata is now more of an helper to mediate with triple regarding an object (text, passage or collection)
Expand Down Expand Up @@ -36,4 +40,4 @@ Made a lot of renaming for clarity :
| MyCapytain.resources.collections.cts.TextInventory | MyCapytain.resources.collections.cts.inventory.XmlCtsTextInventoryMetadata |
| MyCapytain.retrievers.cts5.CTS | MyCapytain.retrievers.cts5.HttpCtsRetriever |

Automatically moved all names matching "CTS\w+" to "Cts\w+"
Automatically moved all names matching "CTS\w+" to "Cts\w+"
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.0"
__version__ = "2.0.1"
8 changes: 6 additions & 2 deletions MyCapytain/resolvers/cts/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,12 @@ def __getText__(self, urn):

text = self.inventory[str(urn)]

with io.open(text.path) as __xml__:
resource = self.TEXT_CLASS(urn=urn, resource=self.xmlparse(__xml__))
if os.path.isfile(text.path):
with io.open(text.path) as __xml__:
resource = self.TEXT_CLASS(urn=urn, resource=self.xmlparse(__xml__))
else:
resource = None
self.logger.warning('The file {} is mentioned in the metadata but does not exist'.format(text.path))

return resource, text

Expand Down
14 changes: 14 additions & 0 deletions tests/resolvers/cts/test_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,20 @@ def test_text_resource(self):
"It should be possible to retrieve text"
)

def test_missing_text_resource(self):
""" Test to make sure the correct warning is raised if a text is missing """
with self.assertLogs(CtsCapitainsLocalResolver(["./tests/testing_data/missing_text"]).logger) as cm:
Repository = CtsCapitainsLocalResolver(["./tests/testing_data/missing_text"])
text, metadata = Repository.__getText__("urn:cts:farsiLit:hafez.divan.missing_text")
self.assertIsNone(text)
self.assertIn('WARNING:root:The file '
'./tests/testing_data/missing_text/data/hafez/divan/hafez.divan.missing_text.xml '
'is mentioned in the metadata but does not exist', cm.output)
self.assertIn(
'ERROR:root:./tests/testing_data/missing_text/data/hafez/divan/hafez.divan.missing_text.xml is not present',
cm.output
)

def test_get_capabilities(self):
""" Check Get Capabilities """
Repository = CtsCapitainsLocalResolver(
Expand Down
3 changes: 3 additions & 0 deletions tests/testing_data/missing_text/data/hafez/__cts__.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<ti:textgroup xmlns:ti="http://chs.harvard.edu/xmlns/cts" projid="farsiLit:hafez" urn="urn:cts:farsiLit:hafez">
<ti:groupname xml:lang="eng">Hafez</ti:groupname>
</ti:textgroup>
29 changes: 29 additions & 0 deletions tests/testing_data/missing_text/data/hafez/divan/__cts__.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<ti:work xmlns:ti="http://chs.harvard.edu/xmlns/cts" groupUrn="urn:cts:farsiLit:hafez" projid="farsiLit:divan" urn="urn:cts:farsiLit:hafez.divan" xml:lang="fa">
<ti:title xml:lang="eng">Div&#257;n</ti:title>
<ti:edition urn="urn:cts:farsiLit:hafez.divan.perseus-far1" workUrn="urn:cts:farsiLit:hafez.divan">
<ti:label xml:lang="eng">Div&#257;n</ti:label>
<ti:description xml:lang="eng">Perseus:bib:oclc, 254557372. Diwan-i Hwaga Sams-ad-Din
Muhammad Hafiz Sirazi qaddas sarra-yi al-aziz ba tamam. edited by Muhammad
Qazwini and Qasim Gani as available on ganjoor.net. Tehran, Caphana-i Maglis.
1941. </ti:description>
</ti:edition>
<ti:translation xml:lang="eng" urn="urn:cts:farsiLit:hafez.divan.perseus-eng1" workUrn="urn:cts:farsiLit:hafez.divan">
<ti:label xml:lang="eng">Div&#257;n (English)</ti:label>
<ti:description xml:lang="eng">Perseus:bib:oclc, 559481156. The D&#299;v&#257;n .Translated for
the first time out of the Persian into English prose, with critical and
explanatory remarks, with an introductory preface, with a note on &#7778;&#363;f&#299;ism, and
with a life of the author, by H. Wilberforce Clarke. Calcutta, India. 1891. </ti:description>
</ti:translation>
<ti:translation xml:lang="ger" urn="urn:cts:farsiLit:hafez.divan.perseus-ger1" workUrn="urn:cts:farsiLit:hafez.divan">
<ti:label xml:lang="eng">Div&#257;n (German)</ti:label>
<ti:description xml:lang="eng">Perseus:bib:oclc, 6773200. Mohammed Schemsed-din Hafis,
Der Diwan, Aus dem Persischen zum erstenmal ganz &#252;bersetzt von Joseph von
Hammer-Purgstall. Stuttgart and T&#252;bingen, 1812. </ti:description>
</ti:translation>
<ti:translation xml:lang="ger" urn="urn:cts:farsiLit:hafez.divan.missing_text" workUrn="urn:cts:farsiLit:hafez.divan">
<ti:label xml:lang="eng">Div&#257;n (German)</ti:label>
<ti:description xml:lang="eng">Perseus:bib:oclc, 6773200. Mohammed Schemsed-din Hafis,
Der Diwan, Aus dem Persischen zum erstenmal ganz &#252;bersetzt von Joseph von
Hammer-Purgstall. Stuttgart and T&#252;bingen, 1812. </ti:description>
</ti:translation>
</ti:work>
Loading

0 comments on commit fbd6643

Please sign in to comment.