diff --git a/.travis.yml b/.travis.yml index 8411c02..91ebf1d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,7 +17,9 @@ env: - TEST_LIST_SLUG=team - TEST_LIST_OWNER_SCREEN_NAME=twitterapi - ACCESS_TOKEN_B64=U2FsdGVkX18QdBhvMNshM4PGy04tU3HLwKP+nNSoNZHKsvGLjELcWEXN2LIu/T+yngX1vGONf9lo14ElnfS4k7sfhiru8phR4+rZuBVP3bDvC2A6fXJuhuLqNhBrWqg32WQewvxLWDWBoKmnvRHg5b74GHh+IN/12tU0cBF2HK8= -install: pip install -r requirements.txt +install: + - pip install -r requirements.txt + - if [[ $TRAVIS_PYTHON_VERSION == '2.6' ]]; then pip install unittest2; fi script: nosetests -v -w tests/ --logging-filter="twython" --with-cov --cov twython --cov-config .coveragerc --cov-report term-missing notifications: email: false diff --git a/tests/config.py b/tests/config.py index 4e8895e..d26b6e1 100644 --- a/tests/config.py +++ b/tests/config.py @@ -1,5 +1,11 @@ import os +import sys +if sys.version_info[0] == 2 and sys.version_info[1] == 6: + import unittest2 as unittest +else: + import unittest + app_key = os.environ.get('APP_KEY') app_secret = os.environ.get('APP_SECRET') oauth_token = os.environ.get('OAUTH_TOKEN') diff --git a/tests/test_auth.py b/tests/test_auth.py index 3b2a713..7de4160 100644 --- a/tests/test_auth.py +++ b/tests/test_auth.py @@ -1,8 +1,6 @@ from twython import Twython, TwythonError, TwythonAuthError -from .config import app_key, app_secret, screen_name - -import unittest +from .config import app_key, app_secret, screen_name, unittest class TwythonAuthTestCase(unittest.TestCase): diff --git a/tests/test_core.py b/tests/test_core.py index 17d1fce..be22925 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -1,21 +1,17 @@ from twython import Twython, TwythonError, TwythonAuthError from .config import ( - test_tweet_object, test_tweet_html + test_tweet_object, test_tweet_html, unittest ) -try: - import unittest2 as unittest -except ImportError: - import unittest - import responses import requests -try: - import io.StringIO as StringIO -except ImportError: - import StringIO +from twython.compat import is_py2 +if is_py2: + from StringIO import StringIO +else: + from io import StringIO try: import unittest.mock as mock @@ -141,7 +137,7 @@ def test_request_should_handle_file_as_parameter(self): url = self.get_url(endpoint) responses.add(responses.POST, url) - mock_file = StringIO.StringIO("Twython test image") + mock_file = StringIO("Twython test image") self.api.request(endpoint, method='POST', params={'image': mock_file}) self.assertIn('filename="image"', responses.calls[0].request.body) diff --git a/tests/test_endpoints.py b/tests/test_endpoints.py index edeacfa..6204a57 100644 --- a/tests/test_endpoints.py +++ b/tests/test_endpoints.py @@ -4,11 +4,10 @@ app_key, app_secret, oauth_token, oauth_token_secret, protected_twitter_1, protected_twitter_2, screen_name, test_tweet_id, test_list_slug, test_list_owner_screen_name, - access_token, test_tweet_object, test_tweet_html + access_token, test_tweet_object, test_tweet_html, unittest ) import time -import unittest class TwythonEndpointsTestCase(unittest.TestCase): diff --git a/tests/test_streaming.py b/tests/test_streaming.py index d0cf20a..9db7059 100644 --- a/tests/test_streaming.py +++ b/tests/test_streaming.py @@ -1,11 +1,9 @@ from twython import TwythonStreamer, TwythonStreamError from .config import ( - app_key, app_secret, oauth_token, oauth_token_secret + app_key, app_secret, oauth_token, oauth_token_secret, unittest ) -import unittest - class TwythonStreamTestCase(unittest.TestCase): def setUp(self):