Skip to content

Commit

Permalink
tests: add first test
Browse files Browse the repository at this point in the history
This is based on the code in #4
by Jacek Konieczny <j.konieczny@eggsoft.pl>.
  • Loading branch information
keszybz committed Aug 7, 2015
1 parent d2bc513 commit a938281
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions systemd/test/test_daemon.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit a938281

Please sign in to comment.