Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | dobey | ||||
Approved revision: | 14 | ||||
Merged at revision: | 10 | ||||
Proposed branch: | lp:~dobey/dirspec/python3 | ||||
Merge into: | lp:dirspec | ||||
Diff against target: |
561 lines (+120/-106) 8 files modified
dirspec/basedir.py (+17/-13) dirspec/tests/__init__.py (+24/-3) dirspec/tests/test_basedir.py (+19/-31) dirspec/tests/test_utils.py (+24/-34) dirspec/utils.py (+25/-13) run-tests (+7/-0) run-tests.bat (+2/-10) setup.py (+2/-2) |
||||
To merge this branch: | bzr merge lp:~dobey/dirspec/python3 | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Mike McCracken (community) | Approve | ||
Diego Sarmentero (community) | Approve | ||
Review via email: mp+114713@code.launchpad.net |
Commit message
Port to Python 3
Description of the change
As this adds python3 support, and runs the tests with python3, you'll also need python3-setuptools and python3-testtools installed. There's no python3-testtools in precise, so you'll need to install it from our nightlies PPA, to run the tests.
Diego Sarmentero (diegosarmentero) wrote : | # |
=======
FAIL: test_darwin_pkgd (dirspec.
dirspec.
-------
_StringException: Traceback (most recent call last):
File "x:\dirspec-
self.
MismatchError: !=:
reference = u'x:\\dirspec-
actual = u'x:\\dirspec-
=======
FAIL: test_linux_
dirspec.
-------
_StringException: Traceback (most recent call last):
File "x:\dirspec-
self.
MismatchError: u'/path/
=======
FAIL: test_unfrozen_
dirspec.
-------
_StringException: Traceback (most recent call last):
File "x:\dirspec-
self.
MismatchError: u'/path/
-------
Ran 32 tests in 0.053s
FAILED (failures=3, skipped=2)
Diego Sarmentero (diegosarmentero) wrote : | # |
+1 tests passing on windows, linux, mac
Mike McCracken (mikemc) : | # |
Preview Diff
1 | === modified file 'dirspec/basedir.py' |
2 | --- dirspec/basedir.py 2011-12-19 18:11:14 +0000 |
3 | +++ dirspec/basedir.py 2012-07-13 19:22:21 +0000 |
4 | @@ -1,6 +1,6 @@ |
5 | # -*- coding: utf-8 -*- |
6 | # |
7 | -# Copyright 2011 Canonical Ltd. |
8 | +# Copyright 2011-2012 Canonical Ltd. |
9 | # |
10 | # This program is free software: you can redistribute it and/or modify |
11 | # it under the terms of the GNU Lesser General Public License version 3 |
12 | @@ -15,6 +15,8 @@ |
13 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
14 | """XDG Base Directory paths.""" |
15 | |
16 | +from __future__ import unicode_literals, print_function |
17 | + |
18 | import os |
19 | |
20 | from dirspec.utils import (default_cache_home, |
21 | @@ -53,16 +55,18 @@ |
22 | def get_xdg_config_dirs(): |
23 | """Get the paths for the XDG config directories.""" |
24 | result = [get_xdg_config_home()] |
25 | - result.extend([x for x in get_env_path( |
26 | - 'XDG_CONFIG_DIRS', default_config_path).split(os.pathsep)]) |
27 | + result.extend([x.encode('utf-8') for x in get_env_path( |
28 | + 'XDG_CONFIG_DIRS', |
29 | + default_config_path).decode('utf-8').split(os.pathsep)]) |
30 | return result |
31 | |
32 | |
33 | def get_xdg_data_dirs(): |
34 | """Get the paths for the XDG data directories.""" |
35 | result = [get_xdg_data_home()] |
36 | - result.extend([x for x in get_env_path( |
37 | - 'XDG_DATA_DIRS', default_data_path).split(os.pathsep)]) |
38 | + result.extend([x.encode('utf-8') for x in get_env_path( |
39 | + 'XDG_DATA_DIRS', |
40 | + default_data_path).decode('utf-8').split(os.pathsep)]) |
41 | return result |
42 | |
43 | |
44 | @@ -77,7 +81,7 @@ |
45 | resource = os.path.join(*resource) |
46 | assert not resource.startswith('/') |
47 | for config_dir in get_xdg_config_dirs(): |
48 | - path = os.path.join(config_dir, resource) |
49 | + path = os.path.join(config_dir, resource.encode('utf-8')) |
50 | # access the file system always with unicode |
51 | # to properly behave in some operating systems |
52 | if os.path.exists(unicode_path(path)): |
53 | @@ -94,7 +98,7 @@ |
54 | resource = os.path.join(*resource) |
55 | assert not resource.startswith('/') |
56 | for data_dir in get_xdg_data_dirs(): |
57 | - path = os.path.join(data_dir, resource) |
58 | + path = os.path.join(data_dir, resource.encode('utf-8')) |
59 | # access the file system always with unicode |
60 | # to properly behave in some operating systems |
61 | if os.path.exists(unicode_path(path)): |
62 | @@ -120,11 +124,11 @@ |
63 | """ |
64 | resource = os.path.join(*resource) |
65 | assert not resource.startswith('/') |
66 | - path = os.path.join(get_xdg_config_home(), resource) |
67 | + path = os.path.join(get_xdg_config_home(), resource.encode('utf-8')) |
68 | # access the file system always with unicode |
69 | # to properly behave in some operating systems |
70 | if not os.path.isdir(unicode_path(path)): |
71 | - os.makedirs(unicode_path(path), 0700) |
72 | + os.makedirs(unicode_path(path), 0o700) |
73 | return path |
74 | |
75 | |
76 | @@ -137,11 +141,11 @@ |
77 | """ |
78 | resource = os.path.join(*resource) |
79 | assert not resource.startswith('/') |
80 | - path = os.path.join(get_xdg_data_home(), resource) |
81 | + path = os.path.join(get_xdg_data_home(), resource.encode('utf-8')) |
82 | # access the file system always with unicode |
83 | # to properly behave in some operating systems |
84 | if not os.path.isdir(unicode_path(path)): |
85 | - os.makedirs(unicode_path(path), 0700) |
86 | + os.makedirs(unicode_path(path), 0o700) |
87 | return path |
88 | |
89 | |
90 | @@ -150,6 +154,6 @@ |
91 | xdg_config_home = get_xdg_config_home() |
92 | xdg_data_home = get_xdg_data_home() |
93 | |
94 | -xdg_config_dirs = filter(lambda x: x, get_xdg_config_dirs()) |
95 | -xdg_data_dirs = filter(lambda x: x, get_xdg_data_dirs()) |
96 | +xdg_config_dirs = [x for x in get_xdg_config_dirs() if x] |
97 | +xdg_data_dirs = [x for x in get_xdg_data_dirs() if x] |
98 | # pylint: disable=C0103 |
99 | |
100 | === modified file 'dirspec/tests/__init__.py' |
101 | --- dirspec/tests/__init__.py 2012-07-12 18:13:19 +0000 |
102 | +++ dirspec/tests/__init__.py 2012-07-13 19:22:21 +0000 |
103 | @@ -1,6 +1,6 @@ |
104 | # -*- coding: utf-8 -*- |
105 | # |
106 | -# Copyright 2011 Canonical Ltd. |
107 | +# Copyright 2011-2012 Canonical Ltd. |
108 | # |
109 | # This program is free software: you can redistribute it and/or modify |
110 | # it under the terms of the GNU Lesser General Public License version 3 |
111 | @@ -15,6 +15,11 @@ |
112 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
113 | """"dirspec tests.""" |
114 | |
115 | +from __future__ import unicode_literals, print_function |
116 | + |
117 | +import os |
118 | + |
119 | +from operator import setitem |
120 | from testtools.testcase import TestCase |
121 | |
122 | |
123 | @@ -23,8 +28,24 @@ |
124 | |
125 | def assert_utf8_bytes(self, value): |
126 | """Check that 'value' is a bytes sequence encoded with utf-8.""" |
127 | - self.assertIsInstance(value, str) |
128 | + self.assertIsInstance(value, bytes) |
129 | try: |
130 | value.decode('utf-8') |
131 | - except UnicodeDecodeError: |
132 | + except UnicodeError: |
133 | self.fail('%r should be a utf8 encoded string.' % value) |
134 | + |
135 | + def tweak_env(self, envvar, value): |
136 | + """Tweak the environment variable %var to %value. |
137 | + |
138 | + Restore the old value when finished. |
139 | + """ |
140 | + old_val = os.environ.get(envvar, None) |
141 | + |
142 | + if old_val is None: |
143 | + self.addCleanup(os.environ.pop, envvar, None) |
144 | + else: |
145 | + self.addCleanup(setitem, os.environ, envvar, old_val) |
146 | + if value is None: |
147 | + os.environ.pop(envvar, None) |
148 | + else: |
149 | + os.environ[envvar] = value |
150 | |
151 | === modified file 'dirspec/tests/test_basedir.py' |
152 | --- dirspec/tests/test_basedir.py 2011-12-20 17:53:34 +0000 |
153 | +++ dirspec/tests/test_basedir.py 2012-07-13 19:22:21 +0000 |
154 | @@ -1,6 +1,6 @@ |
155 | # -*- coding: utf-8 -*- |
156 | # |
157 | -# Copyright 2011 Canonical Ltd. |
158 | +# Copyright 2011-2012 Canonical Ltd. |
159 | # |
160 | # This program is free software: you can redistribute it and/or modify |
161 | # it under the terms of the GNU Lesser General Public License version 3 |
162 | @@ -15,37 +15,22 @@ |
163 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
164 | """Tests for the base directory implementation.""" |
165 | |
166 | +from __future__ import unicode_literals, print_function |
167 | + |
168 | import os |
169 | |
170 | from dirspec import basedir |
171 | from dirspec.tests import BaseTestCase |
172 | -from operator import setitem |
173 | |
174 | |
175 | class BasedirTestCase(BaseTestCase): |
176 | """Tests for XDG Base Directory paths implementation.""" |
177 | |
178 | - def tweak_env(self, envvar, value): |
179 | - """Tweak the environment variable %var to %value. |
180 | - |
181 | - Restore the old value when finished. |
182 | - """ |
183 | - old_val = os.environ.get(envvar, None) |
184 | - |
185 | - if old_val is None: |
186 | - self.addCleanup(os.environ.pop, envvar, None) |
187 | - else: |
188 | - self.addCleanup(setitem, os.environ, envvar, old_val) |
189 | - if value is None: |
190 | - os.environ.pop(envvar, None) |
191 | - else: |
192 | - os.environ[envvar] = value |
193 | - |
194 | def test_cache_home(self): |
195 | """Test that XDG_CACHE_HOME is handled correctly.""" |
196 | self.tweak_env('XDG_CACHE_HOME', os.path.abspath(os.path.join( |
197 | os.getcwd(), '_trial_temp', 'cache'))) |
198 | - self.assertEqual(os.environ['XDG_CACHE_HOME'], |
199 | + self.assertEqual(os.environ['XDG_CACHE_HOME'].encode('utf-8'), |
200 | basedir.get_xdg_cache_home()) |
201 | |
202 | def test_config_dirs(self): |
203 | @@ -53,14 +38,15 @@ |
204 | self.tweak_env('XDG_CONFIG_HOME', os.path.abspath(os.path.join( |
205 | os.getcwd(), '_trial_temp', 'config'))) |
206 | self.tweak_env('XDG_CONFIG_DIRS', os.pathsep.join(['etc'])) |
207 | - self.assertEqual([os.environ['XDG_CONFIG_HOME'], 'etc'], |
208 | + self.assertEqual([os.environ['XDG_CONFIG_HOME'].encode('utf-8'), |
209 | + b'etc'], |
210 | basedir.get_xdg_config_dirs()) |
211 | |
212 | def test_config_home(self): |
213 | """Test that XDG_CONFIG_DIRS is handled correctly.""" |
214 | self.tweak_env('XDG_CONFIG_HOME', os.path.abspath(os.path.join( |
215 | os.getcwd(), '_trial_temp', 'config'))) |
216 | - self.assertEqual(os.environ['XDG_CONFIG_HOME'], |
217 | + self.assertEqual(os.environ['XDG_CONFIG_HOME'].encode('utf-8'), |
218 | basedir.get_xdg_config_home()) |
219 | |
220 | def test_data_dirs(self): |
221 | @@ -68,20 +54,21 @@ |
222 | self.tweak_env('XDG_DATA_HOME', os.path.abspath(os.path.join( |
223 | os.getcwd(), '_trial_temp', 'xdg_data'))) |
224 | self.tweak_env('XDG_DATA_DIRS', os.pathsep.join(['foo', 'bar'])) |
225 | - self.assertEqual([os.environ['XDG_DATA_HOME'], 'foo', 'bar'], |
226 | + self.assertEqual([os.environ['XDG_DATA_HOME'].encode('utf-8'), |
227 | + b'foo', b'bar'], |
228 | basedir.get_xdg_data_dirs()) |
229 | |
230 | def test_data_home(self): |
231 | """Test that XDG_DATA_HOME is handled correctly.""" |
232 | self.tweak_env('XDG_DATA_HOME', os.path.abspath(os.path.join( |
233 | os.getcwd(), '_trial_temp', 'xdg_data'))) |
234 | - self.assertEqual(os.environ['XDG_DATA_HOME'], |
235 | + self.assertEqual(os.environ['XDG_DATA_HOME'].encode('utf-8'), |
236 | basedir.get_xdg_data_home()) |
237 | |
238 | def test_default_cache_home(self): |
239 | """Ensure default values work correctly.""" |
240 | self.tweak_env('XDG_CACHE_HOME', None) |
241 | - expected = '/blah' |
242 | + expected = b'/blah' |
243 | self.patch(basedir, 'default_cache_home', expected) |
244 | self.assertFalse(os.environ.get('XDG_CACHE_HOME', False)) |
245 | self.assertEqual(basedir.get_xdg_cache_home(), expected) |
246 | @@ -90,17 +77,17 @@ |
247 | """Ensure default values work correctly.""" |
248 | self.tweak_env('XDG_CONFIG_DIRS', None) |
249 | self.tweak_env('XDG_CONFIG_HOME', None) |
250 | - expected = '/blah' |
251 | + expected = b'/blah' |
252 | self.patch(basedir, 'default_config_home', expected) |
253 | self.patch(basedir, 'default_config_path', '') |
254 | self.assertFalse(os.environ.get('XDG_CONFIG_DIRS', False)) |
255 | self.assertFalse(os.environ.get('XDG_CONFIG_HOME', False)) |
256 | - self.assertEqual(basedir.get_xdg_config_dirs(), [expected, '']) |
257 | + self.assertEqual(basedir.get_xdg_config_dirs(), [expected, b'']) |
258 | |
259 | def test_default_config_home(self): |
260 | """Ensure default values work correctly.""" |
261 | self.tweak_env('XDG_CONFIG_HOME', None) |
262 | - expected = '/blah' |
263 | + expected = b'/blah' |
264 | self.patch(basedir, 'default_config_home', expected) |
265 | self.assertFalse(os.environ.get('XDG_CONFIG_HOME', False)) |
266 | self.assertEqual(basedir.get_xdg_config_home(), expected) |
267 | @@ -109,17 +96,17 @@ |
268 | """Ensure default values work correctly.""" |
269 | self.tweak_env('XDG_DATA_DIRS', None) |
270 | self.tweak_env('XDG_DATA_HOME', None) |
271 | - expected = '/blah' |
272 | + expected = b'/blah' |
273 | self.patch(basedir, 'default_data_home', expected) |
274 | self.patch(basedir, 'default_data_path', '') |
275 | self.assertFalse(os.environ.get('XDG_DATA_DIRS', False)) |
276 | self.assertFalse(os.environ.get('XDG_DATA_HOME', False)) |
277 | - self.assertEqual(basedir.get_xdg_data_dirs(), [expected, '']) |
278 | + self.assertEqual(basedir.get_xdg_data_dirs(), [expected, b'']) |
279 | |
280 | def test_default_data_home(self): |
281 | """Ensure default values work correctly.""" |
282 | self.tweak_env('XDG_DATA_HOME', None) |
283 | - expected = '/blah' |
284 | + expected = b'/blah' |
285 | self.patch(basedir, 'default_data_home', expected) |
286 | self.assertFalse(os.environ.get('XDG_DATA_HOME', False)) |
287 | self.assertEqual(basedir.get_xdg_data_home(), expected) |
288 | @@ -160,4 +147,5 @@ |
289 | self.tweak_env('XDG_CONFIG_HOME', 'config_home') |
290 | self.patch(os, "makedirs", lambda *args: None) |
291 | result = basedir.save_config_path("x") |
292 | - self.assertEqual(result.split(os.sep)[-2:], ['config_home', 'x']) |
293 | + self.assertEqual(result.decode('utf-8').split(os.sep)[-2:], |
294 | + ['config_home', 'x']) |
295 | |
296 | === modified file 'dirspec/tests/test_utils.py' |
297 | --- dirspec/tests/test_utils.py 2012-07-12 19:11:25 +0000 |
298 | +++ dirspec/tests/test_utils.py 2012-07-13 19:22:21 +0000 |
299 | @@ -1,6 +1,6 @@ |
300 | # -*- coding: utf-8 -*- |
301 | # |
302 | -# Copyright 2011 Canonical Ltd. |
303 | +# Copyright 2011-2012 Canonical Ltd. |
304 | # |
305 | # This program is free software: you can redistribute it and/or modify |
306 | # it under the terms of the GNU Lesser General Public License version 3 |
307 | @@ -14,6 +14,9 @@ |
308 | # You should have received a copy of the GNU Lesser General Public License |
309 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
310 | """Tests for utilities for the base directory implementation.""" |
311 | + |
312 | +from __future__ import unicode_literals, print_function |
313 | + |
314 | import os |
315 | import sys |
316 | |
317 | @@ -48,9 +51,9 @@ |
318 | def __init__(self): |
319 | """Set the proper mapping between CSIDL_ consts.""" |
320 | self.values = { |
321 | - 0: u'c:\\path\\to\\users\\home', |
322 | - 1: u'c:\\path\\to\\users\\home\\appData\\local', |
323 | - 2: u'c:\\programData', |
324 | + 0: 'c:\\path\\to\\users\\home', |
325 | + 1: 'c:\\path\\to\\users\\home\\appData\\local', |
326 | + 2: 'c:\\programData', |
327 | } |
328 | |
329 | # pylint: disable=C0103 |
330 | @@ -92,36 +95,23 @@ |
331 | |
332 | for val in special_folders.itervalues(): |
333 | self.assertIsInstance(val, str) |
334 | - val.decode('utf8') |
335 | + val.encode('utf-8') |
336 | |
337 | def test_get_data_dirs(self): |
338 | """Check thet get_data_dirs uses pathsep correctly.""" |
339 | - bad_sep = filter(lambda x: x not in os.pathsep, ":;") |
340 | + bad_sep = str(filter(lambda x: x not in os.pathsep, ":;")) |
341 | dir_list = ["A", "B", bad_sep, "C"] |
342 | - self.patch(os, "environ", |
343 | - dict(XDG_DATA_DIRS=os.pathsep.join( |
344 | - dir_list))) |
345 | + self.tweak_env('XDG_DATA_DIRS', os.pathsep.join(dir_list)) |
346 | dirs = basedir.get_xdg_data_dirs()[1:] |
347 | - self.assertEqual(dirs, dir_list) |
348 | + self.assertEqual(dirs, [x.encode('utf-8') for x in dir_list]) |
349 | |
350 | def test_get_config_dirs(self): |
351 | """Check thet get_data_dirs uses pathsep correctly.""" |
352 | - bad_sep = filter(lambda x: x not in os.pathsep, ":;") |
353 | + bad_sep = str(filter(lambda x: x not in os.pathsep, ":;")) |
354 | dir_list = ["A", "B", bad_sep, "C"] |
355 | - self.patch(os, "environ", |
356 | - dict(XDG_CONFIG_DIRS=os.pathsep.join( |
357 | - dir_list))) |
358 | + self.tweak_env('XDG_CONFIG_DIRS', os.pathsep.join(dir_list)) |
359 | dirs = basedir.get_xdg_config_dirs()[1:] |
360 | - self.assertEqual(dirs, dir_list) |
361 | - |
362 | - def set_fake_environ(self, key, value): |
363 | - """Set (and restore) a fake environ variable.""" |
364 | - if key in os.environ: |
365 | - prev = os.environ[key] |
366 | - self.addCleanup(os.environ.__setitem__, key, prev) |
367 | - else: |
368 | - self.addCleanup(os.environ.__delitem__, key) |
369 | - os.environ[key] = value |
370 | + self.assertEqual(dirs, [x.encode('utf-8') for x in dir_list]) |
371 | |
372 | def unset_fake_environ(self, key): |
373 | """Unset (and restore) a fake environ variable.""" |
374 | @@ -133,19 +123,18 @@ |
375 | @skip('UnicodeEncodeError: bug #907053') |
376 | def test_get_env_path_var(self): |
377 | """Test that get_env_path transforms an env var.""" |
378 | - fake_path = u"C:\\Users\\Ñandú" |
379 | - fake_env_var = "FAKE_ENV_VAR" |
380 | + fake_path = 'C:\\Users\\Ñandú' |
381 | + fake_env_var = 'FAKE_ENV_VAR' |
382 | |
383 | mbcs_path = fake_path.encode(sys.getfilesystemencoding()) |
384 | - utf8_path = fake_path.encode("utf-8") |
385 | |
386 | - self.set_fake_environ(fake_env_var, mbcs_path) |
387 | - self.assertEqual(get_env_path(fake_env_var, "unexpected"), utf8_path) |
388 | + self.tweak_env(fake_env_var, str(mbcs_path)) |
389 | + self.assertEqual(get_env_path(fake_env_var, "unexpected"), fake_path) |
390 | |
391 | @skip('UnicodeEncodeError: bug #907053') |
392 | def test_get_env_path_no_var(self): |
393 | """Test that get_env_path returns the default when env var not set.""" |
394 | - fake_path = u"C:\\Users\\Ñandú" |
395 | + fake_path = "C:\\Users\\Ñandú" |
396 | fake_env_var = "fake_env_var" |
397 | default = fake_path.encode(sys.getfilesystemencoding()) |
398 | |
399 | @@ -172,7 +161,7 @@ |
400 | def test_unfrozen_dev_toplevel(self): |
401 | """Not frozen, return path to bin dir.""" |
402 | path = get_program_path("foo", fallback_dirs=['/path/to/bin']) |
403 | - self.assertEquals(path, "/path/to/bin/foo") |
404 | + self.assertEquals(path, os.path.join("/path/to/bin", "foo")) |
405 | |
406 | def test_unfrozen_dev_toplevel_raises_nopath(self): |
407 | """Not frozen, raise OSError when the path doesn't exist.""" |
408 | @@ -199,9 +188,10 @@ |
409 | def test_darwin_pkgd(self): |
410 | """Return sub-app path on darwin when frozen.""" |
411 | path = get_program_path("foo", app_names=self.darwin_app_names) |
412 | - expectedpath = "%s/%s" % ( |
413 | + expectedpath = "%s%s" % ( |
414 | dirutils.__file__, |
415 | - "Contents/Resources/Foo.app/Contents/MacOS/foo") |
416 | + os.path.sep + os.path.join('Contents', 'Resources', 'Foo.app', |
417 | + 'Contents', 'MacOS', 'foo')) |
418 | self.assertEquals(path, expectedpath) |
419 | |
420 | def test_darwin_pkgd_raises_on_no_appnames(self): |
421 | @@ -257,7 +247,7 @@ |
422 | def test_linux_src_relative_path_exists(self): |
423 | """linux, return source relative path if it exists.""" |
424 | path = get_program_path("foo", fallback_dirs=['/path/to/bin']) |
425 | - expectedpath = "/path/to/bin/foo" |
426 | + expectedpath = os.path.join("/path/to/bin", "foo") |
427 | self.assertEquals(path, expectedpath) |
428 | |
429 | def test_linux_no_src_relative_path(self): |
430 | |
431 | === modified file 'dirspec/utils.py' |
432 | --- dirspec/utils.py 2012-07-10 21:06:40 +0000 |
433 | +++ dirspec/utils.py 2012-07-13 19:22:21 +0000 |
434 | @@ -15,6 +15,8 @@ |
435 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
436 | """Utilities for multiplatform support of XDG directory handling.""" |
437 | |
438 | +from __future__ import unicode_literals, print_function |
439 | + |
440 | import errno |
441 | import os |
442 | import sys |
443 | @@ -104,15 +106,22 @@ |
444 | if key in os.environ: |
445 | # on windows, environment variables are mbcs bytes |
446 | # so we must turn them into utf-8 Syncdaemon paths |
447 | - path = os.environ.get(key) |
448 | - return path.decode(sys.getfilesystemencoding()).encode("utf-8") |
449 | + try: |
450 | + path = os.environb.get(key.encode('utf-8')) |
451 | + except AttributeError: |
452 | + path = os.environ[key] |
453 | + return path.decode(sys.getfilesystemencoding()).encode('utf-8') |
454 | else: |
455 | + if not isinstance(default, bytes): |
456 | + return default.encode('utf-8') |
457 | return default |
458 | |
459 | |
460 | def unicode_path(utf8path): |
461 | - """Turn a UTF-8 path into a unicode path.""" |
462 | - return utf8path.decode("utf-8") |
463 | + """Turn an utf8 path into a unicode path.""" |
464 | + if isinstance(utf8path, bytes): |
465 | + return utf8path.decode("utf-8") |
466 | + return utf8path |
467 | |
468 | |
469 | def get_special_folders(): |
470 | @@ -153,13 +162,16 @@ |
471 | user_home = special_folders['Personal'] |
472 | default_config_path = special_folders['Common AppData'] |
473 | default_config_home = special_folders['Local AppData'] |
474 | - default_data_path = os.path.join(default_config_path, 'xdg') |
475 | - default_data_home = os.path.join(default_config_home, 'xdg') |
476 | - default_cache_home = os.path.join(default_data_home, 'cache') |
477 | + default_data_path = os.path.join(default_config_path, 'bxdg') |
478 | + default_data_home = os.path.join(default_config_home, b'xdg') |
479 | + default_cache_home = os.path.join(default_data_home, b'cache') |
480 | else: |
481 | - user_home = os.path.expanduser('~') |
482 | - default_cache_home = os.path.join(user_home, '.cache') |
483 | - default_config_path = '/etc/xdg' |
484 | - default_config_home = os.path.join(user_home, '.config') |
485 | - default_data_path = '/usr/local/share:/usr/share' |
486 | - default_data_home = os.path.join(user_home, '.local', 'share') |
487 | + user_home = os.path.expanduser(b'~') |
488 | + default_cache_home = os.path.join(user_home, |
489 | + b'.cache') |
490 | + default_config_path = b'/etc/xdg' |
491 | + default_config_home = os.path.join(user_home, |
492 | + b'.config') |
493 | + default_data_path = b'/usr/local/share:/usr/share' |
494 | + default_data_home = os.path.join(user_home, |
495 | + b'.local', b'share') |
496 | |
497 | === modified file 'run-tests' |
498 | --- run-tests 2012-07-12 18:13:19 +0000 |
499 | +++ run-tests 2012-07-13 19:22:21 +0000 |
500 | @@ -19,6 +19,13 @@ |
501 | # Run the tests |
502 | python ./setup.py build test clean |
503 | |
504 | +# Only run the python3 tests if available |
505 | +if [ -x "`which python3`" ]; then |
506 | + python3 ./setup.py build test clean |
507 | +else |
508 | + echo "Python 3 not found. Not running Python 3 tests." |
509 | +fi |
510 | + |
511 | # Run the style checks |
512 | pyflakes dirspec setup.py |
513 | pep8 --repeat . setup.py |
514 | |
515 | === modified file 'run-tests.bat' |
516 | --- run-tests.bat 2011-12-19 18:43:32 +0000 |
517 | +++ run-tests.bat 2012-07-13 19:22:21 +0000 |
518 | @@ -1,6 +1,4 @@ |
519 | -:: Author: Manuel de la Pena <manuel@canonical.com> |
520 | -:: |
521 | -:: Copyright 2010-2011 Canonical Ltd. |
522 | +:: Copyright 2010-2012 Canonical Ltd. |
523 | :: |
524 | :: This program is free software: you can redistribute it and/or modify it |
525 | :: under the terms of the GNU Lesser General Public License version 3, |
526 | @@ -35,20 +33,14 @@ |
527 | ECHO Please ensure you have python installed |
528 | GOTO :END |
529 | |
530 | -:: Using trial.py is different on Windows, so we need to set PYTHONPATH |
531 | -SET PYTHONPATH=. |
532 | - |
533 | :PYTHONPRESENT |
534 | ECHO Python found, executing the tests... |
535 | :: execute the tests with a number of ignored linux only modules |
536 | -"%PYTHONEXECPATH%\python.exe" "%PYTHONEXECPATH%\Scripts\trial.py" dirspec |
537 | +"%PYTHONEXECPATH%\python.exe" setup.py build test clean |
538 | "%PYTHONEXECPATH%\python.exe" "%PYTHONEXECPATH%\Scripts\pyflakes" dirspec |
539 | :: test for style if we can, if pep8 is not present, move to the end |
540 | IF EXIST "%PYTHONEXECPATH%Scripts\pep8.exe" |
541 | "%PYTHONEXECPATH%\Scripts\pep8.exe" --repeat dirspec |
542 | ELSE |
543 | ECHO Style checks were not done |
544 | -:: Delete the temp folders |
545 | -RMDIR /s /q _trial_temp |
546 | -RMDIR /s /q .coverage |
547 | :END |
548 | |
549 | === modified file 'setup.py' |
550 | --- setup.py 2012-07-12 18:13:19 +0000 |
551 | +++ setup.py 2012-07-13 19:22:21 +0000 |
552 | @@ -1,7 +1,7 @@ |
553 | -#!/usr/bin/env python |
554 | +#!/usr/bin/python |
555 | # -*- coding: utf-8 -*- |
556 | # |
557 | -# Copyright 2011 Canonical Ltd. |
558 | +# Copyright 2011-2012 Canonical Ltd. |
559 | # |
560 | # This program is free software: you can redistribute it and/or modify |
561 | # it under the terms of the GNU Lesser General Public License version 3 |
+1 looks good and all the tests are ok