From bbbc6e8a921759e9ea7587356fbc1fe689eb77fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 17 Sep 2015 00:05:36 +0200 Subject: tests: add tests for Reader initialization --- systemd/journal.py | 2 +- systemd/test/test_journal.py | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/systemd/journal.py b/systemd/journal.py index 598a085..3fe3d83 100644 --- a/systemd/journal.py +++ b/systemd/journal.py @@ -179,7 +179,7 @@ class Reader(_Reader): return value def _convert_entry(self, entry): - """Convert entire journal entry utilising _covert_field""" + """Convert entire journal entry utilising _convert_field""" result = {} for key, value in entry.items(): if isinstance(value, list): diff --git a/systemd/test/test_journal.py b/systemd/test/test_journal.py index 564ead3..e79a410 100644 --- a/systemd/test/test_journal.py +++ b/systemd/test/test_journal.py @@ -32,3 +32,42 @@ def test_journalhandler_init_exception(): def test_journalhandler_init(): kw = {'X':3, 'X3':4} journal.JournalHandler(logging.INFO, **kw) + +def test_reader_init_flags(): + j1 = journal.Reader() + j2 = journal.Reader(journal.LOCAL_ONLY) + j3 = journal.Reader(journal.RUNTIME_ONLY) + j4 = journal.Reader(journal.SYSTEM_ONLY) + j5 = journal.Reader(journal.LOCAL_ONLY| + journal.RUNTIME_ONLY| + journal.SYSTEM_ONLY) + j6 = journal.Reader(0) + +def test_reader_init_path(tmpdir): + j = journal.Reader(path=tmpdir.strpath) + with pytest.raises(ValueError): + journal.Reader(journal.LOCAL_ONLY, path=tmpdir.strpath) + +def test_reader_converters(tmpdir): + converters = {'xxx' : lambda arg: 'yyy'} + j = journal.Reader(path=tmpdir.strpath, converters=converters) + + val = j._convert_field('xxx', b'abc') + assert val == 'yyy' + + val = j._convert_field('zzz', b'\200\200') + assert val == b'\200\200' + +def test_reader_convert_entry(tmpdir): + converters = {'x1' : lambda arg: 'yyy', + 'x2' : lambda arg: 'YYY'} + j = journal.Reader(path=tmpdir.strpath, converters=converters) + + val = j._convert_entry({'x1' : b'abc', + 'y1' : b'\200\200', + 'x2' : [b'abc', b'def'], + 'y2' : [b'\200\200', b'\200\201']}) + assert val == {'x1' : 'yyy', + 'y1' : b'\200\200', + 'x2' : ['YYY', 'YYY'], + 'y2' : [b'\200\200', b'\200\201']} -- cgit v1.2.1