Skip to content

Commit 3c5ffed

Browse files
author
Sharoon Thomas
committed
Merge pull request #8 from aroraumang/feature/task-4507
Added Coveralls and flake8ified #4507
2 parents a13011a + 5d21770 commit 3c5ffed

File tree

7 files changed

+65
-36
lines changed

7 files changed

+65
-36
lines changed

.coveragerc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[run]
2+
source = microsofttranslator
3+
4+
[report]
5+
omit = */tests/*, */fabfile.py

.travis.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
language: python
22
python:
33
- "2.7"
4-
install: python setup.py install
5-
script: python setup.py test
4+
install:
5+
- pip install flake8
6+
- python setup.py install
7+
- pip install coveralls
8+
script:
9+
- coverage run setup.py test
10+
- flake8 .
11+
after_success:
12+
coveralls
13+
notifications:
14+
email:
15+
- ci-notify@openlabs.co.in

README.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ Microsoft Translator V2 -- Python API
99
.. image:: https://secure.travis-ci.org/openlabs/Microsoft-Translator-Python-API.png?branch=master
1010
:target: http://travis-ci.org/#!/openlabs/Microsoft-Translator-Python-API
1111

12+
.. image:: https://coveralls.io/repos/openlabs/Microsoft-Translator-Python-API/badge.png
13+
:target: https://coveralls.io/r/openlabs/Microsoft-Translator-Python-API
14+
1215

1316
This python API implements the Microsoft Translator services which can be used
1417
in web or client applications to perform language translation operations. The

__init__.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
from simplejson import JSONDecodeError
1818
except ImportError:
1919
import json
20-
class JSONDecodeError(Exception): pass
20+
21+
class JSONDecodeError(Exception):
22+
pass
2123
# Ugly: No alternative because this exception class doesnt seem to be there
2224
# in the standard python module
2325
import urllib
@@ -126,7 +128,7 @@ def call(self, url, params):
126128
headers={'Authorization': 'Bearer %s' % self.access_token}
127129
)
128130
response = urllib2.urlopen(request).read()
129-
rv = json.loads(response.decode("UTF-8-sig"))
131+
rv = json.loads(response.decode("UTF-8-sig"))
130132

131133
if isinstance(rv, basestring) and \
132134
rv.startswith("ArgumentOutOfRangeException"):
@@ -159,7 +161,7 @@ def translate(self, text, to_lang, from_lang=None,
159161
'to': to_lang,
160162
'contentType': content_type,
161163
'category': category,
162-
}
164+
}
163165
if from_lang is not None:
164166
params['from'] = from_lang
165167
return self.call(
@@ -170,23 +172,23 @@ def translate_array(self, texts, to_lang, from_lang=None, **options):
170172
"""Translates an array of text strings from one language to another.
171173
172174
:param texts: A list containing texts for translation.
173-
:param to_lang: A string representing the language code to
175+
:param to_lang: A string representing the language code to
174176
translate the text into.
175-
:param from_lang: A string representing the language code of the
176-
translation text. If left None the response will include the
177+
:param from_lang: A string representing the language code of the
178+
translation text. If left None the response will include the
177179
result of language auto-detection. (Default: None)
178-
:param options: A TranslateOptions element containing the values below.
180+
:param options: A TranslateOptions element containing the values below.
179181
They are all optional and default to the most common settings.
180182
181-
Category: A string containing the category (domain) of the
183+
Category: A string containing the category (domain) of the
182184
translation. Defaults to "general".
183-
ContentType: The format of the text being translated. The
184-
supported formats are "text/plain" and "text/html". Any
185+
ContentType: The format of the text being translated. The
186+
supported formats are "text/plain" and "text/html". Any
185187
HTML needs to be well-formed.
186-
Uri: A string containing the content location of this
188+
Uri: A string containing the content location of this
187189
translation.
188190
User: A string used to track the originator of the submission.
189-
State: User state to help correlate request and response. The
191+
State: User state to help correlate request and response. The
190192
same contents will be returned in the response.
191193
"""
192194
options = {
@@ -195,12 +197,12 @@ def translate_array(self, texts, to_lang, from_lang=None, **options):
195197
'Uri': '',
196198
'User': 'default',
197199
'State': ''
198-
}.update(options)
200+
}.update(options)
199201
params = {
200202
'texts': json.dumps(texts),
201203
'to': to_lang,
202204
'options': json.dumps(options),
203-
}
205+
}
204206
if from_lang is not None:
205207
params['from'] = from_lang
206208

setup.cfg

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[flake8]
2+
exclude=.svn,CVS,.bzr,.hg,.git,__pycache__,build,dist,upload.py,doc,scripts,selenium*,proteus*,Flask*,pycountry*
3+
4+
ignore=E126,E131,E128
5+
6+
max-complexity=15
7+
max-line-length=80

setup.py

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
"""
33
Microsoft translator API
44
5-
The Microsoft Translator services can be used in web or client
6-
applications to perform language translation operations. The services
7-
support users who are not familiar with the default language of a page or
8-
application, or those desiring to communicate with people of a different
5+
The Microsoft Translator services can be used in web or client
6+
applications to perform language translation operations. The services
7+
support users who are not familiar with the default language of a page or
8+
application, or those desiring to communicate with people of a different
99
language group.
1010
1111
This module implements the AJAX API for the Microsoft Translator service.
@@ -17,7 +17,7 @@
1717
>>> print translator.translate("Hello", "pt")
1818
"Olá"
1919
20-
The documentation for the service can be obtained here:
20+
The documentation for the service can be obtained here:
2121
http://msdn.microsoft.com/en-us/library/ff512423.aspx
2222
2323
The project is hosted on GitHub where your could fork the project or report
@@ -29,26 +29,27 @@
2929
import os
3030
from setuptools import setup
3131

32+
3233
def read(fname):
3334
return open(os.path.join(os.path.dirname(__file__), fname)).read()
3435

3536
setup(
36-
name = "microsofttranslator",
37-
version = "0.4",
38-
packages = [
37+
name="microsofttranslator",
38+
version="0.4",
39+
packages=[
3940
'microsofttranslator',
40-
],
41-
package_dir = {
41+
],
42+
package_dir={
4243
'microsofttranslator': '.'
43-
},
44-
author = "Openlabs Technologies & Consulting (P) Limited",
45-
author_email = "info@openlabs.co.in",
46-
description = "Microsoft Translator V2 - Python API",
47-
long_description = read('README.rst'),
48-
license = "BSD",
49-
keywords = "translation microsoft",
50-
url = "http://openlabs.co.in/",
51-
include_package_data = True,
44+
},
45+
author="Openlabs Technologies & Consulting (P) Limited",
46+
author_email="info@openlabs.co.in",
47+
description="Microsoft Translator V2 - Python API",
48+
long_description=read('README.rst'),
49+
license="BSD",
50+
keywords="translation microsoft",
51+
url="http://openlabs.co.in/",
52+
include_package_data=True,
5253
classifiers=[
5354
"Development Status :: 4 - Beta",
5455
"Intended Audience :: Developers",
@@ -58,5 +59,5 @@ def read(fname):
5859
"Topic :: Software Development :: Internationalization",
5960
"Topic :: Utilities"
6061
],
61-
test_suite = "microsofttranslator.test.test_all",
62+
test_suite="microsofttranslator.test.test_all",
6263
)

test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def test_invalid_client_id(self):
2525
with self.assertRaises(TranslateApiException):
2626
client.translate("hello", "pt")
2727

28+
2829
def test_all():
2930
loader = unittest.TestLoader()
3031
suite = unittest.TestSuite()

0 commit comments

Comments
 (0)