1
0
Fork 0
mirror of synced 2024-11-18 15:15:35 -05:00
yadm/test/test_unit_query_distro.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

31 lines
1.1 KiB
Python

"""Unit tests: query_distro"""
import pytest
@pytest.mark.parametrize("condition", ["lsb_release", "os-release", "os-release-quotes", "missing"])
def test_query_distro(runner, yadm, tst_distro, tmp_path, condition):
"""Match lsb_release -si when present"""
test_release = "testrelease"
lsb_release = ""
os_release = tmp_path.joinpath("os-release")
if "os-release" in condition:
quotes = '"' if "quotes" in condition else ""
os_release.write_text(f"testing\nID={quotes}{test_release}{quotes}\nrelease")
if condition != "lsb_release":
lsb_release = 'LSB_RELEASE_PROGRAM="missing_lsb_release"'
script = f"""
YADM_TEST=1 source {yadm}
{lsb_release}
OS_RELEASE="{os_release}"
query_distro
"""
run = runner(command=["bash"], inp=script)
assert run.success
assert run.err == ""
if condition == "lsb_release":
assert run.out.rstrip() == tst_distro
elif "os-release" in condition:
assert run.out.rstrip() == test_release
else:
assert run.out.rstrip() == ""