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