This repository has been archived on 2020-06-17. You can view files and clone it, but cannot push or open issues or pull requests.
autonomic/test/test_utils.py
2020-04-11 22:47:16 +02:00

59 lines
1.3 KiB
Python

from subprocess import STDOUT
from autonomic.utils import is_proc, qlist, run, yaml_dump, yaml_load
def test_run_kwargs():
assert run(["whoami"], stderr=STDOUT) is not None
def test_run_cwd(tmp_path):
directory = tmp_path / "test"
directory.mkdir()
testfile = directory / "testfile.txt"
testfile.write_text("hello, world")
output = run(["ls"], cwd=directory.absolute())
assert "testfile.txt" in output.decode()
def test_make_qlist():
output = qlist("foo", "bar", ["bang"])
expected = {
"type": "list",
"name": "foo",
"message": "bar",
"choices": ["bang"],
}
for key, val in expected.items():
assert expected[key] == output[0][key]
def test_yaml_load(tmp_path):
directory = tmp_path / "test"
directory.mkdir()
testfile = directory / "testfile.yml"
testfile.write_text("---\nusername: foobar")
loaded = yaml_load(testfile.absolute())
assert loaded["username"] == "foobar"
def test_yaml_dump(tmp_path):
directory = tmp_path / "test"
directory.mkdir()
testfile = directory / "testfile.yml"
yaml_dump(testfile.absolute(), {"username": "foobar"})
loaded = yaml_load(testfile.absolute())
assert loaded["username"] == "foobar"
def test_is_proc():
assert is_proc("pytest") is True