1
0
Fork 0
mirror of synced 2024-12-04 14:45:36 -05:00
yadm/test/test_unit_copy_perms.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

53 lines
1.5 KiB
Python

"""Unit tests: copy_perms"""
import os
import pytest
OCTAL = "7654"
NON_OCTAL = "9876"
@pytest.mark.parametrize("stat_broken", [True, False], ids=["normal", "stat broken"])
def test_copy_perms(runner, yadm, tmpdir, stat_broken):
"""Test function copy_perms"""
src_mode = 0o754
dst_mode = 0o644
source = tmpdir.join("source")
source.write("test", ensure=True)
source.chmod(src_mode)
dest = tmpdir.join("dest")
dest.write("test", ensure=True)
dest.chmod(dst_mode)
override_stat = ""
if stat_broken:
override_stat = "function stat() { echo broken; }"
script = f"""
YADM_TEST=1 source {yadm}
{override_stat}
copy_perms "{source}" "{dest}"
"""
run = runner(command=["bash"], inp=script)
assert run.success
assert run.err == ""
assert run.out == ""
expected = dst_mode if stat_broken else src_mode
assert oct(os.stat(dest).st_mode)[-3:] == oct(expected)[-3:]
@pytest.mark.parametrize("stat_output", [OCTAL, NON_OCTAL], ids=["octal", "non-octal"])
def test_get_mode(runner, yadm, stat_output):
"""Test function get_mode"""
script = f"""
YADM_TEST=1 source {yadm}
function stat() {{ echo {stat_output}; }}
mode=$(get_mode abc)
echo "MODE:$mode"
"""
run = runner(command=["bash"], inp=script)
assert run.success
assert run.err == ""
expected = OCTAL if stat_output == OCTAL else ""
assert f"MODE:{expected}\n" in run.out