|
1 | 1 | import logging |
2 | | -from systemd import journal |
| 2 | +import uuid |
| 3 | +from systemd import journal, id128 |
3 | 4 |
|
4 | 5 | import pytest |
5 | 6 |
|
| 7 | +TEST_MID = uuid.UUID('8441372f8dca4ca98694a6091fd8519f') |
| 8 | + |
6 | 9 | def test_priorities(): |
7 | 10 | p = journal.JournalHandler.mapPriority |
8 | 11 |
|
@@ -48,6 +51,35 @@ def test_reader_init_path(tmpdir): |
48 | 51 | with pytest.raises(ValueError): |
49 | 52 | journal.Reader(journal.LOCAL_ONLY, path=tmpdir.strpath) |
50 | 53 |
|
| 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 | + |
51 | 83 | def test_reader_converters(tmpdir): |
52 | 84 | converters = {'xxx' : lambda arg: 'yyy'} |
53 | 85 | j = journal.Reader(path=tmpdir.strpath, converters=converters) |
|
0 commit comments