Merge lp:~gocept/landscape-client/fix-locale-dependency into lp:~landscape/landscape-client/trunk

Proposed by Steffen Allner
Status: Rejected
Rejected by: Eric Snow
Proposed branch: lp:~gocept/landscape-client/fix-locale-dependency
Merge into: lp:~landscape/landscape-client/trunk
Diff against target: 32 lines (+17/-7)
1 file modified
landscape/package/skeleton.py (+17/-7)
To merge this branch: bzr merge lp:~gocept/landscape-client/fix-locale-dependency
Reviewer Review Type Date Requested Status
Eric Snow (community) Disapprove
🤖 Landscape Builder test results Approve
Gocept Pending
Review via email: mp+321985@code.launchpad.net

Description of the change

This MP tackles the issue of the dependency on a given locale in tests.

With [0] the LC_ALL=C was introduced for the check target in the Makefile to solve a locale dependency with python 2 and Serbian locale.

This turned out later on to complicate things as the file system default encoding is changed with this setting in a way, which is not easily changed from within a python program. Problems arose at the interface with C-extensions which partly had some decoding errors or replaced unknown characters.

The late phenomenon is actually also present in Python 2 and was tested as landscape.package.tests.test_skeleton.test_build_skeleton_with_unicode_and_non_ascii
Comments [1] [2]

This is also the testcase which gets fixed by this MP.

I personally don't like this solution, I would rather like to make a conditional test based on the given locale as this allows to use the feature of direct decoding of non-ascii characters with Python 3 given and UTF-8 supporting locale.

[0] http://bazaar.launchpad.net/~landscape/landscape-client/trunk/files/940
[1] https://code.launchpad.net/~gocept/landscape-client/py3-package-skeleton/+merge/320610/comments/838871
[2] https://code.launchpad.net/~gocept/landscape-client/py3-package-skeleton/+merge/320610/comments/838930

To post a comment you must log in.
Revision history for this message
🤖 Landscape Builder (landscape-builder) :
review: Abstain (executing tests)
Revision history for this message
🤖 Landscape Builder (landscape-builder) wrote :

Command: make ci-check
Result: Success
Revno: 1001
Branch: lp:~gocept/landscape-client/fix-locale-dependency
Jenkins: https://ci.lscape.net/job/latch-test-xenial/3839/

review: Approve (test results)
Revision history for this message
🤖 Landscape Builder (landscape-builder) :
review: Abstain (executing tests)
Revision history for this message
Steffen Allner (sallner) wrote :

Free is fixes this problem with conditional tests in [0], so it is yours to decide. I will close the card on that.

[0] https://code.launchpad.net/~free.ekanayaka/landscape-client/py3-registration/+merge/321986

Revision history for this message
🤖 Landscape Builder (landscape-builder) wrote :

Command: make ci-check
Result: Success
Revno: 1001
Branch: lp:~gocept/landscape-client/fix-locale-dependency
Jenkins: https://ci.lscape.net/job/latch-test-xenial/3841/

review: Approve (test results)
Revision history for this message
Eric Snow (ericsnowcurrently) wrote :

Yeah, let's go with Free's change.

review: Disapprove

Unmerged revisions

1001. By Steffen Allner

Avoid locale dependency in tests.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'landscape/package/skeleton.py'
2--- landscape/package/skeleton.py 2017-03-17 08:56:02 +0000
3+++ landscape/package/skeleton.py 2017-04-05 13:10:32 +0000
4@@ -152,11 +152,21 @@
5 skeleton.size = version.size
6 if version.installed_size > 0:
7 skeleton.installed_size = version.installed_size
8- if with_unicode and not _PY3:
9- skeleton.section = skeleton.section.decode("utf-8")
10- skeleton.summary = skeleton.summary.decode("utf-8")
11- # Avoid double-decoding package descriptions in build_skeleton_apt,
12- # which causes an error with newer python-apt (Xenial onwards)
13- if not isinstance(skeleton.description, unicode):
14- skeleton.description = skeleton.description.decode("utf-8")
15+ if with_unicode:
16+ if not _PY3:
17+ skeleton.section = skeleton.section.decode("utf-8")
18+ skeleton.summary = skeleton.summary.decode("utf-8")
19+ # Avoid double-decoding package descriptions in
20+ # build_skeleton_apt, which causes an error with newer python-
21+ # apt (Xenial onwards)
22+ if not isinstance(skeleton.description, unicode):
23+ skeleton.description = skeleton.description.decode("utf-8")
24+ # XXX This is a fix to keep the output consistent for different
25+ # locales, i.e. LC_ALL=C vs. UTF-8. Tested in
26+ # test_build_skeleton_with_unicode_and_non_ascii(). The replacement
27+ # is done in apt.cache.Cache and cannot be controlled other then
28+ # with FS default encoding. So we need to encode and decode here
29+ # and replace non-ascii characters on the way.
30+ skeleton.description = skeleton.description.encode(
31+ "ascii", "replace").decode("ascii")
32 return skeleton

Subscribers

People subscribed via source and target branches

to all changes: