def test_ensure_directory(tmpdir): directory = tmpdir.join('directory') assert not directory.check(dir=True) util.ensure_directory(str(directory)) assert directory.check(dir=True) # check that invocation on an existing directory doesn't fail with EEXIST util.ensure_directory(str(directory))
def test_ensure_directory_no_perms(tmpdir): """ Test, that other exceptions than EEXIST are handed up to the caller """ tmpdir.chmod(550) directory = tmpdir.join('directory') with pytest.raises(EnvironmentError) as excinfo: util.ensure_directory(str(directory)) assert excinfo.value.filename == str(directory) assert excinfo.value.errno == errno.EACCES
def get_configuration_directory(): """ Get the configuration directory of synaptiks according to the `XDG base directory specification`_ as string. The directory is guaranteed to exist. The configuration directory is a sub-directory of ``$XDG_CONFIG_HOME`` (which defaults to ``$HOME/.config``). Raise :exc:`~exceptions.EnvironmentError`, if the creation of the configuration directory fails. .. _`XDG base directory specification`: http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html """ xdg_config_home = os.environ.get('XDG_CONFIG_HOME') if not xdg_config_home: xdg_config_home = os.path.expandvars(os.path.join('$HOME', '.config')) return ensure_directory(os.path.join(xdg_config_home, 'synaptiks'))