|
| 1 | +from __future__ import print_function |
1 | 2 | import contextlib |
2 | 3 | import datetime |
3 | 4 | import errno |
|
13 | 14 | TEST_MID = uuid.UUID('8441372f8dca4ca98694a6091fd8519f') |
14 | 15 |
|
15 | 16 | @contextlib.contextmanager |
16 | | -def skip_enosys(): |
| 17 | +def skip_oserror(code): |
17 | 18 | try: |
18 | 19 | yield |
19 | | - except OSError as e: |
20 | | - if e.errno == errno.ENOSYS: |
| 20 | + except (OSError, IOError) as e: |
| 21 | + if e.errno == code: |
21 | 22 | pytest.skip() |
22 | 23 | raise |
23 | 24 |
|
@@ -96,7 +97,7 @@ def test_reader_init_path_nondirectory_fd(): |
96 | 97 | def test_reader_init_path_fd(tmpdir): |
97 | 98 | fd = os.open(tmpdir.strpath, os.O_RDONLY) |
98 | 99 |
|
99 | | - with skip_enosys(): |
| 100 | + with skip_oserror(errno.ENOSYS): |
100 | 101 | j1 = journal.Reader(path=fd) |
101 | 102 | assert list(j1) == [] |
102 | 103 |
|
@@ -139,30 +140,30 @@ def test_reader_this_machine(tmpdir): |
139 | 140 | def test_reader_query_unique(tmpdir): |
140 | 141 | j = journal.Reader(path=tmpdir.strpath) |
141 | 142 | with j: |
142 | | - with skip_enosys(): |
| 143 | + with skip_oserror(errno.ENOSYS): |
143 | 144 | ans = j.query_unique('FOOBAR') |
144 | 145 | assert isinstance(ans, set) |
145 | 146 | assert ans == set() |
146 | 147 |
|
147 | 148 | def test_reader_enumerate_fields(tmpdir): |
148 | 149 | j = journal.Reader(path=tmpdir.strpath) |
149 | 150 | with j: |
150 | | - with skip_enosys(): |
| 151 | + with skip_oserror(errno.ENOSYS): |
151 | 152 | ans = j.enumerate_fields() |
152 | 153 | assert isinstance(ans, set) |
153 | 154 | assert ans == set() |
154 | 155 |
|
155 | 156 | def test_reader_has_runtime_files(tmpdir): |
156 | 157 | j = journal.Reader(path=tmpdir.strpath) |
157 | 158 | with j: |
158 | | - with skip_enosys(): |
| 159 | + with skip_oserror(errno.ENOSYS): |
159 | 160 | ans = j.has_runtime_files() |
160 | 161 | assert ans == False |
161 | 162 |
|
162 | 163 | def test_reader_has_persistent_files(tmpdir): |
163 | 164 | j = journal.Reader(path=tmpdir.strpath) |
164 | 165 | with j: |
165 | | - with skip_enosys(): |
| 166 | + with skip_oserror(errno.ENOSYS): |
166 | 167 | ans = j.has_runtime_files() |
167 | 168 | assert ans == False |
168 | 169 |
|
@@ -200,3 +201,13 @@ def test_seek_realtime(tmpdir): |
200 | 201 |
|
201 | 202 | long_ago = datetime.datetime(1970, 5, 4) |
202 | 203 | j.seek_realtime(long_ago) |
| 204 | + |
| 205 | +def test_journal_stream(): |
| 206 | + # This will fail when running in a bare chroot without /run/systemd/journal/stdout |
| 207 | + with skip_oserror(errno.ENOENT): |
| 208 | + stream = journal.stream('test_journal.py') |
| 209 | + |
| 210 | + res = stream.write('message...\n') |
| 211 | + assert res in (11, None) # Python2 returns None |
| 212 | + |
| 213 | + print('printed message...', file=stream) |
0 commit comments