Merge lp:~dobey/dirspec/python3 into lp:dirspec

Proposed by dobey
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
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.

To post a comment you must log in.
lp:~dobey/dirspec/python3 updated
11. By dobey

Enforce use of bytes for all the paths

Revision history for this message
Diego Sarmentero (diegosarmentero) wrote :

+1 looks good and all the tests are ok

review: Approve
lp:~dobey/dirspec/python3 updated
12. By dobey

Update the run-tests.bat to not use trial, and use setup.py build test clean

13. By dobey

Check for python3 existing before running the tests, for eg OS X

Revision history for this message
Diego Sarmentero (diegosarmentero) wrote :

======================================================================
FAIL: test_darwin_pkgd (dirspec.tests.test_utils.DarwinPkgdTestCase)
dirspec.tests.test_utils.DarwinPkgdTestCase.test_darwin_pkgd
----------------------------------------------------------------------
_StringException: Traceback (most recent call last):
  File "x:\dirspec-dobye\dirspec\tests\test_utils.py", line 194, in test_darwin_pkgd
    self.assertEquals(path, expectedpath)
MismatchError: !=:
reference = u'x:\\dirspec-dobye\\dirspec\\utils.py\\Contents\\Resources\\Foo.app\\Contents\\MacOS\\foo'
actual = u'x:\\dirspec-dobye\\dirspec\\utils.py/Contents/Resources/Foo.app/Contents/MacOS/foo'

======================================================================
FAIL: test_linux_src_relative_path_exists (dirspec.tests.test_utils.PosixTestCase)
dirspec.tests.test_utils.PosixTestCase.test_linux_src_relative_path_exists
----------------------------------------------------------------------
_StringException: Traceback (most recent call last):
  File "x:\dirspec-dobye\dirspec\tests\test_utils.py", line 250, in test_linux_src_relative_path_exists
    self.assertEquals(path, expectedpath)
MismatchError: u'/path/to/bin\\foo' != u'/path/to/bin/foo'

======================================================================
FAIL: test_unfrozen_dev_toplevel (dirspec.tests.test_utils.UnfrozenSrcTestCase)
dirspec.tests.test_utils.UnfrozenSrcTestCase.test_unfrozen_dev_toplevel
----------------------------------------------------------------------
_StringException: Traceback (most recent call last):
  File "x:\dirspec-dobye\dirspec\tests\test_utils.py", line 164, in test_unfrozen_dev_toplevel
    self.assertEquals(path, "/path/to/bin/foo")
MismatchError: u'/path/to/bin\\foo' != u'/path/to/bin/foo'

----------------------------------------------------------------------
Ran 32 tests in 0.053s

FAILED (failures=3, skipped=2)

review: Needs Fixing
lp:~dobey/dirspec/python3 updated
14. By dobey

Fix a few tests on Windows

Revision history for this message
Diego Sarmentero (diegosarmentero) wrote :

+1 tests passing on windows, linux, mac

