Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compatibility with Python 2.6 and Python 3.5, introduce tox to the project #52

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion easywebdav/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.2.0"
__version__ = "1.2.2"
15 changes: 5 additions & 10 deletions easywebdav/client.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
data_files = [],
install_requires=[
"requests",
"six",
],
entry_points=dict(
console_scripts=[],
Expand All @@ -36,6 +37,7 @@
"nose",
"yanc",
"PyWebDAV",
"unittest2",
))

setup(**properties)
11 changes: 6 additions & 5 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
import unittest
import unittest2
import atexit
import subprocess
import inspect
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
17 changes: 5 additions & 12 deletions tests/tests.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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)
Expand All @@ -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)
13 changes: 13 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -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