Bug 52492 - Test failure with Python 2 and non-English locales
Summary: Test failure with Python 2 and non-English locales
Status: RESOLVED FIXED
Alias: None
Product: PyXDG
Classification: Unclassified
Component: PyXDG (show other bugs)
Version: unspecified
Hardware: Other All
: medium normal
Assignee: Thomas Kluyver
QA Contact:
URL:
Whiteboard:
Keywords:
: 52533 (view as bug list)
Depends on:
Blocks:
 
Reported: 2012-07-25 16:01 UTC by Arfrever Frehtes Taifersar Arahesis
Modified: 2012-07-26 20:25 UTC (History)
1 user (show)

See Also:
i915 platform:
i915 features:


Attachments

Description Arfrever Frehtes Taifersar Arahesis 2012-07-25 16:01:32 UTC
1 test fails with Python 2.6 and 2.7 and non-English locales (e.g. pl_PL.UTF-8 or fr_FR.UTF-8). All tests pass with Python 3.1, 3.2 and 3.3.
I use PyXDG 0.21.

$ nosetests-2.6
............./tmp/pyxdg-0.21/xdg/Menu.py:812: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
  if filename in tmp["mergeFiles"]:
E.......
======================================================================
ERROR: test_parse_menu (test-menu.MenuTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/pyxdg-0.21/test/test-menu.py", line 39, in test_parse_menu
    menu = xdg.Menu.parse(self.test_file)
  File "/tmp/pyxdg-0.21/xdg/Menu.py", line 574, in parse
    sort(tmp["Root"])
  File "/tmp/pyxdg-0.21/xdg/Menu.py", line 937, in sort
    sort(submenu)
  File "/tmp/pyxdg-0.21/xdg/Menu.py", line 964, in sort
    menu.MenuEntries.sort()
  File "/tmp/pyxdg-0.21/xdg/Menu.py", line 490, in __lt__
    return self._key() < other
  File "/tmp/pyxdg-0.21/xdg/Menu.py", line 483, in _key
    return locale.strxfrm(self.DesktopEntry.getName())
UnicodeEncodeError: 'ascii' codec can't encode character u'\u0142' in position 3: ordinal not in range(128)

----------------------------------------------------------------------
Ran 21 tests in 2.443s

FAILED (errors=1)
$ nosetests-2.7
/usr/lib64/python2.7/site-packages/nose/util.py:14: DeprecationWarning: The compiler package is deprecated and removed in Python 3.x.
  from compiler.consts import CO_GENERATOR
............./tmp/pyxdg-0.21/xdg/Menu.py:812: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
  if filename in tmp["mergeFiles"]:
E.......
======================================================================
ERROR: test_parse_menu (test-menu.MenuTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/pyxdg-0.21/test/test-menu.py", line 39, in test_parse_menu
    menu = xdg.Menu.parse(self.test_file)
  File "/tmp/pyxdg-0.21/xdg/Menu.py", line 574, in parse
    sort(tmp["Root"])
  File "/tmp/pyxdg-0.21/xdg/Menu.py", line 937, in sort
    sort(submenu)
  File "/tmp/pyxdg-0.21/xdg/Menu.py", line 964, in sort
    menu.MenuEntries.sort()
  File "/tmp/pyxdg-0.21/xdg/Menu.py", line 490, in __lt__
    return self._key() < other
  File "/tmp/pyxdg-0.21/xdg/Menu.py", line 483, in _key
    return locale.strxfrm(self.DesktopEntry.getName())
UnicodeEncodeError: 'ascii' codec can't encode character u'\u0142' in position 3: ordinal not in range(128)

----------------------------------------------------------------------
Ran 21 tests in 1.960s

FAILED (errors=1)
Comment 1 Thomas Kluyver 2012-07-25 16:50:32 UTC
Thanks for the report. I think the first step will be to try to make a self-contained test case that reproduces the problem for anyone in any locale.
Comment 2 Arfrever Frehtes Taifersar Arahesis 2012-07-25 22:24:44 UTC
Apparently test suite of PyXDG triggers parsing of desktop entries installed in /usr/share/applications.

The following can be used to reproduce this bug in any locale:

$ cat /tmp/test.desktop
[Desktop Entry]
Name=€
$ python2.7 -c 'import xdg.Menu; menu_entry=xdg.Menu.MenuEntry("/tmp/test.desktop"); menu_entry < menu_entry'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib64/python2.7/site-packages/xdg/Menu.py", line 487, in __lt__
    other = other._key()
  File "/usr/lib64/python2.7/site-packages/xdg/Menu.py", line 483, in _key
    return locale.strxfrm(self.DesktopEntry.getName())
UnicodeEncodeError: 'ascii' codec can't encode character u'\u20ac' in position 0: ordinal not in range(128)
$ python3.2 -c 'import xdg.Menu; menu_entry=xdg.Menu.MenuEntry("/tmp/test.desktop"); menu_entry < menu_entry'
$
Comment 3 Thomas Kluyver 2012-07-25 23:03:43 UTC
Great. I've added a test and fixed the issue:

http://cgit.freedesktop.org/xdg/pyxdg/commit/?id=2780bc434aac3817097a5a09b0efd93d2c373a02
Comment 4 Edward Sheldrake 2012-07-26 20:25:32 UTC
*** Bug 52533 has been marked as a duplicate of this bug. ***


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.