From 5aab3fc3b41ca06e66463f66ed9cc936a03a18fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Fri, 16 Dec 2016 21:05:38 -0500 Subject: 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. --- docs/login.rst | 6 +++--- setup.py | 4 +++- systemd/test/test_login.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 systemd/test/test_login.py diff --git a/docs/login.rst b/docs/login.rst index 2ee807c..23204e0 100644 --- a/docs/login.rst +++ b/docs/login.rst @@ -17,12 +17,12 @@ external event loop: >>> import select >>> from systemd import login - >>> m = login.Monitor("machine") + >>> m = login.Monitor("machine") # doctest: +SKIP >>> p = select.poll() - >>> p.register(m, m.get_events()) + >>> p.register(m, m.get_events()) # doctest: +SKIP >>> login.machine_names() # doctest: +SKIP [] >>> p.poll() # doctest: +SKIP [(3, 1)] >>> login.machine_names() # doctest: +SKIP - ['fedora-19.nspawn'] + ['fedora-25'] diff --git a/setup.py b/setup.py index 1acfbc5..70c2780 100644 --- a/setup.py +++ b/setup.py @@ -92,7 +92,9 @@ setup (name = 'systemd-python', 'License :: OSI Approved :: GNU Lesser General Public License v2 or later (LGPLv2+)', ], py_modules = ['systemd.journal', 'systemd.daemon', - 'systemd.test.test_daemon', 'systemd.test.test_journal'], + 'systemd.test.test_daemon', + 'systemd.test.test_journal', + 'systemd.test.test_login'], ext_modules = [_journal, _reader, _daemon, 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() -- cgit v1.2.1