From 173c2a89b20a48152eca6136debcf3d43e67d75c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 16 Sep 2015 12:43:06 +0200 Subject: 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. --- systemd/test/test_journal.py | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) 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) -- cgit v1.2.1