Merge lp:~gz/bzr/fix_win32utils_deprecations into lp:bzr

Proposed by Martin Packman
Status: Merged
Approved by: Vincent Ladeuil
Approved revision: no longer in the source branch.
Merged at revision: 6394
Proposed branch: lp:~gz/bzr/fix_win32utils_deprecations
Merge into: lp:bzr
Diff against target: 107 lines (+53/-6)
2 files modified
bzrlib/tests/test_win32utils.py (+46/-0)
bzrlib/win32utils.py (+7/-6)
To merge this branch: bzr merge lp:~gz/bzr/fix_win32utils_deprecations
Reviewer Review Type Date Requested Status
bzr-core Pending
Review via email: mp+86213@code.launchpad.net

Commit message

Fix deprecations of win32utils path function unicode wrappers

Description of the change

Fix screwup of deprecation of unicode wrapper methods^Wfunctions in earlier branch. Also adds tests and makes sort-of testable on nix, as I'd actually fixed the mistake but lost it in a shelve dance and didn't realised as these code paths are only exercised on windows.

Changing the fallback method is annoying but unimportant. With Python 2.6 as a minumum version, ctypes should never be unavailable, and get_user_encoding will, unless messed with, return the python equivalent encoding of the GetACP return.

To post a comment you must log in.
Revision history for this message
Martin Packman (gz) wrote :

sent to pqm by email

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bzrlib/tests/test_win32utils.py'
2--- bzrlib/tests/test_win32utils.py 2011-12-05 12:50:21 +0000
3+++ bzrlib/tests/test_win32utils.py 2011-12-19 10:47:31 +0000
4@@ -20,6 +20,7 @@
5
6 from bzrlib import (
7 osutils,
8+ symbol_versioning,
9 tests,
10 win32utils,
11 )
12@@ -187,6 +188,51 @@
13 self.assertEquals('not-existing', p)
14
15
16+class TestLocations(TestCase):
17+ """Tests for windows specific path and name retrieving functions"""
18+
19+ def test__ensure_unicode_deprecated(self):
20+ s = "text"
21+ u1 = self.applyDeprecated(symbol_versioning.deprecated_in((2, 5, 0)),
22+ win32utils._ensure_unicode, s)
23+ self.assertEqual(s, u1)
24+ self.assertIsInstance(u1, unicode)
25+ u2 = self.applyDeprecated(symbol_versioning.deprecated_in((2, 5, 0)),
26+ win32utils._ensure_unicode, u1)
27+ self.assertIs(u1, u2)
28+
29+ def test_appdata_unicode_deprecated(self):
30+ self.overrideEnv("APPDATA", "fakepath")
31+ s = win32utils.get_appdata_location()
32+ u = self.applyDeprecated(symbol_versioning.deprecated_in((2, 5, 0)),
33+ win32utils.get_appdata_location_unicode)
34+ self.assertEqual(s, u)
35+ self.assertIsInstance(s, unicode)
36+
37+ def test_home_unicode_deprecated(self):
38+ s = win32utils.get_home_location()
39+ u = self.applyDeprecated(symbol_versioning.deprecated_in((2, 5, 0)),
40+ win32utils.get_home_location_unicode)
41+ self.assertEqual(s, u)
42+ self.assertIsInstance(s, unicode)
43+
44+ def test_user_unicode_deprecated(self):
45+ self.overrideEnv("USERNAME", "alien")
46+ s = win32utils.get_user_name()
47+ u = self.applyDeprecated(symbol_versioning.deprecated_in((2, 5, 0)),
48+ win32utils.get_user_name_unicode)
49+ self.assertEqual(s, u)
50+ self.assertIsInstance(s, unicode)
51+
52+ def test_host_unicode_deprecated(self):
53+ self.overrideEnv("COMPUTERNAME", "alienbox")
54+ s = win32utils.get_host_name()
55+ u = self.applyDeprecated(symbol_versioning.deprecated_in((2, 5, 0)),
56+ win32utils.get_host_name_unicode)
57+ self.assertEqual(s, u)
58+ self.assertIsInstance(s, unicode)
59+
60+
61 class TestLocationsCtypes(TestCase):
62
63 _test_needs_features = [CtypesFeature]
64
65=== modified file 'bzrlib/win32utils.py'
66--- bzrlib/win32utils.py 2011-12-14 18:27:44 +0000
67+++ bzrlib/win32utils.py 2011-12-19 10:47:31 +0000
68@@ -370,7 +370,7 @@
69 return get_environ_unicode('COMPUTERNAME')
70
71
72-@symbol_versioning.deprecated_method(
73+@symbol_versioning.deprecated_function(
74 symbol_versioning.deprecated_in((2, 5, 0)))
75 def _ensure_unicode(s):
76 if s and type(s) != unicode:
77@@ -379,16 +379,16 @@
78 return s
79
80
81-get_appdata_location_unicode = symbol_versioning.deprecated_method(
82+get_appdata_location_unicode = symbol_versioning.deprecated_function(
83 symbol_versioning.deprecated_in((2, 5, 0)))(get_appdata_location)
84
85-get_home_location_unicode = symbol_versioning.deprecated_method(
86+get_home_location_unicode = symbol_versioning.deprecated_function(
87 symbol_versioning.deprecated_in((2, 5, 0)))(get_home_location)
88
89-get_user_name_unicode = symbol_versioning.deprecated_method(
90+get_user_name_unicode = symbol_versioning.deprecated_function(
91 symbol_versioning.deprecated_in((2, 5, 0)))(get_user_name)
92
93-get_host_name_unicode = symbol_versioning.deprecated_method(
94+get_host_name_unicode = symbol_versioning.deprecated_function(
95 symbol_versioning.deprecated_in((2, 5, 0)))(get_host_name)
96
97
98@@ -592,8 +592,9 @@
99
100 Fallback version that should basically never be needed.
101 """
102+ from bzrlib import osutils
103 try:
104- return os.environ[key].decode("mbcs")
105+ return os.environ[key].decode(osutils.get_user_encoding())
106 except KeyError:
107 return default
108