Merge lp:~brian.curtin/ubuntu-sso-client/py3-StringIO into lp:ubuntu-sso-client
| Status: | Merged | ||||
|---|---|---|---|---|---|
| Approved by: | dobey on 2012-07-06 | ||||
| Approved revision: | 985 | ||||
| Merged at revision: | 983 | ||||
| Proposed branch: | lp:~brian.curtin/ubuntu-sso-client/py3-StringIO | ||||
| Merge into: | lp:ubuntu-sso-client | ||||
| Diff against target: |
54 lines (+6/-5) 3 files modified
ubuntu_sso/qt/setup_account_page.py (+2/-2) ubuntu_sso/utils/tests/test_parse_args.py (+3/-2) ubuntu_sso/utils/webclient/qtnetwork.py (+1/-1) |
||||
| To merge this branch: | bzr merge lp:~brian.curtin/ubuntu-sso-client/py3-StringIO | ||||
| Related bugs: |
|
| Reviewer | Review Type | Date Requested | Status |
|---|---|---|---|
| dobey (community) | Approve on 2012-07-06 | ||
| Alejandro J. Cura (community) | 2012-06-27 | Approve on 2012-07-03 | |
|
Review via email:
|
|||
Commit Message
Import the StringIO class in a Python 2 and 3 way
Description of the Change
Python 3 moved the StringIO class from the StringIO module to the io module. First try to import it from io, then fall back to StringIO.
| Brian Curtin (brian.curtin) wrote : | # |
All of the above changes have this fixed.
| dobey (dobey) wrote : | # |
I think using io.StringIO here is correct even in 2.7, with the try/except. The test error from alecu seems to be that we also need to do from __future__ import unicode_literals as part of the work to port to python3, and it would likely solve the problem in the test; though opens another can of worms which we also need to deal with. Perhaps we can do some of that in this branch?
- 984. By Brian Curtin on 2012-07-02
-
Use StringIO from the io module regardless of version (since it was introduced in 2.6 and that's our minimum version). Additionally use unicode_literals in test_parse_args
| Brian Curtin (brian.curtin) wrote : | # |
Good point. I have other branches that are covering unicode by itself, but moving to always using io.StringIO regardless of version and adding the unicode_literals import to the test seem to solve this.
We can remove the if/else and try/except because if we're only supporting 2.6+ and 3, io.StringIO is always there.
- 985. By Brian Curtin on 2012-07-03
-
Remove sys import

It seems that io.StringIO exists in 2.7, and it's incompatible from StringIO:
----
[ERROR] alecu/canonical /ubuntu- sso-client/ review_ py3-StringIO/ ubuntu_ sso/utils/ tests/test_ parse_args. py", line 97, in test_parse_ args_app_ name_is_ required parse_args( ) alecu/canonical /ubuntu- sso-client/ review_ py3-StringIO/ ubuntu_ sso/utils/ ui.py", line 261, in parse_args python2. 7/argparse. py", line 1688, in parse_args known_args( args, namespace) python2. 7/argparse. py", line 1720, in parse_known_args known_args( args, namespace) python2. 7/argparse. py", line 1944, in _parse_known_args error(_ ('argument %s is required') % name) python2. 7/argparse. py", line 2346, in error print_usage( _sys.stderr) python2. 7/argparse. py", line 2308, in print_usage _print_ message( self.format_ usage() , file) python2. 7/argparse. py", line 2327, in _print_message write(message) TypeError: unicode argument expected, got 'str'
Traceback (most recent call last):
File "/home/
main.
File "/home/
args = parser.parse_args()
File "/usr/lib/
args, argv = self.parse_
File "/usr/lib/
namespace, args = self._parse_
File "/usr/lib/
self.
File "/usr/lib/
self.
File "/usr/lib/
self.
File "/usr/lib/
file.
exceptions.
ubuntu_ sso.utils. tests.test_ parse_args. ParseArgsTestCa se.test_ parse_args_ app_name_ is_required
----
Please make sure to run the tests on 2 after each of these branches.