Skip to content

Commit bbbc6e8

Browse files
committed
tests: add tests for Reader initialization
1 parent 008aac7 commit bbbc6e8

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

systemd/journal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def _convert_field(self, key, value):
179179
return value
180180

181181
def _convert_entry(self, entry):
182-
"""Convert entire journal entry utilising _covert_field"""
182+
"""Convert entire journal entry utilising _convert_field"""
183183
result = {}
184184
for key, value in entry.items():
185185
if isinstance(value, list):

systemd/test/test_journal.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,42 @@ def test_journalhandler_init_exception():
3232
def test_journalhandler_init():
3333
kw = {'X':3, 'X3':4}
3434
journal.JournalHandler(logging.INFO, **kw)
35+
36+
def test_reader_init_flags():
37+
j1 = journal.Reader()
38+
j2 = journal.Reader(journal.LOCAL_ONLY)
39+
j3 = journal.Reader(journal.RUNTIME_ONLY)
40+
j4 = journal.Reader(journal.SYSTEM_ONLY)
41+
j5 = journal.Reader(journal.LOCAL_ONLY|
42+
journal.RUNTIME_ONLY|
43+
journal.SYSTEM_ONLY)
44+
j6 = journal.Reader(0)
45+
46+
def test_reader_init_path(tmpdir):
47+
j = journal.Reader(path=tmpdir.strpath)
48+
with pytest.raises(ValueError):
49+
journal.Reader(journal.LOCAL_ONLY, path=tmpdir.strpath)
50+
51+
def test_reader_converters(tmpdir):
52+
converters = {'xxx' : lambda arg: 'yyy'}
53+
j = journal.Reader(path=tmpdir.strpath, converters=converters)
54+
55+
val = j._convert_field('xxx', b'abc')
56+
assert val == 'yyy'
57+
58+
val = j._convert_field('zzz', b'\200\200')
59+
assert val == b'\200\200'
60+
61+
def test_reader_convert_entry(tmpdir):
62+
converters = {'x1' : lambda arg: 'yyy',
63+
'x2' : lambda arg: 'YYY'}
64+
j = journal.Reader(path=tmpdir.strpath, converters=converters)
65+
66+
val = j._convert_entry({'x1' : b'abc',
67+
'y1' : b'\200\200',
68+
'x2' : [b'abc', b'def'],
69+
'y2' : [b'\200\200', b'\200\201']})
70+
assert val == {'x1' : 'yyy',
71+
'y1' : b'\200\200',
72+
'x2' : ['YYY', 'YYY'],
73+
'y2' : [b'\200\200', b'\200\201']}

0 commit comments

Comments
 (0)