Improve tests to use XDG* variables
Instead of overriding YADM_DIR via -Y, set the XDG* environment variables.
This commit is contained in:
parent
fc66b6b71b
commit
8efe2c8fad
5 changed files with 83 additions and 39 deletions
|
@ -180,6 +180,10 @@ class Runner():
|
||||||
self.command = ' '.join([str(cmd) for cmd in command])
|
self.command = ' '.join([str(cmd) for cmd in command])
|
||||||
else:
|
else:
|
||||||
self.command = command
|
self.command = command
|
||||||
|
if env is None:
|
||||||
|
env = {}
|
||||||
|
merged_env = os.environ.copy()
|
||||||
|
merged_env.update(env)
|
||||||
self.inp = inp
|
self.inp = inp
|
||||||
self.wrap(expect)
|
self.wrap(expect)
|
||||||
process = Popen(
|
process = Popen(
|
||||||
|
@ -189,7 +193,7 @@ class Runner():
|
||||||
stderr=PIPE,
|
stderr=PIPE,
|
||||||
shell=shell,
|
shell=shell,
|
||||||
cwd=cwd,
|
cwd=cwd,
|
||||||
env=env,
|
env=merged_env,
|
||||||
)
|
)
|
||||||
input_bytes = self.inp
|
input_bytes = self.inp
|
||||||
if self.inp:
|
if self.inp:
|
||||||
|
@ -280,13 +284,17 @@ def yadm():
|
||||||
@pytest.fixture()
|
@pytest.fixture()
|
||||||
def paths(tmpdir, yadm):
|
def paths(tmpdir, yadm):
|
||||||
"""Function scoped test paths"""
|
"""Function scoped test paths"""
|
||||||
|
|
||||||
dir_root = tmpdir.mkdir('root')
|
dir_root = tmpdir.mkdir('root')
|
||||||
dir_work = dir_root.mkdir('work')
|
|
||||||
dir_yadm = dir_root.mkdir('yadm')
|
|
||||||
dir_repo = dir_yadm.mkdir('repo.git')
|
|
||||||
dir_hooks = dir_yadm.mkdir('hooks')
|
|
||||||
dir_remote = dir_root.mkdir('remote')
|
dir_remote = dir_root.mkdir('remote')
|
||||||
file_archive = dir_yadm.join('archive')
|
dir_work = dir_root.mkdir('work')
|
||||||
|
dir_xdg_data = dir_root.mkdir('xdg_data')
|
||||||
|
dir_xdg_home = dir_root.mkdir('xdg_home')
|
||||||
|
dir_data = dir_xdg_data.mkdir('yadm')
|
||||||
|
dir_yadm = dir_xdg_home.mkdir('yadm')
|
||||||
|
dir_hooks = dir_yadm.mkdir('hooks')
|
||||||
|
dir_repo = dir_data.mkdir('repo.git')
|
||||||
|
file_archive = dir_data.join('archive')
|
||||||
file_bootstrap = dir_yadm.join('bootstrap')
|
file_bootstrap = dir_yadm.join('bootstrap')
|
||||||
file_config = dir_yadm.join('config')
|
file_config = dir_yadm.join('config')
|
||||||
file_encrypt = dir_yadm.join('encrypt')
|
file_encrypt = dir_yadm.join('encrypt')
|
||||||
|
@ -294,24 +302,32 @@ def paths(tmpdir, yadm):
|
||||||
'Paths', [
|
'Paths', [
|
||||||
'pgm',
|
'pgm',
|
||||||
'root',
|
'root',
|
||||||
'work',
|
|
||||||
'yadm',
|
|
||||||
'repo',
|
|
||||||
'hooks',
|
|
||||||
'remote',
|
'remote',
|
||||||
|
'work',
|
||||||
|
'xdg_data',
|
||||||
|
'xdg_home',
|
||||||
|
'data',
|
||||||
|
'yadm',
|
||||||
|
'hooks',
|
||||||
|
'repo',
|
||||||
'archive',
|
'archive',
|
||||||
'bootstrap',
|
'bootstrap',
|
||||||
'config',
|
'config',
|
||||||
'encrypt',
|
'encrypt',
|
||||||
])
|
])
|
||||||
|
os.environ['XDG_CONFIG_HOME'] = str(dir_xdg_home)
|
||||||
|
os.environ['XDG_DATA_HOME'] = str(dir_xdg_data)
|
||||||
return paths(
|
return paths(
|
||||||
yadm,
|
yadm,
|
||||||
dir_root,
|
dir_root,
|
||||||
dir_work,
|
|
||||||
dir_yadm,
|
|
||||||
dir_repo,
|
|
||||||
dir_hooks,
|
|
||||||
dir_remote,
|
dir_remote,
|
||||||
|
dir_work,
|
||||||
|
dir_xdg_data,
|
||||||
|
dir_xdg_home,
|
||||||
|
dir_data,
|
||||||
|
dir_yadm,
|
||||||
|
dir_hooks,
|
||||||
|
dir_repo,
|
||||||
file_archive,
|
file_archive,
|
||||||
file_bootstrap,
|
file_bootstrap,
|
||||||
file_config,
|
file_config,
|
||||||
|
@ -324,7 +340,7 @@ def yadm_y(paths):
|
||||||
"""Generate custom command_list function"""
|
"""Generate custom command_list function"""
|
||||||
def command_list(*args):
|
def command_list(*args):
|
||||||
"""Produce params for running yadm with -Y"""
|
"""Produce params for running yadm with -Y"""
|
||||||
return [paths.pgm, '-Y', str(paths.yadm)] + list(args)
|
return [paths.pgm] + list(args)
|
||||||
return command_list
|
return command_list
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -22,12 +22,12 @@ def test_alt_source(
|
||||||
tracked, encrypt, exclude,
|
tracked, encrypt, exclude,
|
||||||
yadm_alt):
|
yadm_alt):
|
||||||
"""Test yadm alt operates on all expected sources of alternates"""
|
"""Test yadm alt operates on all expected sources of alternates"""
|
||||||
yadm_dir = setup_standard_yadm_dir(paths)
|
yadm_dir, yadm_data = setup_standard_yadm_dir(paths)
|
||||||
|
|
||||||
utils.create_alt_files(
|
utils.create_alt_files(
|
||||||
paths, '##default', tracked=tracked, encrypt=encrypt, exclude=exclude,
|
paths, '##default', tracked=tracked, encrypt=encrypt, exclude=exclude,
|
||||||
yadm_alt=yadm_alt, yadm_dir=yadm_dir)
|
yadm_alt=yadm_alt, yadm_dir=yadm_dir)
|
||||||
run = runner([paths.pgm, '-Y', yadm_dir, 'alt'])
|
run = runner([paths.pgm, '-Y', yadm_dir, '--yadm-data', yadm_data, 'alt'])
|
||||||
assert run.success
|
assert run.success
|
||||||
assert run.err == ''
|
assert run.err == ''
|
||||||
linked = utils.parse_alt_output(run.out)
|
linked = utils.parse_alt_output(run.out)
|
||||||
|
@ -57,12 +57,12 @@ def test_alt_source(
|
||||||
@pytest.mark.parametrize('yadm_alt', [True, False], ids=['alt', 'worktree'])
|
@pytest.mark.parametrize('yadm_alt', [True, False], ids=['alt', 'worktree'])
|
||||||
def test_relative_link(runner, paths, yadm_alt):
|
def test_relative_link(runner, paths, yadm_alt):
|
||||||
"""Confirm links created are relative"""
|
"""Confirm links created are relative"""
|
||||||
yadm_dir = setup_standard_yadm_dir(paths)
|
yadm_dir, yadm_data = setup_standard_yadm_dir(paths)
|
||||||
|
|
||||||
utils.create_alt_files(
|
utils.create_alt_files(
|
||||||
paths, '##default', tracked=True, encrypt=False, exclude=False,
|
paths, '##default', tracked=True, encrypt=False, exclude=False,
|
||||||
yadm_alt=yadm_alt, yadm_dir=yadm_dir)
|
yadm_alt=yadm_alt, yadm_dir=yadm_dir)
|
||||||
run = runner([paths.pgm, '-Y', yadm_dir, 'alt'])
|
run = runner([paths.pgm, '-Y', yadm_dir, '--yadm-data', yadm_data, 'alt'])
|
||||||
assert run.success
|
assert run.success
|
||||||
assert run.err == ''
|
assert run.err == ''
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ def test_alt_conditions(
|
||||||
runner, paths,
|
runner, paths,
|
||||||
tst_sys, tst_distro, tst_host, tst_user, suffix):
|
tst_sys, tst_distro, tst_host, tst_user, suffix):
|
||||||
"""Test conditions supported by yadm alt"""
|
"""Test conditions supported by yadm alt"""
|
||||||
yadm_dir = setup_standard_yadm_dir(paths)
|
yadm_dir, yadm_data = setup_standard_yadm_dir(paths)
|
||||||
|
|
||||||
# set the class
|
# set the class
|
||||||
tst_class = 'testclass'
|
tst_class = 'testclass'
|
||||||
|
@ -106,7 +106,7 @@ def test_alt_conditions(
|
||||||
)
|
)
|
||||||
|
|
||||||
utils.create_alt_files(paths, suffix)
|
utils.create_alt_files(paths, suffix)
|
||||||
run = runner([paths.pgm, '-Y', yadm_dir, 'alt'])
|
run = runner([paths.pgm, '-Y', yadm_dir, '--yadm-data', yadm_data, 'alt'])
|
||||||
assert run.success
|
assert run.success
|
||||||
assert run.err == ''
|
assert run.err == ''
|
||||||
linked = utils.parse_alt_output(run.out)
|
linked = utils.parse_alt_output(run.out)
|
||||||
|
@ -131,13 +131,13 @@ def test_alt_conditions(
|
||||||
def test_alt_templates(
|
def test_alt_templates(
|
||||||
runner, paths, kind, label):
|
runner, paths, kind, label):
|
||||||
"""Test templates supported by yadm alt"""
|
"""Test templates supported by yadm alt"""
|
||||||
yadm_dir = setup_standard_yadm_dir(paths)
|
yadm_dir, yadm_data = setup_standard_yadm_dir(paths)
|
||||||
|
|
||||||
suffix = f'##{label}.{kind}'
|
suffix = f'##{label}.{kind}'
|
||||||
if kind is None:
|
if kind is None:
|
||||||
suffix = f'##{label}'
|
suffix = f'##{label}'
|
||||||
utils.create_alt_files(paths, suffix)
|
utils.create_alt_files(paths, suffix)
|
||||||
run = runner([paths.pgm, '-Y', yadm_dir, 'alt'])
|
run = runner([paths.pgm, '-Y', yadm_dir, '--yadm-data', yadm_data, 'alt'])
|
||||||
assert run.success
|
assert run.success
|
||||||
assert run.err == ''
|
assert run.err == ''
|
||||||
created = utils.parse_alt_output(run.out, linked=False)
|
created = utils.parse_alt_output(run.out, linked=False)
|
||||||
|
@ -265,12 +265,13 @@ def test_template_overwrite_symlink(runner, yadm_y, paths, tst_sys):
|
||||||
@pytest.mark.parametrize('style', ['symlink', 'template'])
|
@pytest.mark.parametrize('style', ['symlink', 'template'])
|
||||||
def test_ensure_alt_path(runner, paths, style):
|
def test_ensure_alt_path(runner, paths, style):
|
||||||
"""Test that directories are created before making alternates"""
|
"""Test that directories are created before making alternates"""
|
||||||
yadm_dir = setup_standard_yadm_dir(paths)
|
yadm_dir, yadm_data = setup_standard_yadm_dir(paths)
|
||||||
suffix = 'default' if style == 'symlink' else 'template'
|
suffix = 'default' if style == 'symlink' else 'template'
|
||||||
filename = 'a/b/c/file'
|
filename = 'a/b/c/file'
|
||||||
source = yadm_dir.join(f'alt/{filename}##{suffix}')
|
source = yadm_dir.join(f'alt/{filename}##{suffix}')
|
||||||
source.write('test-data', ensure=True)
|
source.write('test-data', ensure=True)
|
||||||
run = runner([paths.pgm, '-Y', yadm_dir, 'add', source])
|
run = runner([
|
||||||
|
paths.pgm, '-Y', yadm_dir, '--yadm-data', yadm_data, 'add', source])
|
||||||
assert run.success
|
assert run.success
|
||||||
assert run.err == ''
|
assert run.err == ''
|
||||||
assert run.out == ''
|
assert run.out == ''
|
||||||
|
@ -280,6 +281,7 @@ def test_ensure_alt_path(runner, paths, style):
|
||||||
def setup_standard_yadm_dir(paths):
|
def setup_standard_yadm_dir(paths):
|
||||||
"""Configure a yadm home within the work tree"""
|
"""Configure a yadm home within the work tree"""
|
||||||
std_yadm_dir = paths.work.mkdir('.config').mkdir('yadm')
|
std_yadm_dir = paths.work.mkdir('.config').mkdir('yadm')
|
||||||
std_yadm_dir.join('repo.git').mksymlinkto(paths.repo, absolute=1)
|
std_yadm_data = paths.work.mkdir('.local').mkdir('share').mkdir('yadm')
|
||||||
|
std_yadm_data.join('repo.git').mksymlinkto(paths.repo, absolute=1)
|
||||||
std_yadm_dir.join('encrypt').mksymlinkto(paths.encrypt, absolute=1)
|
std_yadm_dir.join('encrypt').mksymlinkto(paths.encrypt, absolute=1)
|
||||||
return std_yadm_dir
|
return std_yadm_dir, std_yadm_data
|
||||||
|
|
|
@ -9,12 +9,14 @@ ENCRYPT = 'encrypt'
|
||||||
HOME = '/testhome'
|
HOME = '/testhome'
|
||||||
REPO = 'repo.git'
|
REPO = 'repo.git'
|
||||||
YDIR = '.config/yadm'
|
YDIR = '.config/yadm'
|
||||||
|
YDATA = '.local/share/yadm'
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
'override, expect', [
|
'override, expect', [
|
||||||
(None, {}),
|
(None, {}),
|
||||||
('-Y', {}),
|
('-Y', {'yadm': 'YADM_DIR'}),
|
||||||
|
('--yadm-data', {'data': 'YADM_DATA'}),
|
||||||
('--yadm-repo', {'repo': 'YADM_REPO', 'git': 'GIT_DIR'}),
|
('--yadm-repo', {'repo': 'YADM_REPO', 'git': 'GIT_DIR'}),
|
||||||
('--yadm-config', {'config': 'YADM_CONFIG'}),
|
('--yadm-config', {'config': 'YADM_CONFIG'}),
|
||||||
('--yadm-encrypt', {'encrypt': 'YADM_ENCRYPT'}),
|
('--yadm-encrypt', {'encrypt': 'YADM_ENCRYPT'}),
|
||||||
|
@ -23,6 +25,7 @@ YDIR = '.config/yadm'
|
||||||
], ids=[
|
], ids=[
|
||||||
'default',
|
'default',
|
||||||
'override yadm dir',
|
'override yadm dir',
|
||||||
|
'override yadm data',
|
||||||
'override repo',
|
'override repo',
|
||||||
'override config',
|
'override config',
|
||||||
'override encrypt',
|
'override encrypt',
|
||||||
|
@ -36,6 +39,8 @@ def test_config(runner, paths, override, expect):
|
||||||
args = []
|
args = []
|
||||||
if override == '-Y':
|
if override == '-Y':
|
||||||
matches = match_map('/' + opath)
|
matches = match_map('/' + opath)
|
||||||
|
if override == '--yadm-data':
|
||||||
|
matches = match_map(None, '/' + opath)
|
||||||
|
|
||||||
if override:
|
if override:
|
||||||
args = [override, '/' + opath]
|
args = [override, '/' + opath]
|
||||||
|
@ -49,18 +54,20 @@ def test_config(runner, paths, override, expect):
|
||||||
run_test(runner, paths, args, matches.values(), 0)
|
run_test(runner, paths, args, matches.values(), 0)
|
||||||
|
|
||||||
|
|
||||||
def match_map(yadm_dir=None):
|
def match_map(yadm_dir=None, yadm_data=None):
|
||||||
"""Create a dictionary of matches, relative to yadm_dir"""
|
"""Create a dictionary of matches, relative to yadm_dir"""
|
||||||
if not yadm_dir:
|
if not yadm_dir:
|
||||||
yadm_dir = '/'.join([HOME, YDIR])
|
yadm_dir = '/'.join([HOME, YDIR])
|
||||||
|
if not yadm_data:
|
||||||
|
yadm_data = '/'.join([HOME, YDATA])
|
||||||
return {
|
return {
|
||||||
'yadm': f'YADM_DIR="{yadm_dir}"',
|
'yadm': f'YADM_DIR="{yadm_dir}"',
|
||||||
'repo': f'YADM_REPO="{yadm_dir}/{REPO}"',
|
'repo': f'YADM_REPO="{yadm_data}/{REPO}"',
|
||||||
'config': f'YADM_CONFIG="{yadm_dir}/{CONFIG}"',
|
'config': f'YADM_CONFIG="{yadm_dir}/{CONFIG}"',
|
||||||
'encrypt': f'YADM_ENCRYPT="{yadm_dir}/{ENCRYPT}"',
|
'encrypt': f'YADM_ENCRYPT="{yadm_dir}/{ENCRYPT}"',
|
||||||
'archive': f'YADM_ARCHIVE="{yadm_dir}/{ARCHIVE}"',
|
'archive': f'YADM_ARCHIVE="{yadm_data}/{ARCHIVE}"',
|
||||||
'bootstrap': f'YADM_BOOTSTRAP="{yadm_dir}/{BOOTSTRAP}"',
|
'bootstrap': f'YADM_BOOTSTRAP="{yadm_dir}/{BOOTSTRAP}"',
|
||||||
'git': f'GIT_DIR="{yadm_dir}/{REPO}"',
|
'git': f'GIT_DIR="{yadm_data}/{REPO}"',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -70,6 +77,8 @@ def run_test(runner, paths, args, expected_matches, expected_code=0):
|
||||||
script = f"""
|
script = f"""
|
||||||
YADM_TEST=1 HOME="{HOME}" source {paths.pgm}
|
YADM_TEST=1 HOME="{HOME}" source {paths.pgm}
|
||||||
process_global_args {argstring}
|
process_global_args {argstring}
|
||||||
|
XDG_CONFIG_HOME=
|
||||||
|
XDG_DATA_HOME=
|
||||||
HOME="{HOME}" set_yadm_dirs
|
HOME="{HOME}" set_yadm_dirs
|
||||||
configure_paths
|
configure_paths
|
||||||
declare -p | grep -E '(YADM|GIT)_'
|
declare -p | grep -E '(YADM|GIT)_'
|
||||||
|
|
|
@ -26,7 +26,7 @@ def test_set_local_alt_values(
|
||||||
script = f"""
|
script = f"""
|
||||||
YADM_TEST=1 source {yadm} &&
|
YADM_TEST=1 source {yadm} &&
|
||||||
set_operating_system &&
|
set_operating_system &&
|
||||||
YADM_DIR={paths.yadm} configure_paths &&
|
YADM_DIR={paths.yadm} YADM_DATA={paths.data} configure_paths &&
|
||||||
set_local_alt_values
|
set_local_alt_values
|
||||||
echo "class='$local_class'"
|
echo "class='$local_class'"
|
||||||
echo "os='$local_system'"
|
echo "os='$local_system'"
|
||||||
|
|
|
@ -3,29 +3,46 @@ import pytest
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
'condition',
|
'condition', [
|
||||||
['basic', 'override', 'xdg_config_home'],
|
'basic',
|
||||||
|
'override',
|
||||||
|
'override_data',
|
||||||
|
'xdg_config_home',
|
||||||
|
'xdg_data_home'
|
||||||
|
],
|
||||||
)
|
)
|
||||||
def test_set_yadm_dirs(runner, yadm, condition):
|
def test_set_yadm_dirs(runner, yadm, condition):
|
||||||
"""Test set_yadm_dirs"""
|
"""Test set_yadm_dirs"""
|
||||||
setup = ''
|
setup = ''
|
||||||
if condition == 'override':
|
if condition == 'override':
|
||||||
setup = 'YADM_DIR=/override'
|
setup = 'YADM_DIR=/override'
|
||||||
|
elif condition == 'override_data':
|
||||||
|
setup = 'YADM_DATA=/override'
|
||||||
elif condition == 'xdg_config_home':
|
elif condition == 'xdg_config_home':
|
||||||
setup = 'XDG_CONFIG_HOME=/xdg'
|
setup = 'XDG_CONFIG_HOME=/xdg'
|
||||||
|
elif condition == 'xdg_data_home':
|
||||||
|
setup = 'XDG_DATA_HOME=/xdg'
|
||||||
script = f"""
|
script = f"""
|
||||||
HOME=/testhome
|
HOME=/testhome
|
||||||
YADM_TEST=1 source {yadm}
|
YADM_TEST=1 source {yadm}
|
||||||
|
XDG_CONFIG_HOME=
|
||||||
|
XDG_DATA_HOME=
|
||||||
{setup}
|
{setup}
|
||||||
set_yadm_dirs
|
set_yadm_dirs
|
||||||
echo "$YADM_DIR"
|
echo "YADM_DIR=$YADM_DIR"
|
||||||
|
echo "YADM_DATA=$YADM_DATA"
|
||||||
"""
|
"""
|
||||||
run = runner(command=['bash'], inp=script)
|
run = runner(command=['bash'], inp=script)
|
||||||
assert run.success
|
assert run.success
|
||||||
assert run.err == ''
|
assert run.err == ''
|
||||||
if condition == 'basic':
|
if condition == 'basic':
|
||||||
assert run.out.rstrip() == '/testhome/.config/yadm'
|
assert 'YADM_DIR=/testhome/.config/yadm' in run.out
|
||||||
|
assert 'YADM_DATA=/testhome/.local/share/yadm' in run.out
|
||||||
elif condition == 'override':
|
elif condition == 'override':
|
||||||
assert run.out.rstrip() == '/override'
|
assert 'YADM_DIR=/override' in run.out
|
||||||
|
elif condition == 'override_data':
|
||||||
|
assert 'YADM_DATA=/override' in run.out
|
||||||
elif condition == 'xdg_config_home':
|
elif condition == 'xdg_config_home':
|
||||||
assert run.out.rstrip() == '/xdg/yadm'
|
assert 'YADM_DIR=/xdg/yadm' in run.out
|
||||||
|
elif condition == 'xdg_data_home':
|
||||||
|
assert 'YADM_DATA=/xdg/yadm' in run.out
|
||||||
|
|
Loading…
Reference in a new issue