def test_user_dirs_when_no_dirs_file(environ, tmpdir): os.environ['XDG_CONFIG_HOME'] = str(tmpdir) result = xdg.get_dirs() assert 'XDG_MUSIC_DIR' not in result assert 'XDG_DOWNLOAD_DIR' not in result
def test_user_dirs(environ, tmpdir): os.environ['XDG_CONFIG_HOME'] = str(tmpdir) with open(os.path.join(str(tmpdir), 'user-dirs.dirs'), 'wb') as fh: fh.write('# Some comments\n') fh.write('XDG_MUSIC_DIR="$HOME/Music2"\n') result = xdg.get_dirs() assert result['XDG_MUSIC_DIR'] == os.path.expanduser(b'~/Music2') assert 'XDG_DOWNLOAD_DIR' not in result
def test_user_dirs(environ, tmpdir): os.environ["XDG_CONFIG_HOME"] = str(tmpdir) with open(os.path.join(str(tmpdir), "user-dirs.dirs"), "wb") as fh: fh.write(b"# Some comments\n") fh.write(b'XDG_MUSIC_DIR="$HOME/Music2"\n') result = xdg.get_dirs() assert result["XDG_MUSIC_DIR"] == pathlib.Path("~/Music2").expanduser() assert "XDG_DOWNLOAD_DIR" not in result
import logging import os import stat import string import threading import urllib import urlparse from mopidy import compat, exceptions from mopidy.compat import queue from mopidy.internal import encoding, xdg logger = logging.getLogger(__name__) XDG_DIRS = xdg.get_dirs() def get_or_create_dir(dir_path): if not isinstance(dir_path, bytes): raise ValueError('Path is not a bytestring.') dir_path = expand_path(dir_path) if os.path.isfile(dir_path): raise OSError('A file with the same name as the desired dir, ' '"%s", already exists.' % dir_path) elif not os.path.isdir(dir_path): logger.info('Creating dir %s', dir_path) os.makedirs(dir_path, 0o755) return dir_path
def test_cache_dir_from_env(environ): os.environ["XDG_CACHE_HOME"] = "/foo/bar" assert xdg.get_dirs()["XDG_CACHE_DIR"] == pathlib.Path("/foo/bar")
def test_data_dir_from_env(environ): os.environ['XDG_DATA_HOME'] = b'/foo/bar' assert xdg.get_dirs()['XDG_DATA_DIR'] == b'/foo/bar' assert type(xdg.get_dirs()['XDG_DATA_DIR']) == bytes
def test_config_dir_from_env(environ): os.environ['XDG_CONFIG_HOME'] = b'/foo/bar' assert xdg.get_dirs()['XDG_CONFIG_DIR'] == b'/foo/bar' assert type(xdg.get_dirs()['XDG_CONFIG_DIR']) == bytes
def test_cache_dir_from_env(environ): os.environ['XDG_CACHE_HOME'] = b'/foo/bar' assert xdg.get_dirs()['XDG_CACHE_DIR'] == b'/foo/bar' assert type(xdg.get_dirs()['XDG_CACHE_DIR']) == bytes
def test_cache_dir_from_env(environ): os.environ['XDG_CACHE_HOME'] = '/foo/bar' assert xdg.get_dirs()['XDG_CACHE_DIR'] == '/foo/bar'
def test_cache_dir_default(environ): assert xdg.get_dirs()['XDG_CACHE_DIR'] == os.path.expanduser(b'~/.cache')
def test_data_dir_from_env(environ): os.environ["XDG_DATA_HOME"] = "/foo/bar" assert xdg.get_dirs()["XDG_DATA_DIR"] == pathlib.Path("/foo/bar")
def test_data_dir_default(environ): assert xdg.get_dirs()["XDG_DATA_DIR"] == ( pathlib.Path("~/.local/share").expanduser() )
def test_config_dir_from_env(environ): os.environ["XDG_CONFIG_HOME"] = "/foo/bar" assert xdg.get_dirs()["XDG_CONFIG_DIR"] == pathlib.Path("/foo/bar")
def test_config_dir_default(environ): assert xdg.get_dirs()["XDG_CONFIG_DIR"] == ( pathlib.Path("~/.config").expanduser() )
import logging import os import stat import string import threading from mopidy import compat, exceptions from mopidy.compat import queue, urllib from mopidy.internal import encoding, xdg logger = logging.getLogger(__name__) XDG_DIRS = xdg.get_dirs() def get_or_create_dir(dir_path): if not isinstance(dir_path, bytes): raise ValueError('Path is not a bytestring.') dir_path = expand_path(dir_path) if os.path.isfile(dir_path): raise OSError( 'A file with the same name as the desired dir, ' '"%s", already exists.' % dir_path) elif not os.path.isdir(dir_path): logger.info('Creating dir %s', dir_path) os.makedirs(dir_path, 0o755) return dir_path
def test_config_dir_default(environ): assert xdg.get_dirs()['XDG_CONFIG_DIR'] == os.path.expanduser(b'~/.config')
def test_config_dir_from_env(environ): os.environ['XDG_CONFIG_HOME'] = '/foo/bar' assert xdg.get_dirs()['XDG_CONFIG_DIR'] == '/foo/bar'
def test_data_dir_default(environ): assert xdg.get_dirs()['XDG_DATA_DIR'] == os.path.expanduser( b'~/.local/share')
def test_data_dir_from_env(environ): os.environ['XDG_DATA_HOME'] = '/foo/bar' assert xdg.get_dirs()['XDG_DATA_DIR'] == '/foo/bar'
def test_cache_dir_default(environ): assert xdg.get_dirs()["XDG_CACHE_DIR"] == ( pathlib.Path("~/.cache").expanduser() )