review: Approve
Revision history for this message
Mike McCracken (mikemc) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'dirspec/basedir.py'
--- dirspec/basedir.py 2011-12-19 18:11:14 +0000
+++ dirspec/basedir.py 2012-07-13 19:22:21 +0000
@@ -1,6 +1,6 @@
1# -*- coding: utf-8 -*-1# -*- coding: utf-8 -*-
2#2#
3# Copyright 2011 Canonical Ltd.3# Copyright 2011-2012 Canonical Ltd.
4#4#
5# This program is free software: you can redistribute it and/or modify5# This program is free software: you can redistribute it and/or modify
6# it under the terms of the GNU Lesser General Public License version 36# it under the terms of the GNU Lesser General Public License version 3
@@ -15,6 +15,8 @@
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/>.
16"""XDG Base Directory paths."""16"""XDG Base Directory paths."""
1717
18from __future__ import unicode_literals, print_function
19
18import os20import os
1921
20from dirspec.utils import (default_cache_home,22from dirspec.utils import (default_cache_home,
@@ -53,16 +55,18 @@
53def get_xdg_config_dirs():55def get_xdg_config_dirs():
54 """Get the paths for the XDG config directories."""56 """Get the paths for the XDG config directories."""
55 result = [get_xdg_config_home()]57 result = [get_xdg_config_home()]
56 result.extend([x for x in get_env_path(58 result.extend([x.encode('utf-8') for x in get_env_path(
57 'XDG_CONFIG_DIRS', default_config_path).split(os.pathsep)])59 'XDG_CONFIG_DIRS',
60 default_config_path).decode('utf-8').split(os.pathsep)])
58 return result61 return result
5962
6063
61def get_xdg_data_dirs():64def get_xdg_data_dirs():
62 """Get the paths for the XDG data directories."""65 """Get the paths for the XDG data directories."""
63 result = [get_xdg_data_home()]66 result = [get_xdg_data_home()]
64 result.extend([x for x in get_env_path(67 result.extend([x.encode('utf-8') for x in get_env_path(
65 'XDG_DATA_DIRS', default_data_path).split(os.pathsep)])68 'XDG_DATA_DIRS',
69 default_data_path).decode('utf-8').split(os.pathsep)])
66 return result70 return result
6771
6872
@@ -77,7 +81,7 @@
77 resource = os.path.join(*resource)81 resource = os.path.join(*resource)
78 assert not resource.startswith('/')82 assert not resource.startswith('/')
79 for config_dir in get_xdg_config_dirs():83 for config_dir in get_xdg_config_dirs():
80 path = os.path.join(config_dir, resource)84 path = os.path.join(config_dir, resource.encode('utf-8'))
81 # access the file system always with unicode85 # access the file system always with unicode
82 # to properly behave in some operating systems86 # to properly behave in some operating systems
83 if os.path.exists(unicode_path(path)):87 if os.path.exists(unicode_path(path)):
@@ -94,7 +98,7 @@
94 resource = os.path.join(*resource)98 resource = os.path.join(*resource)
95 assert not resource.startswith('/')99 assert not resource.startswith('/')
96 for data_dir in get_xdg_data_dirs():100 for data_dir in get_xdg_data_dirs():
97 path = os.path.join(data_dir, resource)101 path = os.path.join(data_dir, resource.encode('utf-8'))
98 # access the file system always with unicode102 # access the file system always with unicode
99 # to properly behave in some operating systems103 # to properly behave in some operating systems
100 if os.path.exists(unicode_path(path)):104 if os.path.exists(unicode_path(path)):
@@ -120,11 +124,11 @@
120 """124 """
121 resource = os.path.join(*resource)125 resource = os.path.join(*resource)
122 assert not resource.startswith('/')126 assert not resource.startswith('/')
123 path = os.path.join(get_xdg_config_home(), resource)127 path = os.path.join(get_xdg_config_home(), resource.encode('utf-8'))
124 # access the file system always with unicode128 # access the file system always with unicode
125 # to properly behave in some operating systems129 # to properly behave in some operating systems
126 if not os.path.isdir(unicode_path(path)):130 if not os.path.isdir(unicode_path(path)):
127 os.makedirs(unicode_path(path), 0700)131 os.makedirs(unicode_path(path), 0o700)
128 return path132 return path
129133
130134
@@ -137,11 +141,11 @@
137 """141 """
138 resource = os.path.join(*resource)142 resource = os.path.join(*resource)
139 assert not resource.startswith('/')143 assert not resource.startswith('/')
140 path = os.path.join(get_xdg_data_home(), resource)144 path = os.path.join(get_xdg_data_home(), resource.encode('utf-8'))
141 # access the file system always with unicode145 # access the file system always with unicode
142 # to properly behave in some operating systems146 # to properly behave in some operating systems
143 if not os.path.isdir(unicode_path(path)):147 if not os.path.isdir(unicode_path(path)):
144 os.makedirs(unicode_path(path), 0700)148 os.makedirs(unicode_path(path), 0o700)
145 return path149 return path
146150
147151
@@ -150,6 +154,6 @@
150xdg_config_home = get_xdg_config_home()154xdg_config_home = get_xdg_config_home()
151xdg_data_home = get_xdg_data_home()155xdg_data_home = get_xdg_data_home()
152156
153xdg_config_dirs = filter(lambda x: x, get_xdg_config_dirs())157xdg_config_dirs = [x for x in get_xdg_config_dirs() if x]
154xdg_data_dirs = filter(lambda x: x, get_xdg_data_dirs())158xdg_data_dirs = [x for x in get_xdg_data_dirs() if x]
155# pylint: disable=C0103159# pylint: disable=C0103
156160
=== modified file 'dirspec/tests/__init__.py'
--- dirspec/tests/__init__.py 2012-07-12 18:13:19 +0000
+++ dirspec/tests/__init__.py 2012-07-13 19:22:21 +0000
@@ -1,6 +1,6 @@
1# -*- coding: utf-8 -*-1# -*- coding: utf-8 -*-
2#2#
3# Copyright 2011 Canonical Ltd.3# Copyright 2011-2012 Canonical Ltd.
4#4#
5# This program is free software: you can redistribute it and/or modify5# This program is free software: you can redistribute it and/or modify
6# it under the terms of the GNU Lesser General Public License version 36# it under the terms of the GNU Lesser General Public License version 3
@@ -15,6 +15,11 @@
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/>.
16""""dirspec tests."""16""""dirspec tests."""
1717
18from __future__ import unicode_literals, print_function
19
20import os
21
22from operator import setitem
18from testtools.testcase import TestCase23from testtools.testcase import TestCase
1924
2025
@@ -23,8 +28,24 @@
2328
24 def assert_utf8_bytes(self, value):29 def assert_utf8_bytes(self, value):
25 """Check that 'value' is a bytes sequence encoded with utf-8."""30 """Check that 'value' is a bytes sequence encoded with utf-8."""
26 self.assertIsInstance(value, str)31 self.assertIsInstance(value, bytes)
27 try:32 try:
28 value.decode('utf-8')33 value.decode('utf-8')
29 except UnicodeDecodeError:34 except UnicodeError:
30 self.fail('%r should be a utf8 encoded string.' % value)35 self.fail('%r should be a utf8 encoded string.' % value)
36
37 def tweak_env(self, envvar, value):
38 """Tweak the environment variable %var to %value.
39
40 Restore the old value when finished.
41 """
42 old_val = os.environ.get(envvar, None)
43
44 if old_val is None:
45 self.addCleanup(os.environ.pop, envvar, None)
46 else:
47 self.addCleanup(setitem, os.environ, envvar, old_val)
48 if value is None:
49 os.environ.pop(envvar, None)
50 else:
51 os.environ[envvar] = value
3152
=== modified file 'dirspec/tests/test_basedir.py'
--- dirspec/tests/test_basedir.py 2011-12-20 17:53:34 +0000
+++ dirspec/tests/test_basedir.py 2012-07-13 19:22:21 +0000
@@ -1,6 +1,6 @@
1# -*- coding: utf-8 -*-1# -*- coding: utf-8 -*-
2#2#
3# Copyright 2011 Canonical Ltd.3# Copyright 2011-2012 Canonical Ltd.
4#4#
5# This program is free software: you can redistribute it and/or modify5# This program is free software: you can redistribute it and/or modify
6# it under the terms of the GNU Lesser General Public License version 36# it under the terms of the GNU Lesser General Public License version 3
@@ -15,37 +15,22 @@
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/>.
16"""Tests for the base directory implementation."""16"""Tests for the base directory implementation."""
1717
18from __future__ import unicode_literals, print_function
19
18import os20import os
1921
20from dirspec import basedir22from dirspec import basedir
21from dirspec.tests import BaseTestCase23from dirspec.tests import BaseTestCase
22from operator import setitem
2324
2425
25class BasedirTestCase(BaseTestCase):26class BasedirTestCase(BaseTestCase):
26 """Tests for XDG Base Directory paths implementation."""27 """Tests for XDG Base Directory paths implementation."""
2728
28 def tweak_env(self, envvar, value):
29 """Tweak the environment variable %var to %value.
30
31 Restore the old value when finished.
32 """
33 old_val = os.environ.get(envvar, None)
34
35 if old_val is None:
36 self.addCleanup(os.environ.pop, envvar, None)
37 else:
38 self.addCleanup(setitem, os.environ, envvar, old_val)
39 if value is None:
40 os.environ.pop(envvar, None)
41 else:
42 os.environ[envvar] = value
43
44 def test_cache_home(self):29 def test_cache_home(self):
45 """Test that XDG_CACHE_HOME is handled correctly."""30 """Test that XDG_CACHE_HOME is handled correctly."""
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(
47 os.getcwd(), '_trial_temp', 'cache')))32 os.getcwd(), '_trial_temp', 'cache')))
48 self.assertEqual(os.environ['XDG_CACHE_HOME'],33 self.assertEqual(os.environ['XDG_CACHE_HOME'].encode('utf-8'),
49 basedir.get_xdg_cache_home())34 basedir.get_xdg_cache_home())
5035
51 def test_config_dirs(self):36 def test_config_dirs(self):
@@ -53,14 +38,15 @@
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(
54 os.getcwd(), '_trial_temp', 'config')))39 os.getcwd(), '_trial_temp', 'config')))
55 self.tweak_env('XDG_CONFIG_DIRS', os.pathsep.join(['etc']))40 self.tweak_env('XDG_CONFIG_DIRS', os.pathsep.join(['etc']))
56 self.assertEqual([os.environ['XDG_CONFIG_HOME'], 'etc'],41 self.assertEqual([os.environ['XDG_CONFIG_HOME'].encode('utf-8'),
42 b'etc'],
57 basedir.get_xdg_config_dirs())43 basedir.get_xdg_config_dirs())
5844
59 def test_config_home(self):45 def test_config_home(self):
60 """Test that XDG_CONFIG_DIRS is handled correctly."""46 """Test that XDG_CONFIG_DIRS is handled correctly."""
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(
62 os.getcwd(), '_trial_temp', 'config')))48 os.getcwd(), '_trial_temp', 'config')))
63 self.assertEqual(os.environ['XDG_CONFIG_HOME'],49 self.assertEqual(os.environ['XDG_CONFIG_HOME'].encode('utf-8'),
64 basedir.get_xdg_config_home())50 basedir.get_xdg_config_home())
6551
66 def test_data_dirs(self):52 def test_data_dirs(self):
@@ -68,20 +54,21 @@
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(
69 os.getcwd(), '_trial_temp', 'xdg_data')))55 os.getcwd(), '_trial_temp', 'xdg_data')))
70 self.tweak_env('XDG_DATA_DIRS', os.pathsep.join(['foo', 'bar']))56 self.tweak_env('XDG_DATA_DIRS', os.pathsep.join(['foo', 'bar']))
71 self.assertEqual([os.environ['XDG_DATA_HOME'], 'foo', 'bar'],57 self.assertEqual([os.environ['XDG_DATA_HOME'].encode('utf-8'),
58 b'foo', b'bar'],
72 basedir.get_xdg_data_dirs())59 basedir.get_xdg_data_dirs())
7360
74 def test_data_home(self):61 def test_data_home(self):
75 """Test that XDG_DATA_HOME is handled correctly."""62 """Test that XDG_DATA_HOME is handled correctly."""
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(
77 os.getcwd(), '_trial_temp', 'xdg_data')))64 os.getcwd(), '_trial_temp', 'xdg_data')))
78 self.assertEqual(os.environ['XDG_DATA_HOME'],65 self.assertEqual(os.environ['XDG_DATA_HOME'].encode('utf-8'),
79 basedir.get_xdg_data_home())66 basedir.get_xdg_data_home())
8067
81 def test_default_cache_home(self):68 def test_default_cache_home(self):
82 """Ensure default values work correctly."""69 """Ensure default values work correctly."""
83 self.tweak_env('XDG_CACHE_HOME', None)70 self.tweak_env('XDG_CACHE_HOME', None)
84 expected = '/blah'71 expected = b'/blah'
85 self.patch(basedir, 'default_cache_home', expected)72 self.patch(basedir, 'default_cache_home', expected)
86 self.assertFalse(os.environ.get('XDG_CACHE_HOME', False))73 self.assertFalse(os.environ.get('XDG_CACHE_HOME', False))
87 self.assertEqual(basedir.get_xdg_cache_home(), expected)74 self.assertEqual(basedir.get_xdg_cache_home(), expected)
@@ -90,17 +77,17 @@
90 """Ensure default values work correctly."""77 """Ensure default values work correctly."""
91 self.tweak_env('XDG_CONFIG_DIRS', None)78 self.tweak_env('XDG_CONFIG_DIRS', None)
92 self.tweak_env('XDG_CONFIG_HOME', None)79 self.tweak_env('XDG_CONFIG_HOME', None)
93 expected = '/blah'80 expected = b'/blah'
94 self.patch(basedir, 'default_config_home', expected)81 self.patch(basedir, 'default_config_home', expected)
95 self.patch(basedir, 'default_config_path', '')82 self.patch(basedir, 'default_config_path', '')
96 self.assertFalse(os.environ.get('XDG_CONFIG_DIRS', False))83 self.assertFalse(os.environ.get('XDG_CONFIG_DIRS', False))
97 self.assertFalse(os.environ.get('XDG_CONFIG_HOME', False))84 self.assertFalse(os.environ.get('XDG_CONFIG_HOME', False))
98 self.assertEqual(basedir.get_xdg_config_dirs(), [expected, ''])85 self.assertEqual(basedir.get_xdg_config_dirs(), [expected, b''])
9986
100 def test_default_config_home(self):87 def test_default_config_home(self):
101 """Ensure default values work correctly."""88 """Ensure default values work correctly."""
102 self.tweak_env('XDG_CONFIG_HOME', None)89 self.tweak_env('XDG_CONFIG_HOME', None)
103 expected = '/blah'90 expected = b'/blah'
104 self.patch(basedir, 'default_config_home', expected)91 self.patch(basedir, 'default_config_home', expected)
105 self.assertFalse(os.environ.get('XDG_CONFIG_HOME', False))92 self.assertFalse(os.environ.get('XDG_CONFIG_HOME', False))
106 self.assertEqual(basedir.get_xdg_config_home(), expected)93 self.assertEqual(basedir.get_xdg_config_home(), expected)
@@ -109,17 +96,17 @@
109 """Ensure default values work correctly."""96 """Ensure default values work correctly."""
110 self.tweak_env('XDG_DATA_DIRS', None)97 self.tweak_env('XDG_DATA_DIRS', None)
111 self.tweak_env('XDG_DATA_HOME', None)98 self.tweak_env('XDG_DATA_HOME', None)
112 expected = '/blah'99 expected = b'/blah'
113 self.patch(basedir, 'default_data_home', expected)100 self.patch(basedir, 'default_data_home', expected)
114 self.patch(basedir, 'default_data_path', '')101 self.patch(basedir, 'default_data_path', '')
115 self.assertFalse(os.environ.get('XDG_DATA_DIRS', False))102 self.assertFalse(os.environ.get('XDG_DATA_DIRS', False))
116 self.assertFalse(os.environ.get('XDG_DATA_HOME', False))103 self.assertFalse(os.environ.get('XDG_DATA_HOME', False))
117 self.assertEqual(basedir.get_xdg_data_dirs(), [expected, ''])104 self.assertEqual(basedir.get_xdg_data_dirs(), [expected, b''])
118105
119 def test_default_data_home(self):106 def test_default_data_home(self):
120 """Ensure default values work correctly."""107 """Ensure default values work correctly."""
121 self.tweak_env('XDG_DATA_HOME', None)108 self.tweak_env('XDG_DATA_HOME', None)
122 expected = '/blah'109 expected = b'/blah'
123 self.patch(basedir, 'default_data_home', expected)110 self.patch(basedir, 'default_data_home', expected)
124 self.assertFalse(os.environ.get('XDG_DATA_HOME', False))111 self.assertFalse(os.environ.get('XDG_DATA_HOME', False))
125 self.assertEqual(basedir.get_xdg_data_home(), expected)112 self.assertEqual(basedir.get_xdg_data_home(), expected)
@@ -160,4 +147,5 @@
160 self.tweak_env('XDG_CONFIG_HOME', 'config_home')147 self.tweak_env('XDG_CONFIG_HOME', 'config_home')
161 self.patch(os, "makedirs", lambda *args: None)148 self.patch(os, "makedirs", lambda *args: None)
162 result = basedir.save_config_path("x")149 result = basedir.save_config_path("x")
163 self.assertEqual(result.split(os.sep)[-2:], ['config_home', 'x'])150 self.assertEqual(result.decode('utf-8').split(os.sep)[-2:],
151 ['config_home', 'x'])
164152
=== modified file 'dirspec/tests/test_utils.py'
--- dirspec/tests/test_utils.py 2012-07-12 19:11:25 +0000
+++ dirspec/tests/test_utils.py 2012-07-13 19:22:21 +0000
@@ -1,6 +1,6 @@
1# -*- coding: utf-8 -*-1# -*- coding: utf-8 -*-
2#2#
3# Copyright 2011 Canonical Ltd.3# Copyright 2011-2012 Canonical Ltd.
4#4#
5# This program is free software: you can redistribute it and/or modify5# This program is free software: you can redistribute it and/or modify
6# it under the terms of the GNU Lesser General Public License version 36# it under the terms of the GNU Lesser General Public License version 3
@@ -14,6 +14,9 @@
14# You should have received a copy of the GNU Lesser General Public License14# You should have received a copy of the GNU Lesser General Public License
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/>.
16"""Tests for utilities for the base directory implementation."""16"""Tests for utilities for the base directory implementation."""
17
18from __future__ import unicode_literals, print_function
19
17import os20import os
18import sys21import sys
1922
@@ -48,9 +51,9 @@
48 def __init__(self):51 def __init__(self):
49 """Set the proper mapping between CSIDL_ consts."""52 """Set the proper mapping between CSIDL_ consts."""
50 self.values = {53 self.values = {
51 0: u'c:\\path\\to\\users\\home',54 0: 'c:\\path\\to\\users\\home',
52 1: u'c:\\path\\to\\users\\home\\appData\\local',55 1: 'c:\\path\\to\\users\\home\\appData\\local',
53 2: u'c:\\programData',56 2: 'c:\\programData',
54 }57 }
5558
56 # pylint: disable=C010359 # pylint: disable=C0103
@@ -92,36 +95,23 @@
9295
93 for val in special_folders.itervalues():96 for val in special_folders.itervalues():
94 self.assertIsInstance(val, str)97 self.assertIsInstance(val, str)
95 val.decode('utf8')98 val.encode('utf-8')
9699
97 def test_get_data_dirs(self):100 def test_get_data_dirs(self):
98 """Check thet get_data_dirs uses pathsep correctly."""101 """Check thet get_data_dirs uses pathsep correctly."""
99 bad_sep = filter(lambda x: x not in os.pathsep, ":;")102 bad_sep = str(filter(lambda x: x not in os.pathsep, ":;"))
100 dir_list = ["A", "B", bad_sep, "C"]103 dir_list = ["A", "B", bad_sep, "C"]
101 self.patch(os, "environ",104 self.tweak_env('XDG_DATA_DIRS', os.pathsep.join(dir_list))
102 dict(XDG_DATA_DIRS=os.pathsep.join(
103 dir_list)))
104 dirs = basedir.get_xdg_data_dirs()[1:]105 dirs = basedir.get_xdg_data_dirs()[1:]
105 self.assertEqual(dirs, dir_list)106 self.assertEqual(dirs, [x.encode('utf-8') for x in dir_list])
106107
107 def test_get_config_dirs(self):108 def test_get_config_dirs(self):
108 """Check thet get_data_dirs uses pathsep correctly."""109 """Check thet get_data_dirs uses pathsep correctly."""
109 bad_sep = filter(lambda x: x not in os.pathsep, ":;")110 bad_sep = str(filter(lambda x: x not in os.pathsep, ":;"))
110 dir_list = ["A", "B", bad_sep, "C"]111 dir_list = ["A", "B", bad_sep, "C"]
111 self.patch(os, "environ",112 self.tweak_env('XDG_CONFIG_DIRS', os.pathsep.join(dir_list))
112 dict(XDG_CONFIG_DIRS=os.pathsep.join(
113 dir_list)))
114 dirs = basedir.get_xdg_config_dirs()[1:]113 dirs = basedir.get_xdg_config_dirs()[1:]
115 self.assertEqual(dirs, dir_list)114 self.assertEqual(dirs, [x.encode('utf-8') for x in dir_list])
116
117 def set_fake_environ(self, key, value):
118 """Set (and restore) a fake environ variable."""
119 if key in os.environ:
120 prev = os.environ[key]
121 self.addCleanup(os.environ.__setitem__, key, prev)
122 else:
123 self.addCleanup(os.environ.__delitem__, key)
124 os.environ[key] = value
125115
126 def unset_fake_environ(self, key):116 def unset_fake_environ(self, key):
127 """Unset (and restore) a fake environ variable."""117 """Unset (and restore) a fake environ variable."""
@@ -133,19 +123,18 @@
133 @skip('UnicodeEncodeError: bug #907053')123 @skip('UnicodeEncodeError: bug #907053')
134 def test_get_env_path_var(self):124 def test_get_env_path_var(self):
135 """Test that get_env_path transforms an env var."""125 """Test that get_env_path transforms an env var."""
136 fake_path = u"C:\\Users\\Ñandú"126 fake_path = 'C:\\Users\\Ñandú'
137 fake_env_var = "FAKE_ENV_VAR"127 fake_env_var = 'FAKE_ENV_VAR'
138128
139 mbcs_path = fake_path.encode(sys.getfilesystemencoding())129 mbcs_path = fake_path.encode(sys.getfilesystemencoding())
140 utf8_path = fake_path.encode("utf-8")
141130
142 self.set_fake_environ(fake_env_var, mbcs_path)131 self.tweak_env(fake_env_var, str(mbcs_path))
143 self.assertEqual(get_env_path(fake_env_var, "unexpected"), utf8_path)132 self.assertEqual(get_env_path(fake_env_var, "unexpected"), fake_path)
144133
145 @skip('UnicodeEncodeError: bug #907053')134 @skip('UnicodeEncodeError: bug #907053')
146 def test_get_env_path_no_var(self):135 def test_get_env_path_no_var(self):
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."""
148 fake_path = u"C:\\Users\\Ñandú"137 fake_path = "C:\\Users\\Ñandú"
149 fake_env_var = "fake_env_var"138 fake_env_var = "fake_env_var"
150 default = fake_path.encode(sys.getfilesystemencoding())139 default = fake_path.encode(sys.getfilesystemencoding())
151140
@@ -172,7 +161,7 @@
172 def test_unfrozen_dev_toplevel(self):161 def test_unfrozen_dev_toplevel(self):
173 """Not frozen, return path to bin dir."""162 """Not frozen, return path to bin dir."""
174 path = get_program_path("foo", fallback_dirs=['/path/to/bin'])163 path = get_program_path("foo", fallback_dirs=['/path/to/bin'])
175 self.assertEquals(path, "/path/to/bin/foo")164 self.assertEquals(path, os.path.join("/path/to/bin", "foo"))
176165
177 def test_unfrozen_dev_toplevel_raises_nopath(self):166 def test_unfrozen_dev_toplevel_raises_nopath(self):
178 """Not frozen, raise OSError when the path doesn't exist."""167 """Not frozen, raise OSError when the path doesn't exist."""
@@ -199,9 +188,10 @@
199 def test_darwin_pkgd(self):188 def test_darwin_pkgd(self):
200 """Return sub-app path on darwin when frozen."""189 """Return sub-app path on darwin when frozen."""
201 path = get_program_path("foo", app_names=self.darwin_app_names)190 path = get_program_path("foo", app_names=self.darwin_app_names)
202 expectedpath = "%s/%s" % (191 expectedpath = "%s%s" % (
203 dirutils.__file__,192 dirutils.__file__,
204 "Contents/Resources/Foo.app/Contents/MacOS/foo")193 os.path.sep + os.path.join('Contents', 'Resources', 'Foo.app',
194 'Contents', 'MacOS', 'foo'))
205 self.assertEquals(path, expectedpath)195 self.assertEquals(path, expectedpath)
206196
207 def test_darwin_pkgd_raises_on_no_appnames(self):197 def test_darwin_pkgd_raises_on_no_appnames(self):
@@ -257,7 +247,7 @@
257 def test_linux_src_relative_path_exists(self):247 def test_linux_src_relative_path_exists(self):
258 """linux, return source relative path if it exists."""248 """linux, return source relative path if it exists."""
259 path = get_program_path("foo", fallback_dirs=['/path/to/bin'])249 path = get_program_path("foo", fallback_dirs=['/path/to/bin'])
260 expectedpath = "/path/to/bin/foo"250 expectedpath = os.path.join("/path/to/bin", "foo")
261 self.assertEquals(path, expectedpath)251 self.assertEquals(path, expectedpath)
262252
263 def test_linux_no_src_relative_path(self):253 def test_linux_no_src_relative_path(self):
264254
=== modified file 'dirspec/utils.py'
--- dirspec/utils.py 2012-07-10 21:06:40 +0000
+++ dirspec/utils.py 2012-07-13 19:22:21 +0000
@@ -15,6 +15,8 @@
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/>.
16"""Utilities for multiplatform support of XDG directory handling."""16"""Utilities for multiplatform support of XDG directory handling."""
1717
18from __future__ import unicode_literals, print_function
19
18import errno20import errno
19import os21import os
20import sys22import sys
@@ -104,15 +106,22 @@
104 if key in os.environ:106 if key in os.environ:
105 # on windows, environment variables are mbcs bytes107 # on windows, environment variables are mbcs bytes
106 # so we must turn them into utf-8 Syncdaemon paths108 # so we must turn them into utf-8 Syncdaemon paths
107 path = os.environ.get(key)109 try:
108 return path.decode(sys.getfilesystemencoding()).encode("utf-8")110 path = os.environb.get(key.encode('utf-8'))
111 except AttributeError:
112 path = os.environ[key]
113 return path.decode(sys.getfilesystemencoding()).encode('utf-8')
109 else:114 else:
115 if not isinstance(default, bytes):
116 return default.encode('utf-8')
110 return default117 return default
111118
112119
113def unicode_path(utf8path):120def unicode_path(utf8path):
114 """Turn a UTF-8 path into a unicode path."""121 """Turn an utf8 path into a unicode path."""
115 return utf8path.decode("utf-8")122 if isinstance(utf8path, bytes):
123 return utf8path.decode("utf-8")
124 return utf8path
116125
117126
118def get_special_folders():127def get_special_folders():
@@ -153,13 +162,16 @@
153 user_home = special_folders['Personal']162 user_home = special_folders['Personal']
154 default_config_path = special_folders['Common AppData']163 default_config_path = special_folders['Common AppData']
155 default_config_home = special_folders['Local AppData']164 default_config_home = special_folders['Local AppData']
156 default_data_path = os.path.join(default_config_path, 'xdg')165 default_data_path = os.path.join(default_config_path, 'bxdg')
157 default_data_home = os.path.join(default_config_home, 'xdg')166 default_data_home = os.path.join(default_config_home, b'xdg')
158 default_cache_home = os.path.join(default_data_home, 'cache')167 default_cache_home = os.path.join(default_data_home, b'cache')
159else:168else:
160 user_home = os.path.expanduser('~')169 user_home = os.path.expanduser(b'~')
161 default_cache_home = os.path.join(user_home, '.cache')170 default_cache_home = os.path.join(user_home,
162 default_config_path = '/etc/xdg'171 b'.cache')
163 default_config_home = os.path.join(user_home, '.config')172 default_config_path = b'/etc/xdg'
164 default_data_path = '/usr/local/share:/usr/share'173 default_config_home = os.path.join(user_home,
165 default_data_home = os.path.join(user_home, '.local', 'share')174 b'.config')
175 default_data_path = b'/usr/local/share:/usr/share'
176 default_data_home = os.path.join(user_home,
177 b'.local', b'share')
166178
=== modified file 'run-tests'
--- run-tests 2012-07-12 18:13:19 +0000
+++ run-tests 2012-07-13 19:22:21 +0000
@@ -19,6 +19,13 @@
19# Run the tests19# Run the tests
20python ./setup.py build test clean20python ./setup.py build test clean
2121
22# Only run the python3 tests if available
23if [ -x "`which python3`" ]; then
24 python3 ./setup.py build test clean
25else
26 echo "Python 3 not found. Not running Python 3 tests."
27fi
28
22# Run the style checks29# Run the style checks
23pyflakes dirspec setup.py30pyflakes dirspec setup.py
24pep8 --repeat . setup.py31pep8 --repeat . setup.py
2532
=== modified file 'run-tests.bat'
--- run-tests.bat 2011-12-19 18:43:32 +0000
+++ run-tests.bat 2012-07-13 19:22:21 +0000
@@ -1,6 +1,4 @@
1:: Author: Manuel de la Pena <manuel@canonical.com>1:: Copyright 2010-2012 Canonical Ltd.
2::
3:: Copyright 2010-2011 Canonical Ltd.
4::2::
5:: This program is free software: you can redistribute it and/or modify it3:: This program is free software: you can redistribute it and/or modify it
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,
@@ -35,20 +33,14 @@
35ECHO Please ensure you have python installed33ECHO Please ensure you have python installed
36GOTO :END34GOTO :END
3735
38:: Using trial.py is different on Windows, so we need to set PYTHONPATH
39SET PYTHONPATH=.
40
41:PYTHONPRESENT36:PYTHONPRESENT
42ECHO Python found, executing the tests...37ECHO Python found, executing the tests...
43:: execute the tests with a number of ignored linux only modules38:: execute the tests with a number of ignored linux only modules
44"%PYTHONEXECPATH%\python.exe" "%PYTHONEXECPATH%\Scripts\trial.py" dirspec39"%PYTHONEXECPATH%\python.exe" setup.py build test clean
45"%PYTHONEXECPATH%\python.exe" "%PYTHONEXECPATH%\Scripts\pyflakes" dirspec40"%PYTHONEXECPATH%\python.exe" "%PYTHONEXECPATH%\Scripts\pyflakes" dirspec
46:: test for style if we can, if pep8 is not present, move to the end41:: test for style if we can, if pep8 is not present, move to the end
47IF EXIST "%PYTHONEXECPATH%Scripts\pep8.exe"42IF EXIST "%PYTHONEXECPATH%Scripts\pep8.exe"
48"%PYTHONEXECPATH%\Scripts\pep8.exe" --repeat dirspec43"%PYTHONEXECPATH%\Scripts\pep8.exe" --repeat dirspec
49ELSE44ELSE
50ECHO Style checks were not done45ECHO Style checks were not done
51:: Delete the temp folders
52RMDIR /s /q _trial_temp
53RMDIR /s /q .coverage
54:END46:END
5547
=== modified file 'setup.py'
--- setup.py 2012-07-12 18:13:19 +0000
+++ setup.py 2012-07-13 19:22:21 +0000
@@ -1,7 +1,7 @@
1#!/usr/bin/env python1#!/usr/bin/python
2# -*- coding: utf-8 -*-2# -*- coding: utf-8 -*-
3#3#
4# Copyright 2011 Canonical Ltd.4# Copyright 2011-2012 Canonical Ltd.
5#5#
6# This program is free software: you can redistribute it and/or modify6# This program is free software: you can redistribute it and/or modify
7# it under the terms of the GNU Lesser General Public License version 37# it under the terms of the GNU Lesser General Public License version 3

Subscribers

People subscribed via source and target branches

to all changes: