Skip to content

Commit 173c2a8

Browse files
committed
tests: add simplistic tests for Reader matches
It would be nice to run those tests against fake journal files with the right content to actually test the matches. But those tests are still useful because they test that the interface works as expected.
1 parent 4f5aa7b commit 173c2a8

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

systemd/test/test_journal.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import logging
2-
from systemd import journal
2+
import uuid
3+
from systemd import journal, id128
34

45
import pytest
56

7+
TEST_MID = uuid.UUID('8441372f8dca4ca98694a6091fd8519f')
8+
69
def test_priorities():
710
p = journal.JournalHandler.mapPriority
811

@@ -48,6 +51,35 @@ def test_reader_init_path(tmpdir):
4851
with pytest.raises(ValueError):
4952
journal.Reader(journal.LOCAL_ONLY, path=tmpdir.strpath)
5053

54+
def test_reader_as_cm(tmpdir):
55+
j = journal.Reader(path=tmpdir.strpath)
56+
with j:
57+
assert not j.closed
58+
assert j.closed
59+
# make sure that operations on the Reader fail
60+
with pytest.raises(OSError):
61+
next(j)
62+
63+
def test_reader_messageid_match(tmpdir):
64+
j = journal.Reader(path=tmpdir.strpath)
65+
with j:
66+
j.messageid_match(id128.SD_MESSAGE_JOURNAL_START)
67+
j.messageid_match(id128.SD_MESSAGE_JOURNAL_STOP.hex)
68+
69+
def test_reader_this_boot(tmpdir):
70+
j = journal.Reader(path=tmpdir.strpath)
71+
with j:
72+
j.this_boot()
73+
j.this_boot(TEST_MID)
74+
j.this_boot(TEST_MID.hex)
75+
76+
def test_reader_this_machine(tmpdir):
77+
j = journal.Reader(path=tmpdir.strpath)
78+
with j:
79+
j.this_machine()
80+
j.this_machine(TEST_MID)
81+
j.this_machine(TEST_MID.hex)
82+
5183
def test_reader_converters(tmpdir):
5284
converters = {'xxx' : lambda arg: 'yyy'}
5385
j = journal.Reader(path=tmpdir.strpath, converters=converters)

0 commit comments

Comments
 (0)