summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2015-09-16 12:43:06 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2015-09-16 12:43:06 +0200
commit173c2a89b20a48152eca6136debcf3d43e67d75c (patch)
treed6bebbdad2d9ba1f2133578efceb23c56bf5014c
parent4f5aa7b54af5c2393448f38258ff297b43f2b777 (diff)
downloadpython-systemd-173c2a89b20a48152eca6136debcf3d43e67d75c.tar.gz
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.
-rw-r--r--systemd/test/test_journal.py34
1 files changed, 33 insertions, 1 deletions
diff --git a/systemd/test/test_journal.py b/systemd/test/test_journal.py
index e79a410..ab155da 100644
--- a/systemd/test/test_journal.py
+++ b/systemd/test/test_journal.py
@@ -1,8 +1,11 @@
import logging
-from systemd import journal
+import uuid
+from systemd import journal, id128
import pytest
+TEST_MID = uuid.UUID('8441372f8dca4ca98694a6091fd8519f')
+
def test_priorities():
p = journal.JournalHandler.mapPriority
@@ -48,6 +51,35 @@ def test_reader_init_path(tmpdir):
with pytest.raises(ValueError):
journal.Reader(journal.LOCAL_ONLY, path=tmpdir.strpath)
+def test_reader_as_cm(tmpdir):
+ j = journal.Reader(path=tmpdir.strpath)
+ with j:
+ assert not j.closed
+ assert j.closed
+ # make sure that operations on the Reader fail
+ with pytest.raises(OSError):
+ next(j)
+
+def test_reader_messageid_match(tmpdir):
+ j = journal.Reader(path=tmpdir.strpath)
+ with j:
+ j.messageid_match(id128.SD_MESSAGE_JOURNAL_START)
+ j.messageid_match(id128.SD_MESSAGE_JOURNAL_STOP.hex)
+
+def test_reader_this_boot(tmpdir):
+ j = journal.Reader(path=tmpdir.strpath)
+ with j:
+ j.this_boot()
+ j.this_boot(TEST_MID)
+ j.this_boot(TEST_MID.hex)
+
+def test_reader_this_machine(tmpdir):
+ j = journal.Reader(path=tmpdir.strpath)
+ with j:
+ j.this_machine()
+ j.this_machine(TEST_MID)
+ j.this_machine(TEST_MID.hex)
+
def test_reader_converters(tmpdir):
converters = {'xxx' : lambda arg: 'yyy'}
j = journal.Reader(path=tmpdir.strpath, converters=converters)