add test code for multibyte string#530
Conversation
|
@ros-pull-request-builder retest this please |
the built was failed due to time out. |
| Req = StringStringRequest | ||
|
|
||
| for name in [STRING_CAT_SERVICE_NAKED, STRING_CAT_SERVICE_WRAPPED]: | ||
| if sys.version < '3': |
There was a problem hiding this comment.
This is a very fragile way to check the major Python version. Please use sys.version_info.major for a numeric comparison.
There was a problem hiding this comment.
I'm not sure the version check is even required. The u prefix syntax is valid in both Python 2 and 3. In 2, it produces a unicode, and in 3, a str. So I think the first block would be adequate for both versions.
There was a problem hiding this comment.
@dirk-thomas changed to use sys.version_info.major
@mikepurvis as far as I remember, interpreting unicode has been changed between python 2 vs python 3
- http://lucumr.pocoo.org/2014/1/5/unicode-in-2-and-3/
- https://docs.python.org/3/howto/unicode.html#python-s-unicode-support
- https://docs.python.org/2/howto/unicode.html#python-2-x-s-unicode-support
k-okada@p40-yoga:/tmp/ros_comm/test/test_rospy/test/rostest$ python
Python 2.7.6 (default, Oct 26 2016, 20:30:19)
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> u'オープンソース' == 'オープンソース'
__main__:1: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them\
as being unequal
False
and
k-okada@p40-yoga:~$ python3
Python 3.4.3 (default, Nov 17 2016, 01:08:31)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> u'オープンソース' == 'オープンソース'
True
There was a problem hiding this comment.
Right, but look at what happens in the two cases:
if sys.version_info.major < '3':
# Python 2, returns a <unicode>.
resp_req = self._test(name, Cls, Req(String(u'ロボット'), Val(u'机器人')))
else:
# Python 3, returns a <str>.
resp_req = self._test(name, Cls, Req(String('ロボット'), Val('机器人')))
But you can use the u prefix in both, so the following can replace the above:
# Returns <unicode> in Python 2, <str> in Python 3.
resp_req = self._test(name, Cls, Req(String(u'ロボット'), Val(u'机器人')))
c05c3dc to
859cf64
Compare
|
@ros-pull-request-builder retest this please |
|
Closing in favour of #985. |
I'm not sure if this is what you expected, In python, unicode data is transferred to str data.