Permalink
Browse files

use flake8 in a Travis compatible way

  • Loading branch information...
1 parent d0d3449 commit 116d2888284837f9ac4fcf3c897eca8f4de9646c @andrew-stripe andrew-stripe committed Dec 5, 2013
View
@@ -10,6 +10,9 @@ before_install:
- sudo apt-get update
- sudo apt-get install libcurl4-gnutls-dev librtmp-dev
install:
+ - pip install pycurl flake8 --use-mirrors
+ - if [[ $TRAVIS_PYTHON_VERSION == 2* ]]; then pip install --use-mirrors simplejson; fi
- python setup.py install
- - python -c 'print(__import__("requests").__version__)'
+before_script:
+ - if [[ $TRAVIS_PYTHON_VERSION == '2.7' ]]; then flake8 stripe; fi
script: python -W always setup.py test
View
@@ -40,6 +40,6 @@
packages=['stripe', 'stripe.test'],
package_data={'stripe': ['data/ca-certificates.crt', '../VERSION']},
install_requires=install_requires,
- test_suite='stripe.test',
+ test_suite='stripe.test.all',
use_2to3 = True,
)
View
@@ -14,27 +14,28 @@
# Resource
-from stripe.resource import (
+from stripe.resource import ( # noqa
Account, Balance, BalanceTransaction, Card, Charge, Customer, Invoice,
InvoiceItem, Plan, Token, Coupon, Event, Transfer, Recipient)
# Error imports. Note that we may want to move these out of the root
# namespace in the future and you should prefer to access them via
# the fully qualified `stripe.error` module.
-from stripe.error import (StripeError, APIError, APIConnectionError,
- AuthenticationError, CardError, InvalidRequestError)
+from stripe.error import ( # noqa
+ StripeError, APIError, APIConnectionError, AuthenticationError, CardError,
+ InvalidRequestError)
# DEPRECATED: These imports will be moved out of the root stripe namespace
# in version 2.0
-from stripe.version import VERSION
-from stripe.api_requestor import APIRequestor
-from stripe.resource import (
+from stripe.version import VERSION # noqa
+from stripe.api_requestor import APIRequestor # noqa
+from stripe.resource import ( # noqa
convert_to_stripe_object, StripeObject, StripeObjectEncoder,
APIResource, ListObject, SingletonAPIResource, ListableAPIResource,
CreateableAPIResource, UpdateableAPIResource, DeletableAPIResource)
-from stripe.util import json, logger
+from stripe.util import json, logger # noqa
# This is a pretty ugly solution to deprecating modules but a similar
@@ -2,7 +2,6 @@
import datetime
import platform
import time
-import types
import urllib
import urlparse
import warnings
View
@@ -6,7 +6,11 @@ def __init__(self, message=None, http_body=None, http_status=None,
super(StripeError, self).__init__(message)
if http_body and hasattr(http_body, 'decode'):
- http_body = http_body.decode('utf-8')
+ try:
+ http_body = http_body.decode('utf-8')
+ except:
+ http_body = '<could not decode utf-8 body>'
@jbalogh
jbalogh Dec 5, 2013 Contributor

Because it wasn't actually utf-8? Is there an escape hatch to debug this?

@metcalf
metcalf Dec 5, 2013 Contributor

This is probably a "contact support" kind of instance anyway since it indicates that we're sending something malformed over the wire. I'll comment to that effect in the error message.

+
self.http_body = http_body
self.http_status = http_status
@@ -1,7 +1,6 @@
import os
import sys
import textwrap
-import sys
import warnings
from stripe import error, util
@@ -262,11 +261,8 @@ def request(self, method, url, headers, post_data=None):
try:
response = urllib2.urlopen(req)
- try:
- rbody = response.read()
- rcode = response.code
- finally:
- response.close()
+ rbody = response.read()
+ rcode = response.code
except urllib2.HTTPError, e:
rcode = e.code
rbody = e.read()
@@ -101,6 +101,7 @@ def test_exception(self):
self.make_request,
'get', self.valid_url, {}, None)
+
class RequestsVerify(object):
def __eq__(self, other):
@@ -71,14 +71,15 @@ def __eq__(self, other):
for part in ('scheme', 'netloc', 'path', 'fragment'):
expected = getattr(self.exp_parts, part)
actual = getattr(other_parts, part)
- if expected != actual:
+ if expected != actual:
print 'Expected %s "%s" but got "%s"' % (
part, expected, actual)
return False
q_matcher = QueryMatcher(stripe.util.parse_qsl(self.exp_parts.query))
return q_matcher == other
+
class APIRequestorRequestTests(StripeUnitTestCase):
ENCODE_INPUTS = {
'dict': {
@@ -3,7 +3,7 @@
from stripe.test.helper import (
StripeUnitTestCase, StripeApiTestCase,
MySingleton, MyListable, MyCreatable, MyUpdateable, MyDeletable,
- MyComposite, MyResource, SAMPLE_INVOICE)
+ MyResource, SAMPLE_INVOICE)
from stripe import util
@@ -1,21 +0,0 @@
-import unittest
-import subprocess
-import os
-import sys
-
-
-class WholesomeTests(unittest.TestCase):
-
- def test_pep8(self):
- if sys.version_info >= (3, 0):
- self.skipTest('2to3 may not return pep8 compliant code')
-
- code_dir = os.path.join(os.path.dirname(__file__), '..')
-
- rc = subprocess.call(('pep8', code_dir))
-
- if rc:
- self.fail('Code is not pep 8 compliant')
-
-if __name__ == '__main__':
- unittest.main()
View
@@ -1,12 +1,10 @@
-import calendar
-import datetime
import logging
-import re
import sys
-import time
logger = logging.getLogger('stripe')
+__all__ = ['StringIO', 'parse_qsl', 'json', 'utf8']
+
try:
# When cStringIO is available
import cStringIO as StringIO
View
@@ -8,15 +8,20 @@ envlist = py25, py26, py27, pypy, py33
[testenv]
deps =
- nose
+ flake8
pycurl>=7.19
requests>=0.8.8
mock>=1.0.1
commands = python -W always setup.py test
+[testenv:py27]
+commands =
+ - flake8 stripe
+ - python -W always setup.py test
+
[testenv:py25]
deps =
- nose
+ flake8
pycurl>=7.19
requests<0.10.1
mock>=1.0.1

0 comments on commit 116d288

Please sign in to comment.