summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2016-09-20 09:34:27 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2016-09-21 15:32:58 -0400
commit52119523482430f762f7c8d75161f714b7ef3670 (patch)
tree85013fd64accc494ecd161052986c634ac920aa3
parent02b9432e736f3951078f3ad232baa445ca5d30b1 (diff)
downloadpython-systemd-52119523482430f762f7c8d75161f714b7ef3670.tar.gz
tests: use a context manager, skip new functions if missing
-rw-r--r--systemd/test/test_journal.py37
1 files changed, 16 insertions, 21 deletions
diff --git a/systemd/test/test_journal.py b/systemd/test/test_journal.py
index 10a57e9..4acd7fe 100644
--- a/systemd/test/test_journal.py
+++ b/systemd/test/test_journal.py
@@ -1,4 +1,5 @@
import logging
+import contextlib
import uuid
import errno
import os
@@ -8,6 +9,15 @@ import pytest
TEST_MID = uuid.UUID('8441372f8dca4ca98694a6091fd8519f')
+@contextlib.contextmanager
+def skip_enosys():
+ try:
+ yield
+ except OSError as e:
+ if e.errno == errno.ENOSYS:
+ pytest.skip()
+ raise
+
def test_priorities():
p = journal.JournalHandler.mapPriority
@@ -74,7 +84,8 @@ def test_reader_init_path_nondirectory_fd():
def test_reader_init_path_fd(tmpdir):
fd = os.open(tmpdir.strpath, os.O_RDONLY)
- j1 = journal.Reader(path=fd)
+ with skip_enosys():
+ j1 = journal.Reader(path=fd)
assert list(j1) == []
j2 = journal.Reader(journal.SYSTEM, path=fd)
@@ -115,47 +126,31 @@ def test_reader_this_machine(tmpdir):
def test_reader_query_unique(tmpdir):
j = journal.Reader(path=tmpdir.strpath)
with j:
- try:
+ with skip_enosys():
ans = j.query_unique('FOOBAR')
- except OSError as e:
- if e.errno == errno.ENOSYS:
- return
- raise
assert isinstance(ans, set)
assert ans == set()
def test_reader_enumerate_fields(tmpdir):
j = journal.Reader(path=tmpdir.strpath)
with j:
- try:
+ with skip_enosys():
ans = j.enumerate_fields()
- except OSError as e:
- if e.errno == errno.ENOSYS:
- pytest.skip()
- raise
assert isinstance(ans, set)
assert ans == set()
def test_reader_has_runtime_files(tmpdir):
j = journal.Reader(path=tmpdir.strpath)
with j:
- try:
+ with skip_enosys():
ans = j.has_runtime_files()
- except OSError as e:
- if e.errno == errno.ENOSYS:
- pytest.skip()
- raise
assert ans == False
def test_reader_has_persistent_files(tmpdir):
j = journal.Reader(path=tmpdir.strpath)
with j:
- try:
+ with skip_enosys():
ans = j.has_runtime_files()
- except OSError as e:
- if e.errno == errno.ENOSYS:
- pytest.skip()
- raise
assert ans == False
def test_reader_converters(tmpdir):