Skip to content

Commit 5211952

Browse files
committed
tests: use a context manager, skip new functions if missing
1 parent 02b9432 commit 5211952

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed

systemd/test/test_journal.py

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
import contextlib
23
import uuid
34
import errno
45
import os
@@ -8,6 +9,15 @@
89

910
TEST_MID = uuid.UUID('8441372f8dca4ca98694a6091fd8519f')
1011

12+
@contextlib.contextmanager
13+
def skip_enosys():
14+
try:
15+
yield
16+
except OSError as e:
17+
if e.errno == errno.ENOSYS:
18+
pytest.skip()
19+
raise
20+
1121
def test_priorities():
1222
p = journal.JournalHandler.mapPriority
1323

@@ -74,7 +84,8 @@ def test_reader_init_path_nondirectory_fd():
7484
def test_reader_init_path_fd(tmpdir):
7585
fd = os.open(tmpdir.strpath, os.O_RDONLY)
7686

77-
j1 = journal.Reader(path=fd)
87+
with skip_enosys():
88+
j1 = journal.Reader(path=fd)
7889
assert list(j1) == []
7990

8091
j2 = journal.Reader(journal.SYSTEM, path=fd)
@@ -115,47 +126,31 @@ def test_reader_this_machine(tmpdir):
115126
def test_reader_query_unique(tmpdir):
116127
j = journal.Reader(path=tmpdir.strpath)
117128
with j:
118-
try:
129+
with skip_enosys():
119130
ans = j.query_unique('FOOBAR')
120-
except OSError as e:
121-
if e.errno == errno.ENOSYS:
122-
return
123-
raise
124131
assert isinstance(ans, set)
125132
assert ans == set()
126133

127134
def test_reader_enumerate_fields(tmpdir):
128135
j = journal.Reader(path=tmpdir.strpath)
129136
with j:
130-
try:
137+
with skip_enosys():
131138
ans = j.enumerate_fields()
132-
except OSError as e:
133-
if e.errno == errno.ENOSYS:
134-
pytest.skip()
135-
raise
136139
assert isinstance(ans, set)
137140
assert ans == set()
138141

139142
def test_reader_has_runtime_files(tmpdir):
140143
j = journal.Reader(path=tmpdir.strpath)
141144
with j:
142-
try:
145+
with skip_enosys():
143146
ans = j.has_runtime_files()
144-
except OSError as e:
145-
if e.errno == errno.ENOSYS:
146-
pytest.skip()
147-
raise
148147
assert ans == False
149148

150149
def test_reader_has_persistent_files(tmpdir):
151150
j = journal.Reader(path=tmpdir.strpath)
152151
with j:
153-
try:
152+
with skip_enosys():
154153
ans = j.has_runtime_files()
155-
except OSError as e:
156-
if e.errno == errno.ENOSYS:
157-
pytest.skip()
158-
raise
159154
assert ans == False
160155

161156
def test_reader_converters(tmpdir):

0 commit comments

Comments
 (0)