diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2016-09-20 09:03:07 -0400 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2016-09-21 15:32:58 -0400 |
commit | 02b9432e736f3951078f3ad232baa445ca5d30b1 (patch) | |
tree | bca487a1fbecd877c77e65963e0587af279992ff /systemd/test | |
parent | 89badf50b797d7b76e37e71c27cba47264c560bf (diff) | |
download | python-systemd-02b9432e736f3951078f3ad232baa445ca5d30b1.tar.gz |
reader: add SD_JOURNAL_OS_ROOT and rework flag passing
Let's pass any flags through to the journal functions without checking
validity. Those functions do their own checking, so there's no need to
second-guess.
The semantics for _Reader(flags=0) are a bit changed:
before, this would be transformed into sd_journal_open(SD_J_LOCAL_ONLY).
Now, this results in sd_journal_open(0). Previous behaviour should be
achieved by not specifying the flags at all.
This change is necessary, because previously it was not possible to
pass flags=0 to sd_journal_open(0), i.e. it was not possible to "merge"
journals through the Python interface.
Similarly, Reader(flags=0) now means to open all journals, and
Reader(flags=None) is the same as Reader(flags=LOCAL_ONLY).
Diffstat (limited to 'systemd/test')
-rw-r--r-- | systemd/test/test_journal.py | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/systemd/test/test_journal.py b/systemd/test/test_journal.py index 4b23a70..10a57e9 100644 --- a/systemd/test/test_journal.py +++ b/systemd/test/test_journal.py @@ -43,15 +43,25 @@ def test_reader_init_flags(): 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) + 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) +def test_reader_os_root(tmpdir): with pytest.raises(ValueError): - journal.Reader(journal.LOCAL_ONLY, path=tmpdir.strpath) + journal.Reader(journal.OS_ROOT) + j1 = journal.Reader(path=tmpdir.strpath, + flags=journal.OS_ROOT) + j2 = journal.Reader(path=tmpdir.strpath, + flags=journal.OS_ROOT | journal.CURRENT_USER) + j3 = journal.Reader(path=tmpdir.strpath, + flags=journal.OS_ROOT | journal.SYSTEM_ONLY) + +def test_reader_init_path(tmpdir): + j1 = journal.Reader(path=tmpdir.strpath) + journal.Reader(0, path=tmpdir.strpath) + + j2 = journal.Reader(path=tmpdir.strpath) + journal.Reader(path=tmpdir.strpath) def test_reader_init_path_invalid_fd(): with pytest.raises(OSError): @@ -63,10 +73,15 @@ def test_reader_init_path_nondirectory_fd(): def test_reader_init_path_fd(tmpdir): fd = os.open(tmpdir.strpath, os.O_RDONLY) - j = journal.Reader(path=fd) - with pytest.raises(ValueError): - journal.Reader(journal.LOCAL_ONLY, path=fd) - assert list(j) == [] + + j1 = journal.Reader(path=fd) + assert list(j1) == [] + + j2 = journal.Reader(journal.SYSTEM, path=fd) + assert list(j2) == [] + + j3 = journal.Reader(journal.CURRENT_USER, path=fd) + assert list(j3) == [] def test_reader_as_cm(tmpdir): j = journal.Reader(path=tmpdir.strpath) |