diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 0000000..7424faf --- /dev/null +++ b/.coveragerc @@ -0,0 +1,5 @@ +[run] +source = microsofttranslator + +[report] +omit = */tests/*, */fabfile.py diff --git a/.travis.yml b/.travis.yml index f1f3964..8e31262 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,15 @@ language: python python: - "2.7" -install: python setup.py install -script: python setup.py test +install: + - pip install flake8 + - python setup.py install + - pip install coveralls +script: + - coverage run setup.py test + - flake8 . +after_success: + coveralls +notifications: + email: + - ci-notify@openlabs.co.in diff --git a/README.rst b/README.rst index c579002..92a646e 100644 --- a/README.rst +++ b/README.rst @@ -9,6 +9,9 @@ Microsoft Translator V2 -- Python API .. image:: https://secure.travis-ci.org/openlabs/Microsoft-Translator-Python-API.png?branch=master :target: http://travis-ci.org/#!/openlabs/Microsoft-Translator-Python-API +.. image:: https://coveralls.io/repos/openlabs/Microsoft-Translator-Python-API/badge.png + :target: https://coveralls.io/r/openlabs/Microsoft-Translator-Python-API + This python API implements the Microsoft Translator services which can be used in web or client applications to perform language translation operations. The diff --git a/__init__.py b/__init__.py index 362f4c8..e9f5233 100644 --- a/__init__.py +++ b/__init__.py @@ -17,7 +17,9 @@ from simplejson import JSONDecodeError except ImportError: import json - class JSONDecodeError(Exception): pass + + class JSONDecodeError(Exception): + pass # Ugly: No alternative because this exception class doesnt seem to be there # in the standard python module import urllib @@ -126,7 +128,7 @@ def call(self, url, params): headers={'Authorization': 'Bearer %s' % self.access_token} ) response = urllib2.urlopen(request).read() - rv = json.loads(response.decode("UTF-8-sig")) + rv = json.loads(response.decode("UTF-8-sig")) if isinstance(rv, basestring) and \ rv.startswith("ArgumentOutOfRangeException"): @@ -159,7 +161,7 @@ def translate(self, text, to_lang, from_lang=None, 'to': to_lang, 'contentType': content_type, 'category': category, - } + } if from_lang is not None: params['from'] = from_lang return self.call( @@ -170,23 +172,23 @@ def translate_array(self, texts, to_lang, from_lang=None, **options): """Translates an array of text strings from one language to another. :param texts: A list containing texts for translation. - :param to_lang: A string representing the language code to + :param to_lang: A string representing the language code to translate the text into. - :param from_lang: A string representing the language code of the - translation text. If left None the response will include the + :param from_lang: A string representing the language code of the + translation text. If left None the response will include the result of language auto-detection. (Default: None) - :param options: A TranslateOptions element containing the values below. + :param options: A TranslateOptions element containing the values below. They are all optional and default to the most common settings. - Category: A string containing the category (domain) of the + Category: A string containing the category (domain) of the translation. Defaults to "general". - ContentType: The format of the text being translated. The - supported formats are "text/plain" and "text/html". Any + ContentType: The format of the text being translated. The + supported formats are "text/plain" and "text/html". Any HTML needs to be well-formed. - Uri: A string containing the content location of this + Uri: A string containing the content location of this translation. User: A string used to track the originator of the submission. - State: User state to help correlate request and response. The + State: User state to help correlate request and response. The same contents will be returned in the response. """ options = { @@ -195,12 +197,12 @@ def translate_array(self, texts, to_lang, from_lang=None, **options): 'Uri': '', 'User': 'default', 'State': '' - }.update(options) + }.update(options) params = { 'texts': json.dumps(texts), 'to': to_lang, 'options': json.dumps(options), - } + } if from_lang is not None: params['from'] = from_lang diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..0f41843 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,7 @@ +[flake8] +exclude=.svn,CVS,.bzr,.hg,.git,__pycache__,build,dist,upload.py,doc,scripts,selenium*,proteus*,Flask*,pycountry* + +ignore=E126,E131,E128 + +max-complexity=15 +max-line-length=80 diff --git a/setup.py b/setup.py index 9457099..d007718 100644 --- a/setup.py +++ b/setup.py @@ -2,10 +2,10 @@ """ Microsoft translator API - The Microsoft Translator services can be used in web or client - applications to perform language translation operations. The services - support users who are not familiar with the default language of a page or - application, or those desiring to communicate with people of a different + The Microsoft Translator services can be used in web or client + applications to perform language translation operations. The services + support users who are not familiar with the default language of a page or + application, or those desiring to communicate with people of a different language group. This module implements the AJAX API for the Microsoft Translator service. @@ -17,7 +17,7 @@ >>> print translator.translate("Hello", "pt") "Olá" - The documentation for the service can be obtained here: + The documentation for the service can be obtained here: http://msdn.microsoft.com/en-us/library/ff512423.aspx The project is hosted on GitHub where your could fork the project or report @@ -29,26 +29,27 @@ import os from setuptools import setup + def read(fname): return open(os.path.join(os.path.dirname(__file__), fname)).read() setup( - name = "microsofttranslator", - version = "0.4", - packages = [ + name="microsofttranslator", + version="0.4", + packages=[ 'microsofttranslator', - ], - package_dir = { + ], + package_dir={ 'microsofttranslator': '.' - }, - author = "Openlabs Technologies & Consulting (P) Limited", - author_email = "info@openlabs.co.in", - description = "Microsoft Translator V2 - Python API", - long_description = read('README.rst'), - license = "BSD", - keywords = "translation microsoft", - url = "http://openlabs.co.in/", - include_package_data = True, + }, + author="Openlabs Technologies & Consulting (P) Limited", + author_email="info@openlabs.co.in", + description="Microsoft Translator V2 - Python API", + long_description=read('README.rst'), + license="BSD", + keywords="translation microsoft", + url="http://openlabs.co.in/", + include_package_data=True, classifiers=[ "Development Status :: 4 - Beta", "Intended Audience :: Developers", @@ -58,5 +59,5 @@ def read(fname): "Topic :: Software Development :: Internationalization", "Topic :: Utilities" ], - test_suite = "microsofttranslator.test.test_all", + test_suite="microsofttranslator.test.test_all", ) diff --git a/test.py b/test.py index 30fca75..893912b 100644 --- a/test.py +++ b/test.py @@ -25,6 +25,7 @@ def test_invalid_client_id(self): with self.assertRaises(TranslateApiException): client.translate("hello", "pt") + def test_all(): loader = unittest.TestLoader() suite = unittest.TestSuite()