dstufft/slumber — pull request #73 by dupuy (2013-07-03 05:34:27+00:00)
Title: Python 2.6 and 3.x support fixes and enhanced versions testing

This pull request is mostly a superset of [Bernardo Heynemann](https://github.com/heynemann)'s PR https://github.com/dstufft/slumber/pull/70 (I omitted the last two commits in that PR as they seemed off-topic, worthwhile as they might otherwise be).

In addition to his fixes for 2.6 and py3k bugs, using the excellent ``six`` compatibility library, I enhanced the testing setup for slumber, updating the ``.travis.yml`` configuration to add testing for all the Python versions (except 2.5) that it supports, and as you can see from the [Travis report](https://travis-ci.org/dupuy/slumber/builds/8684058) on this PR, all tests are passing on all those versions. I also made some tweaks to the ``tox.ini`` he created, so that it doesn't install tox itself (and all of its dependencies) in the virtualenvs that it creates for testing slumber on different Python versions, and so that it tests Python 3.1 if available (Travis no longer supports Python 3.1, so it's commented out in ``.travis.yml``).

I also fixed some other Py3K issues that I ran into while using slumber (before I saw his PR). In particular:

* Use of ``iteritems()`` method in several places was not compatible with py3k; I used ``six.iteritems()`` function, which is defined appropriately for Python 2 or 3.
* The url_join() function did not properly concatenate path components passed as bytes in py3k - they would be formatted as ``/b'url-path-comp'/`` rather than as ``/url-path-comp/``. Passing them as bytearray made it worse, as they would then be formatted as ``/bytearray(b'url-path-comp')/``! There were also some latent issues with encoding compatibility and mixing Unicode and bytes, where urlsplit or urlunsplit could raise ``UnicodeDecodeError`` exceptions, and other cases where users could pass in bytes data with incompatible encodings that would not raise exceptions.

For the second issue, I added several cases to the test suite for url_join, including checks that ``TypeError`` exceptions are raised for potentially incompatibly encoded data passed to url_join (if you need non-ASCII data in the extra arguments, you need to pass them (and the base URL) as Unicode, not bytes).

In @merwok's comment on PR #70, issue https://github.com/dstufft/slumber/issues/56 is mentioned, specifically the possibility of syncing ``tox.ini`` and ``.travis.yml`` using the panci tool. I installed panci and ran it against those files in this PR, but I found the output to be somewhat inferior to the versions of those files in this PR; the resulting files lose functionality and/or cause test failures, and I didn't feel like fixing panci too.

```diff
--- .travis.yml 2013-06-05 02:16:45 -0400
+++ tox-to-travis.yml 2013-07-03 01:16:43 -0400
@@ -1,13 +1,14 @@
language: python
python:
- - 2.6
- - 2.7
- # 3.1 # Travis no longer supports Python 3.1
- - 3.2
- - 3.3
+- '2.6'
+- '2.7'
+- '3.1'
+- '3.2'
+- '3.3'
- pypy
-install:
- - pip install -r requirements.txt && pip install -r requirements-test.txt
- - case `python -V 2>&1` in *2.6*) pip install unittest2;; esac
-script:
- - python setup.py test
+script: '
+
+ pip install -r requirements.txt
+
+ python setup.py test'
+
```
```diff
--- tox.ini 2013-07-03 00:32:56 -0400
+++ travis-to-tox.ini 2013-07-03 01:16:52 -0400
@@ -4,16 +4,11 @@
# and then run "tox" from this directory.

[tox]
-envlist = py26, py27, py31, py32, py33, pypy
+envlist = py26, py27, py32, py33, pypy

[testenv]
commands =
- pip install -r requirements.txt
+ pip install -r requirements.txt && pip install -r requirements-test.txt
+ case `python -V 2>&1` in *2.6*) pip install unittest2;; esac
python setup.py test
-deps =
- mock

-[testenv:py26]
-deps =
- mock
- unittest2
```

If you really want to generate one from the other, generate ``tox.ini`` from ``.travis.yml`` since the only lost functionality is Python 3.1 testing, and the useless installation of tox and its dependencies inside the virtualenvs for testing slumber (which I fixed in d534651) is annoying but harmless, and I don't think you'll get any test failures.