diff options
Diffstat (limited to 'systemd/test/test_journal.py')
-rw-r--r-- | systemd/test/test_journal.py | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/systemd/test/test_journal.py b/systemd/test/test_journal.py index fd13cd0..fd38036 100644 --- a/systemd/test/test_journal.py +++ b/systemd/test/test_journal.py @@ -1,3 +1,4 @@ +from __future__ import print_function import contextlib import datetime import errno @@ -40,11 +41,11 @@ class MockSender: self.buf.append(args) @contextlib.contextmanager -def skip_enosys(): +def skip_oserror(code): try: yield - except OSError as e: - if e.errno == errno.ENOSYS: + except (OSError, IOError) as e: + if e.errno == code: pytest.skip() raise @@ -132,7 +133,7 @@ def test_reader_init_path_nondirectory_fd(): def test_reader_init_path_fd(tmpdir): fd = os.open(tmpdir.strpath, os.O_RDONLY) - with skip_enosys(): + with skip_oserror(errno.ENOSYS): j1 = journal.Reader(path=fd) assert list(j1) == [] @@ -175,7 +176,7 @@ def test_reader_this_machine(tmpdir): def test_reader_query_unique(tmpdir): j = journal.Reader(path=tmpdir.strpath) with j: - with skip_enosys(): + with skip_oserror(errno.ENOSYS): ans = j.query_unique('FOOBAR') assert isinstance(ans, set) assert ans == set() @@ -183,7 +184,7 @@ def test_reader_query_unique(tmpdir): def test_reader_enumerate_fields(tmpdir): j = journal.Reader(path=tmpdir.strpath) with j: - with skip_enosys(): + with skip_oserror(errno.ENOSYS): ans = j.enumerate_fields() assert isinstance(ans, set) assert ans == set() @@ -191,14 +192,14 @@ def test_reader_enumerate_fields(tmpdir): def test_reader_has_runtime_files(tmpdir): j = journal.Reader(path=tmpdir.strpath) with j: - with skip_enosys(): + with skip_oserror(errno.ENOSYS): ans = j.has_runtime_files() assert ans == False def test_reader_has_persistent_files(tmpdir): j = journal.Reader(path=tmpdir.strpath) with j: - with skip_enosys(): + with skip_oserror(errno.ENOSYS): ans = j.has_runtime_files() assert ans == False @@ -236,3 +237,13 @@ def test_seek_realtime(tmpdir): long_ago = datetime.datetime(1970, 5, 4) j.seek_realtime(long_ago) + +def test_journal_stream(): + # This will fail when running in a bare chroot without /run/systemd/journal/stdout + with skip_oserror(errno.ENOENT): + stream = journal.stream('test_journal.py') + + res = stream.write('message...\n') + assert res in (11, None) # Python2 returns None + + print('printed message...', file=stream) |