2020-11-15 15:23:49 -05:00
|
|
|
"""Unit tests: set_yadm_dirs"""
|
2024-11-11 16:30:41 -05:00
|
|
|
|
2019-08-06 09:19:45 -04:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
2023-07-10 15:43:17 -04:00
|
|
|
"condition",
|
|
|
|
["basic", "override", "override_data", "xdg_config_home", "xdg_data_home"],
|
|
|
|
)
|
2020-11-15 15:23:49 -05:00
|
|
|
def test_set_yadm_dirs(runner, yadm, condition):
|
|
|
|
"""Test set_yadm_dirs"""
|
2023-07-10 15:43:17 -04:00
|
|
|
setup = ""
|
|
|
|
if condition == "override":
|
|
|
|
setup = "YADM_DIR=/override"
|
|
|
|
elif condition == "override_data":
|
|
|
|
setup = "YADM_DATA=/override"
|
|
|
|
elif condition == "xdg_config_home":
|
|
|
|
setup = "XDG_CONFIG_HOME=/xdg"
|
|
|
|
elif condition == "xdg_data_home":
|
|
|
|
setup = "XDG_DATA_HOME=/xdg"
|
2019-08-06 09:19:45 -04:00
|
|
|
script = f"""
|
|
|
|
HOME=/testhome
|
|
|
|
YADM_TEST=1 source {yadm}
|
2020-11-17 15:57:34 -05:00
|
|
|
XDG_CONFIG_HOME=
|
|
|
|
XDG_DATA_HOME=
|
2019-08-06 09:19:45 -04:00
|
|
|
{setup}
|
2020-11-15 15:23:49 -05:00
|
|
|
set_yadm_dirs
|
2020-11-17 15:57:34 -05:00
|
|
|
echo "YADM_DIR=$YADM_DIR"
|
|
|
|
echo "YADM_DATA=$YADM_DATA"
|
2019-08-06 09:19:45 -04:00
|
|
|
"""
|
2023-07-10 15:43:17 -04:00
|
|
|
run = runner(command=["bash"], inp=script)
|
2019-08-06 09:19:45 -04:00
|
|
|
assert run.success
|
2023-07-10 15:43:17 -04:00
|
|
|
assert run.err == ""
|
|
|
|
if condition == "basic":
|
|
|
|
assert "YADM_DIR=/testhome/.config/yadm" in run.out
|
|
|
|
assert "YADM_DATA=/testhome/.local/share/yadm" in run.out
|
|
|
|
elif condition == "override":
|
|
|
|
assert "YADM_DIR=/override" in run.out
|
|
|
|
elif condition == "override_data":
|
|
|
|
assert "YADM_DATA=/override" in run.out
|
|
|
|
elif condition == "xdg_config_home":
|
|
|
|
assert "YADM_DIR=/xdg/yadm" in run.out
|
|
|
|
elif condition == "xdg_data_home":
|
|
|
|
assert "YADM_DATA=/xdg/yadm" in run.out
|