diff --git a/easywebdav/__version__.py b/easywebdav/__version__.py index c68196d..bc86c94 100644 --- a/easywebdav/__version__.py +++ b/easywebdav/__version__.py @@ -1 +1 @@ -__version__ = "1.2.0" +__version__ = "1.2.2" diff --git a/easywebdav/client.py b/easywebdav/client.py index 4003198..c6e4b81 100644 --- a/easywebdav/client.py +++ b/easywebdav/client.py @@ -1,17 +1,12 @@ +import six import requests -import platform from numbers import Number import xml.etree.cElementTree as xml from collections import namedtuple -py_majversion, py_minversion, py_revversion = platform.python_version_tuple() +from six.moves.urllib_parse import urlparse +from six.moves.http_client import responses as HTTP_CODES -if py_majversion == '2': - from httplib import responses as HTTP_CODES - from urlparse import urlparse -else: - from http.client import responses as HTTP_CODES - from urllib.parse import urlparse DOWNLOAD_CHUNK_SIZE_BYTES = 1 * 1024 * 1024 @@ -150,7 +145,7 @@ def delete(self, path): self._send('DELETE', path, 204) def upload(self, local_path_or_fileobj, remote_path): - if isinstance(local_path_or_fileobj, basestring): + if isinstance(local_path_or_fileobj, six.string_types): with open(local_path_or_fileobj, 'rb') as f: self._upload(f, remote_path) else: @@ -161,7 +156,7 @@ def _upload(self, fileobj, remote_path): def download(self, remote_path, local_path_or_fileobj): response = self._send('GET', remote_path, 200, stream=True) - if isinstance(local_path_or_fileobj, basestring): + if isinstance(local_path_or_fileobj, six.string_types): with open(local_path_or_fileobj, 'wb') as f: self._download(f, response) else: diff --git a/setup.py b/setup.py index a2c8a3c..9233c7b 100644 --- a/setup.py +++ b/setup.py @@ -24,6 +24,7 @@ data_files = [], install_requires=[ "requests", + "six", ], entry_points=dict( console_scripts=[], @@ -36,6 +37,7 @@ "nose", "yanc", "PyWebDAV", + "unittest2", )) setup(**properties) \ No newline at end of file diff --git a/tests/__init__.py b/tests/__init__.py index 44dad4c..7b9ec3d 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,5 +1,5 @@ import os -import unittest +import unittest2 import atexit import subprocess import inspect @@ -14,7 +14,7 @@ SERVER_USERNAME = 'testuser' SERVER_PASSWORD = SERVER_USERNAME SERVER_PORT = 28080 -SERVER_URL = 'http://localhost:{}'.format(SERVER_PORT) +SERVER_URL = 'http://localhost:{0}'.format(SERVER_PORT) _initialized = False _init_failed = False @@ -24,7 +24,7 @@ def init(): global _initialized, _init_failed, _server_process, _server_path, _client if _init_failed: - raise unittest.SkipTest('Test session initialization failed') + raise unittest2.SkipTest('Test session initialization failed') try: if _initialized: return @@ -51,6 +51,7 @@ def init(): stdin=subprocess.PIPE, ) _server_process = subprocess.Popen(**process_props) + output('Start WebDAV with {0}...'.format(process_props)) atexit.register(terminate_server) # Ensure server is running @@ -96,7 +97,7 @@ def output(msg, *args, **kwargs): msg = msg.format(args, kwargs) print(msg) -class TestCase(unittest.TestCase): +class TestCase(unittest2.TestCase): def setUp(self): init() self.client = ClientProxy(self, _client) @@ -174,6 +175,6 @@ def __call__(self, *args, **kwargs): result = self.__method__(*args, **kwargs) cwd_after = self.__client__.cwd self.__test__.assertEqual(cwd_before, cwd_after, - 'CWD has changed during method "{}":\n Before: {}\n After: {}' + 'CWD has changed during method "{0}":\n Before: {1}\n After: {2}' .format(self.__method__.__name__, cwd_before, cwd_after)) return result diff --git a/tests/tests.py b/tests/tests.py index 173f9a6..ced6322 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -1,11 +1,4 @@ -import platform - -python_version, _, __ = platform.python_version_tuple() -if python_version == '2': - from StringIO import StringIO -else: - from io import StringIO - +import six from . import TestCase class Tests(TestCase): @@ -126,9 +119,9 @@ def test__download_absolute(self): self._assert_local_file(path, self.content) def test__download_stream(self): self._create_file('file', self.content) - sio = StringIO() + sio = six.BytesIO() self.client.download('file', sio) - self.assertEqual(self.content, sio.getvalue()) + self.assertEqual(six.b(self.content), sio.getvalue()) def test__upload(self): path = self._local_file(self.content) @@ -146,8 +139,8 @@ def test__upload_nested_absolute(self): self.client.upload(path, '/two/file') self._assert_file('two/file', self.content) def test__upload_stream(self): - sio = StringIO() - sio.write(self.content) + sio = six.BytesIO() + sio.write(six.b(self.content)) sio.seek(0) self.client.upload(sio, 'file') self._assert_file('file', self.content) diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..403ca29 --- /dev/null +++ b/tox.ini @@ -0,0 +1,13 @@ +# Tox (http://tox.testrun.org/) is a tool for running tests +# in multiple virtualenvs. This configuration file will run the +# test suite on all supported python versions. To use it, "pip install tox" +# and then run "tox" from this directory. + +[tox] +envlist = py26, py27, py32, py33, py34, py35 + +[testenv] +commands = nosetests --nologcapture --nocapture tests +deps = nose + PyWebDAV + unittest2