Skip to content

Commit

Permalink
working on docstring completion #24
Browse files Browse the repository at this point in the history
  • Loading branch information
Guts committed Mar 27, 2018
1 parent 234012d commit 3dd7f09
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 13 deletions.
4 changes: 2 additions & 2 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ Isogeo PySDK's documentation
:caption: Contents:

.. module:: isogeo-pysdk
.. moduleauthor:: Julien Moura
.. moduleauthor:: Julien M. (Isogeo)

:Author: Julien Moura (Isogeo)
:Author: Julien M. (Isogeo)
:Source code: https://github.com/Guts/isogeo-api-py-minsdk/
:Issues: https://github.com/Guts/isogeo-api-py-minsdk/issues

Expand Down
42 changes: 33 additions & 9 deletions isogeo_pysdk/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
# ----------------------------------------------------------------------------

"""
Additionnal strings to be translated in the exports.
Additionnal strings to be translated from Isogeo API.
"""

# Created: 18/10/2016
# Updated: 22/11/2016
# ---------------------------------------------------------------------------

# ##############################################################################
Expand Down Expand Up @@ -194,10 +193,16 @@


class IsogeoTranslator(object):
"""Makes easier the translation of Isogeo API specific strings."""
"""
Makes easier the translation of Isogeo API specific strings.
"""

def __init__(self, lang="FR"):
"""Set text dictionary depending on language passed."""
"""
Instanciate IsogeoTranslator depending on required language.
:param str lang: language code to apply. EN or FR.
"""
if lang == "FR":
self.translations = dict_md_fields_fr
else:
Expand All @@ -206,19 +211,38 @@ def __init__(self, lang="FR"):
super(IsogeoTranslator, self).__init__()

def tr(self, subdomain=None, string_to_translate=""):
"""Returns translation of string passed."""
"""
Returns translation of string passed.
:param str subdomain: subpart of strings dictionary.
Must be one of self.translations.keys() i.e. 'restrictions'
:param str string_to_translate: string you want to translate
"""
if subdomain:
str_translated = self.translations.get(subdomain, {"error": "Subdomain not found: {}".format(subdomain)})\
.get(string_to_translate, "String not found")
# check subdomain
if subdomain not in self.translations.keys():
raise ValueError("'{}' is not a correct subdomain."
" Must be one of {}"
.format(subdomain,
self.translations.keys()))
else:
pass
# translate
str_translated = self.translations.get(subdomain,
{"error": "Subdomain not found: {}"
.format(subdomain)})\
.get(string_to_translate,
"String not found")
else:
str_translated = self.translations.get(string_to_translate, "String not found")
str_translated = self.translations.get(string_to_translate,
"String not found")
# end of method
return str_translated


# ##############################################################################
# ##### Stand alone program ########
# ##################################

if __name__ == '__main__':
"""Standalone execution."""
# French
Expand Down
13 changes: 11 additions & 2 deletions isogeo_pysdk/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,23 @@


class IsogeoUtils(object):
"""Makes easier the translation of Isogeo API specific strings."""
"""
Complementary set of utilitary methods and functions to make it easier
using Isogeo API.
"""
API_URLS = {"prod": "api",
"qa": "api.qa",
# "int": "api.int.hq.isogeo.fr"
}

def __init__(self, proxies=dict()):
"""Set text dictionary depending on language passed."""
"""
Instanciate IsogeoUtils module.
:param dict proxies: dictionary of proxy settings as described in
requests
(http://docs.python-requests.org/en/master/user/advanced/#proxies)
"""
self.platform, self.base_url = self.set_base_url()
self.proxies = proxies
super(IsogeoUtils, self).__init__()
Expand Down
7 changes: 7 additions & 0 deletions tests/test_translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ def test_translation_en(self):
for role in self.li_contacts_roles:
self.assertIn(tr.tr("roles", role), li_contacts_en)

def test_translation_bad(self):
"""Test translation of inexistent word.."""
tr = IsogeoTranslator("EN")
with self.assertRaises(ValueError):
for role in self.li_contacts_roles:
self.assertIn(tr.tr("BAD_SUBDOMAIN", role), li_contacts_en)


# #############################################################################
# ######## Standalone ##############
Expand Down

0 comments on commit 3dd7f09

Please sign in to comment.