diff options
Diffstat (limited to 'systemd/test')
-rw-r--r-- | systemd/test/test_daemon.py | 22 | ||||
-rw-r--r-- | systemd/test/test_journal.py | 4 | ||||
-rw-r--r-- | systemd/test/test_login.py | 48 |
3 files changed, 61 insertions, 13 deletions
diff --git a/systemd/test/test_daemon.py b/systemd/test/test_daemon.py index c1e08c7..ae76e54 100644 --- a/systemd/test/test_daemon.py +++ b/systemd/test/test_daemon.py @@ -243,12 +243,12 @@ def test_listen_fds_default_unset(): assert listen_fds() == [] def test_notify_no_socket(): - assert notify('READY=1') == False + assert notify('READY=1') is False with skip_enosys(): - assert notify('FDSTORE=1', fds=[]) == False - assert notify('FDSTORE=1', fds=[1,2]) == False - assert notify('FDSTORE=1', pid=os.getpid()) == False - assert notify('FDSTORE=1', pid=os.getpid(), fds=(1,)) == False + assert notify('FDSTORE=1', fds=[]) is False + assert notify('FDSTORE=1', fds=[1, 2]) is False + assert notify('FDSTORE=1', pid=os.getpid()) is False + assert notify('FDSTORE=1', pid=os.getpid(), fds=(1,)) is False if sys.version_info >= (3,): connection_error = ConnectionRefusedError @@ -264,7 +264,7 @@ def test_notify_bad_socket(): with skip_enosys(): notify('FDSTORE=1', fds=[]) with pytest.raises(connection_error): - notify('FDSTORE=1', fds=[1,2]) + notify('FDSTORE=1', fds=[1, 2]) with pytest.raises(connection_error): notify('FDSTORE=1', pid=os.getpid()) with pytest.raises(connection_error): @@ -282,9 +282,9 @@ def test_notify_with_socket(tmpdir): sock.setsockopt(socket.SOL_SOCKET, SO_PASSCRED, 1) os.environ['NOTIFY_SOCKET'] = path - assert notify('READY=1') == True + assert notify('READY=1') with skip_enosys(): - assert notify('FDSTORE=1', fds=[]) == True - assert notify('FDSTORE=1', fds=[1,2]) == True - assert notify('FDSTORE=1', pid=os.getpid()) == True - assert notify('FDSTORE=1', pid=os.getpid(), fds=(1,)) == True + assert notify('FDSTORE=1', fds=[]) + assert notify('FDSTORE=1', fds=[1, 2]) + assert notify('FDSTORE=1', pid=os.getpid()) + assert notify('FDSTORE=1', pid=os.getpid(), fds=(1,)) diff --git a/systemd/test/test_journal.py b/systemd/test/test_journal.py index fd38036..582b031 100644 --- a/systemd/test/test_journal.py +++ b/systemd/test/test_journal.py @@ -194,14 +194,14 @@ def test_reader_has_runtime_files(tmpdir): with j: with skip_oserror(errno.ENOSYS): ans = j.has_runtime_files() - assert ans == False + assert ans is False def test_reader_has_persistent_files(tmpdir): j = journal.Reader(path=tmpdir.strpath) with j: with skip_oserror(errno.ENOSYS): ans = j.has_runtime_files() - assert ans == False + assert ans is False def test_reader_converters(tmpdir): converters = {'xxx' : lambda arg: 'yyy'} 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() |