sensiblecodeio / data-services-helpers

Python module containing classes and functions that The Sensible Code Company's Data Services often used
https://sensiblecode.io/
BSD 2-Clause "Simplified" License
4 stars 4 forks source link

Python3 compatible #27

Closed StevenMaude closed 9 years ago

StevenMaude commented 9 years ago

Tests now pass on my Python 2.7 and Python 3.4 virtualenvs.

Couple of issues:

  1. In 64d4e30, is there a nice way to convert the exception message to unicode for Python 2.7 and Python 3.4. At the moment, it'll be a string for Python 2.7, while in Python 3.4 it's unicode; doesn't affect the tests, but would be nice to be consistent.
  2. Not sure why dfe8e49 is needed: on Python 2.7, tests run in 0.03 s with or without adding @patch('time.sleep'), but in my Python 3.4 setup, the tests take 2 s (as if it's actually doing a time.sleep after doing a request, even though the request should be mocked out to give a 200 response).

Comments welcome :)

scraperdragon commented 9 years ago

1. To force something to unicode in Py2 without losing Py3 functionality, I'd tend to override unicode:

unicode = type(u'')

However, in this case, it'll do the right thing in both cases: it'll have a byte string on both sides of the equation in Py2 and a unicode string on both sides of the equation in Py3.

2. I'd try pressing Ctrl-C during the delay in the tests, see where you break it.

Otherwise looks good to me.

StevenMaude commented 9 years ago
  1. Using from __future__ import unicode_literals so I suspect that it's implicitly comparing the byte string with the Unicode literal and finding a match in Python 2.7.
  2. The reason for the test duration difference is _HIT_PERIOD; this value almost entirely governs the time taken for tests in Python 3.4 (plus the little bit to actually run the tests). Still don't understand why though.

(Incidentally, Ctrl+C doesn't help there, if you press it before the test completes, nosetests bails out early reporting the test results up to that point, without telling you at what stage the code was at.)

StevenMaude commented 9 years ago

(For the record, the Travis checks had passed, only we didn't wait for them to repeat on the small change of rebasing to change the version number from 1.0.5 to 1.1.0.)