Skip to content

Commit

Permalink
Test read_xdg_config_home
Browse files Browse the repository at this point in the history
  • Loading branch information
akaIDIOT committed Feb 21, 2018
1 parent b8a1597 commit 439af88
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion tests/test_io.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from os import path
from unittest.mock import call, patch

from confidence import Configuration, load, load_name, loadf, loads, NotConfigured, read_envvar_file, read_envvars
from confidence import Configuration, load, load_name, loadf, loads, NotConfigured, read_envvar_file, read_envvars, read_xdg_config_home


test_files = path.join(path.dirname(__file__), 'files')
Expand Down Expand Up @@ -148,6 +148,46 @@ def test_load_name_order():
], any_order=False)


def test_load_name_xdg_config_home():
env = {
'XDG_CONFIG_HOME': '/home/user/.not-config',
'HOME': '/home/user'
}

with patch('confidence.path') as mocked, patch('confidence.environ', env):
# 'unmock' path.join
mocked.join.side_effect = path.join
# avoid actually opening files that might unexpectedly exist
mocked.exists.return_value = False

assert len(load_name('foo', 'bar', load_order=(read_xdg_config_home,))) == 0

mocked.exists.assert_has_calls([
call('/home/user/.not-config/foo.yaml'),
call('/home/user/.not-config/bar.yaml'),
], any_order=False)


def test_load_name_xdg_config_home_fallback():
env = {
'HOME': '/home/user'
}

with patch('confidence.path') as mocked_path, patch('confidence.loadf') as mocked_loadf, patch('confidence.environ', env):
# 'unmock' path.join
mocked_path.join.side_effect = path.join
# avoid actually opening files that might unexpectedly exist
mocked_path.exists.return_value = True
mocked_loadf.return_value = NotConfigured

assert len(load_name('foo', 'bar', load_order=(read_xdg_config_home,))) == 0

mocked_loadf.assert_has_calls([
call('/home/user/.config/foo.yaml'),
call('/home/user/.config/bar.yaml'),
], any_order=False)


def test_load_name_envvars():
env = {
'FOO_KEY': 'foo',
Expand Down

0 comments on commit 439af88

Please sign in to comment.