[liblouis-liblouisxml] Re: Python2.7 and 3.2 compatible runharness file
- From: Michael Whapples <mwhapples@xxxxxxx>
- To: liblouis-liblouisxml@xxxxxxxxxxxxx
- Date: Wed, 16 May 2012 21:03:29 +0100
Possibly I do have ideas, however I am not certain how natural they will
feel.
For input I guess you could define the strings as bytes and use the
decode function, for example
b'Hello world!'.decode("UTF-8")
The above works for both python2.7 and python3. I haven't tried it on
python2.6 though. This I feel might be satisfactory although not
necessarily the most natural way if you were to support python3 or
python2 only.
To resolve the issue with python2 using u'xxx' notation for unicode and
python3 using 'xxx' notation in results, you could use print for the
result (remember use print as a function IE. print(variable) as python3
won't get print variable notation). However this might not work if the
result has a non-printing character in it but might be shorter to write
than the next option.
Again, going back to what I suggested for input, we could use a similar
approach to that for output. If doing that we then must use comparison
rather than relying on doctest testing the output. As an example:
result == b',hello _w6'.decode("UTF-8")
True
If python2.7 is fine as a minimum supported version (or if python2.6
supports the b'xxx' notation then python2.6 as minimum) the
b'xxx'.decode("UTF-8") system seems to be reasonable to me.
I don't know whether there is a way of defining a helper function for a
doctest to reduce the overhead of continually using decode and
comparing, I guess if needed one can define such a function at the top
of each doctest file but it would be good/neater if it could
automatically be included.
Michael Whapples
On 16/05/2012 08:39, Christian Egli wrote:
Michael Whapples<mwhapples@xxxxxxx> writes:
It is just the doctests which need to be made to work with python3.
Do you have an idea how this can be done so that the same test works for
both Python 2 and Python 3?
Thanks
Christian
For a description of the software, to download it and links to
project pages go to http://www.abilitiessoft.com
Other related posts: