From a233c4407d1827e4187de80c934cf5ca9fa4dffa Mon Sep 17 00:00:00 2001 From: Thibault Clerice Date: Fri, 11 Mar 2016 11:23:58 +0100 Subject: [PATCH 1/2] Fixed #71 --- MyCapytain/resources/inventory.py | 14 +++++++++----- tests/resources/test_inventory.py | 14 ++++++++++---- tests/testing_data/cts/getCapabilities.xml | 2 +- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/MyCapytain/resources/inventory.py b/MyCapytain/resources/inventory.py index e0e660a7..f78e4137 100644 --- a/MyCapytain/resources/inventory.py +++ b/MyCapytain/resources/inventory.py @@ -299,18 +299,22 @@ def __str__(self): :returns: XML representation of the work """ strings = [] + __lang = "" + if self.lang: + __lang = """xml:lang="{}" """.format(self.lang) + if self.urn is not None: strings.append( - "".format( - self.urn, self.urn.upTo(URN.TEXTGROUP)) + "".format( + self.urn, self.urn.upTo(URN.TEXTGROUP), __lang) ) else: if len(self.parents) > 0 and hasattr(self.parents[0], "urn") is True: - strings.append("".format( - self.parents[0].urn) + strings.append("".format( + self.parents[0].urn, __lang) ) else: - strings.append("") + strings.append("".format(__lang)) for tag, metadatum in self.metadata: for lang, value in metadatum: strings.append("{value}".format(tag=tag, lang=lang, value=value)) diff --git a/tests/resources/test_inventory.py b/tests/resources/test_inventory.py index 57f047b3..3b6297db 100644 --- a/tests/resources/test_inventory.py +++ b/tests/resources/test_inventory.py @@ -126,7 +126,7 @@ def setUp(self): """.replace("\n", "") - self.wk = """ + self.wk = """ Epigrammata Epigrammes""" + self.tr + self.ed + """""".replace("\n", "") @@ -158,6 +158,8 @@ def test_xml_TextInventory_GetItem(self): self.assertEqual(str(TI["urn:cts:latinLit:phi1294.phi002"].urn), "urn:cts:latinLit:phi1294.phi002") self.assertIsInstance(TI["urn:cts:latinLit:phi1294.phi002.perseus-lat2"], Text) self.assertEqual(str(TI["urn:cts:latinLit:phi1294.phi002.perseus-lat2"].urn), "urn:cts:latinLit:phi1294.phi002.perseus-lat2") + self.assertEqual(TI["urn:cts:latinLit:phi1294.phi002"].lang, "lat") + self.assertEqual(TI["urn:cts:latinLit:phi1294.phi002.perseus-lat2"].lang, "lat") def test_xml_Work_GetItem(self): """ Test access through getItem obj[urn] """ @@ -171,7 +173,7 @@ def test_xml_Work_GetItem(self): def test_xml_work_getLang(self): """ Test access to translation """ xml = """ - + Epigrammata @@ -187,10 +189,11 @@ def test_xml_work_getLang(self): self.assertEqual(len(W.getLang("eng")), 2) self.assertEqual(len(W.getLang()), 3) + def test_xml_Text_others(self): """ Test access to translation """ xml = """ - + Epigrammata @@ -206,6 +209,7 @@ def test_xml_Text_others(self): E = W["urn:cts:latinLit:phi1294.phi002.perseus-lat2"] T = W["urn:cts:latinLit:phi1294.phi002.perseus-fre1"] + self.assertEqual(E.lang, "lat") self.assertEqual(E.translations("fre"), [T]) self.assertEqual(T.editions(), [E]) @@ -305,7 +309,7 @@ def test_export(self): """.replace("\n", "") - wk = """ + wk = """ Epigrammata Epigrammes""" + tr + ed + """""".replace("\n", "") @@ -330,6 +334,8 @@ def test_export(self): self.assertXmlEquivalentOutputs(*compareXML(ti["urn='urn:cts:latinLit:phi1294.phi002"].export(), wk)) self.assertXmlEquivalentOutputs(*compareXML(ti["urn='urn:cts:latinLit:phi1294.phi002.perseus-eng2"].export(), tr)) self.assertXmlEquivalentOutputs(*compareXML(ti["urn='urn:cts:latinLit:phi1294.phi002.perseus-lat2"].export(), ed)) + self.assertEqual(ti["urn='urn:cts:latinLit:phi1294.phi002.perseus-lat2"].lang, "lat") + self.assertEqual(ti["urn='urn:cts:latinLit:phi1294.phi002.perseus-eng2"].lang, "eng") def test_export_to_text(self): """ Test export to Text object """ diff --git a/tests/testing_data/cts/getCapabilities.xml b/tests/testing_data/cts/getCapabilities.xml index b51c0497..10f66fb2 100644 --- a/tests/testing_data/cts/getCapabilities.xml +++ b/tests/testing_data/cts/getCapabilities.xml @@ -243,7 +243,7 @@ Martial Martialis - + Epigrammata Epigrammes From 9f6e7ab7239c485f2272fce4a338bc14e90d2552 Mon Sep 17 00:00:00 2001 From: Thibault Clerice Date: Fri, 11 Mar 2016 11:27:04 +0100 Subject: [PATCH 2/2] Bump to 0.1.1 with special new badge on readme --- MyCapytain/__init__.py | 2 +- README.rst | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/MyCapytain/__init__.py b/MyCapytain/__init__.py index 7fba3b05..e023cd6a 100644 --- a/MyCapytain/__init__.py +++ b/MyCapytain/__init__.py @@ -10,5 +10,5 @@ """ __name__ = "MyCapytain" -__version__ = "0.1.0" +__version__ = "0.1.1" __all__ = ["common", "endpoints", "resources"] diff --git a/README.rst b/README.rst index 69f0278b..8e47f9e2 100644 --- a/README.rst +++ b/README.rst @@ -10,7 +10,8 @@ :target: http://mycapytain.readthedocs.org .. image:: https://zenodo.org/badge/3923/Capitains/MyCapytain.svg :target: https://zenodo.org/badge/latestdoi/3923/Capitains/MyCapytain - +.. image:: https://img.shields.io/pypi/dm/MyCapytain.svg + :target: https://pypi.python.org/pypi/MyCapytain MyCapytain is a python package which provides a large set of tools to deal with CTS and Capitains Guidelines in Python. Installation and Requirements