From 2e115f3c4f6f96a2fae0ef011def64ab8b0a11ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Sat, 5 Sep 2015 14:13:38 +0200 Subject: tests: daemon.listen_fds --- systemd/test/test_daemon.py | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/systemd/test/test_daemon.py b/systemd/test/test_daemon.py index 230581d..96c5717 100644 --- a/systemd/test/test_daemon.py +++ b/systemd/test/test_daemon.py @@ -1,7 +1,7 @@ import sys import os import posix -from systemd.daemon import _is_fifo, is_fifo +from systemd.daemon import _is_fifo, is_fifo, listen_fds import pytest @@ -62,3 +62,28 @@ def test_is_fifo_bad_fd(tmpdir): with pytest.raises(OSError): assert not is_fifo(-1, path) + +def test_listen_fds_no_fds(): + # make sure we have no fds to listen to + os.unsetenv('LISTEN_FDS') + os.unsetenv('LISTEN_PID') + + assert listen_fds() == [] + assert listen_fds(True) == [] + assert listen_fds(False) == [] + +def test_listen_fds(): + os.environ['LISTEN_FDS'] = '3' + os.environ['LISTEN_PID'] = str(os.getpid()) + + assert listen_fds(False) == [3, 4, 5] + assert listen_fds(True) == [3, 4, 5] + assert listen_fds() == [] + +def test_listen_fds_default_unset(): + os.environ['LISTEN_FDS'] = '1' + os.environ['LISTEN_PID'] = str(os.getpid()) + + assert listen_fds(False) == [3] + assert listen_fds() == [3] + assert listen_fds() == [] -- cgit v1.2.1