1
0
Fork 0
mirror of synced 2024-11-18 23:25:35 -05:00
yadm/test/test_unit_set_yadm_dir.py
Erik Flodin 30fa6f08a4
Update testbed docker image
* Update base image to Ubuntu 24.10. This uses a python version where j2cli no
  longer works when installed using pip so use the version from Ubuntu instead
  which has been patched to work.

* Update shellcheck, pylint, pytest, isort, flake8, black and yamllint to the
  latest versions. This closes #502.

* Use a longer expect timeout to fix tests failing when gpg is killed due to
  this timeout.

* Explicitly flush gpg-agent's cached passwords to fix failing tests with
  latest gnupg. Also clean up after tests to avoid having gpg-agents running
  after the test (e.g. when running tests directly without docker).
2024-11-11 22:30:41 +01:00

44 lines
1.4 KiB
Python

"""Unit tests: set_yadm_dirs"""
import pytest
@pytest.mark.parametrize(
"condition",
["basic", "override", "override_data", "xdg_config_home", "xdg_data_home"],
)
def test_set_yadm_dirs(runner, yadm, condition):
"""Test set_yadm_dirs"""
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"
script = f"""
HOME=/testhome
YADM_TEST=1 source {yadm}
XDG_CONFIG_HOME=
XDG_DATA_HOME=
{setup}
set_yadm_dirs
echo "YADM_DIR=$YADM_DIR"
echo "YADM_DATA=$YADM_DATA"
"""
run = runner(command=["bash"], inp=script)
assert run.success
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