diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2016-12-16 21:05:38 -0500 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2017-03-12 12:26:51 -0400 |
commit | 5aab3fc3b41ca06e66463f66ed9cc936a03a18fd (patch) | |
tree | 2db6fca65738888b6e652125c5e943b3bc27f6c4 /systemd | |
parent | 8921c79fb98e5e04c0e2f00813e9d8e015e4206e (diff) | |
download | python-systemd-5aab3fc3b41ca06e66463f66ed9cc936a03a18fd.tar.gz |
tests: move login tests from doctest to separate file
This way we can skip ENOENT (which happens in containers).
While at it, let's extend the tests a bit, so that we at least
call all functions and check the type of the return value.
Also, drop '.nspawn' from the machine name, nspawn doesn't
use that suffix any more.
Diffstat (limited to 'systemd')
-rw-r--r-- | systemd/test/test_login.py | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/systemd/test/test_login.py b/systemd/test/test_login.py new file mode 100644 index 0000000..afb5f45 --- /dev/null +++ b/systemd/test/test_login.py @@ -0,0 +1,48 @@ +from __future__ import print_function +import select +import contextlib +import errno + +from systemd import login + +import pytest + +@contextlib.contextmanager +def skip_oserror(code): + try: + yield + except (OSError, IOError) as e: + if e.errno == code: + pytest.skip() + raise + +def test_seats(): + # just check that we get some sequence back + with skip_oserror(errno.ENOENT): + seats = login.seats() + assert len(seats) >= 0 + +def test_sessions(): + with skip_oserror(errno.ENOENT): + sessions = login.sessions() + assert len(sessions) >= 0 + +def test_machine_names(): + with skip_oserror(errno.ENOENT): + machine_names = login.machine_names() + assert len(machine_names) >= 0 + +def test_uids(): + with skip_oserror(errno.ENOENT): + uids = login.uids() + assert len(uids) >= 0 + +def test_monitor(): + p = select.poll() + + with skip_oserror(errno.ENOENT): + m = login.Monitor("machine") + p.register(m, m.get_events()) + login.machine_names() + p.poll(1) + login.machine_names() |