summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2015-08-07 11:47:37 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2015-08-07 11:49:56 -0400
commita93828172f8f62b0bd2f1363c0932a5853ce7a3f (patch)
treeb11cfec24aac84197a4f6801b219bd972c2101e3
parentd2bc51344064f839f6189383a90b77ea8f6e633a (diff)
downloadpython-systemd-a93828172f8f62b0bd2f1363c0932a5853ce7a3f.tar.gz
tests: add first test
This is based on the code in https://github.com/systemd/python-systemd/pull/4 by Jacek Konieczny <j.konieczny@eggsoft.pl>.
-rw-r--r--systemd/test/test_daemon.py64
1 files changed, 64 insertions, 0 deletions
diff --git a/systemd/test/test_daemon.py b/systemd/test/test_daemon.py
new file mode 100644
index 0000000..230581d
--- /dev/null
+++ b/systemd/test/test_daemon.py
@@ -0,0 +1,64 @@
+import sys
+import os
+import posix
+from systemd.daemon import _is_fifo, is_fifo
+
+import pytest
+
+def test__is_fifo(tmpdir):
+ path = tmpdir.join('test.fifo').strpath
+ posix.mkfifo(path)
+ fd = os.open(path, os.O_RDONLY|os.O_NONBLOCK)
+
+ assert _is_fifo(fd, None)
+ assert _is_fifo(fd, path)
+
+def test__is_fifo_file(tmpdir):
+ file = tmpdir.join('test.fifo')
+ file.write('boo')
+ path = file.strpath
+ fd = os.open(path, os.O_RDONLY|os.O_NONBLOCK)
+
+ assert not _is_fifo(fd, None)
+ assert not _is_fifo(fd, path)
+
+def test__is_fifo_bad_fd(tmpdir):
+ path = tmpdir.join('test.fifo').strpath
+
+ with pytest.raises(OSError):
+ assert not _is_fifo(-1, None)
+
+ with pytest.raises(OSError):
+ assert not _is_fifo(-1, path)
+
+def test_is_fifo(tmpdir):
+ path = tmpdir.join('test.fifo').strpath
+ posix.mkfifo(path)
+ fd = os.open(path, os.O_RDONLY|os.O_NONBLOCK)
+ file = os.fdopen(fd, 'r')
+
+ assert is_fifo(file, None)
+ assert is_fifo(file, path)
+ assert is_fifo(fd, None)
+ assert is_fifo(fd, path)
+
+def test_is_fifo_file(tmpdir):
+ file = tmpdir.join('test.fifo')
+ file.write('boo')
+ path = file.strpath
+ fd = os.open(path, os.O_RDONLY|os.O_NONBLOCK)
+ file = os.fdopen(fd, 'r')
+
+ assert not is_fifo(file, None)
+ assert not is_fifo(file, path)
+ assert not is_fifo(fd, None)
+ assert not is_fifo(fd, path)
+
+def test_is_fifo_bad_fd(tmpdir):
+ path = tmpdir.join('test.fifo').strpath
+
+ with pytest.raises(OSError):
+ assert not is_fifo(-1, None)
+
+ with pytest.raises(OSError):
+ assert not is_fifo(-1, path)