path: Handle XDG paths as bytes, not unicode
This commit is contained in:
parent
eb18d8d4e3
commit
004fe6dbf8
@ -11,19 +11,15 @@ import urllib
|
||||
|
||||
import glib
|
||||
|
||||
|
||||
logger = logging.getLogger('mopidy.utils.path')
|
||||
|
||||
XDG_CACHE_DIR = glib.get_user_cache_dir().decode('utf-8')
|
||||
XDG_CONFIG_DIR = glib.get_user_config_dir().decode('utf-8')
|
||||
XDG_DATA_DIR = glib.get_user_data_dir().decode('utf-8')
|
||||
XDG_MUSIC_DIR = glib.get_user_special_dir(glib.USER_DIRECTORY_MUSIC)
|
||||
if XDG_MUSIC_DIR:
|
||||
XDG_MUSIC_DIR = XDG_MUSIC_DIR.decode('utf-8')
|
||||
|
||||
XDG_DIRS = {
|
||||
'XDG_CACHE_DIR': XDG_CACHE_DIR,
|
||||
'XDG_CONFIG_DIR': XDG_CONFIG_DIR,
|
||||
'XDG_DATA_DIR': XDG_DATA_DIR,
|
||||
'XDG_MUSIC_DIR': XDG_MUSIC_DIR,
|
||||
'XDG_CACHE_DIR': glib.get_user_cache_dir(),
|
||||
'XDG_CONFIG_DIR': glib.get_user_config_dir(),
|
||||
'XDG_DATA_DIR': glib.get_user_data_dir(),
|
||||
'XDG_MUSIC_DIR': glib.get_user_special_dir(glib.USER_DIRECTORY_MUSIC),
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -201,27 +201,27 @@ class ExpandPathTest(unittest.TestCase):
|
||||
# TODO: test via mocks?
|
||||
|
||||
def test_empty_path(self):
|
||||
self.assertEqual(os.path.abspath('.'), path.expand_path(''))
|
||||
self.assertEqual(os.path.abspath(b'.'), path.expand_path(b''))
|
||||
|
||||
def test_absolute_path(self):
|
||||
self.assertEqual('/tmp/foo', path.expand_path('/tmp/foo'))
|
||||
self.assertEqual(b'/tmp/foo', path.expand_path(b'/tmp/foo'))
|
||||
|
||||
def test_home_dir_expansion(self):
|
||||
self.assertEqual(
|
||||
os.path.expanduser('~/foo'), path.expand_path('~/foo'))
|
||||
os.path.expanduser(b'~/foo'), path.expand_path(b'~/foo'))
|
||||
|
||||
def test_abspath(self):
|
||||
self.assertEqual(os.path.abspath('./foo'), path.expand_path('./foo'))
|
||||
self.assertEqual(os.path.abspath(b'./foo'), path.expand_path(b'./foo'))
|
||||
|
||||
def test_xdg_subsititution(self):
|
||||
self.assertEqual(
|
||||
glib.get_user_data_dir() + '/foo',
|
||||
path.expand_path('$XDG_DATA_DIR/foo'))
|
||||
glib.get_user_data_dir() + b'/foo',
|
||||
path.expand_path(b'$XDG_DATA_DIR/foo'))
|
||||
|
||||
def test_xdg_subsititution_unknown(self):
|
||||
self.assertEqual(
|
||||
'/tmp/$XDG_INVALID_DIR/foo',
|
||||
path.expand_path('/tmp/$XDG_INVALID_DIR/foo'))
|
||||
b'/tmp/$XDG_INVALID_DIR/foo',
|
||||
path.expand_path(b'/tmp/$XDG_INVALID_DIR/foo'))
|
||||
|
||||
|
||||
class FindFilesTest(unittest.TestCase):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user