|
1 | 1 | import logging |
| 2 | +import contextlib |
2 | 3 | import uuid |
3 | 4 | import errno |
4 | 5 | import os |
|
8 | 9 |
|
9 | 10 | TEST_MID = uuid.UUID('8441372f8dca4ca98694a6091fd8519f') |
10 | 11 |
|
| 12 | +@contextlib.contextmanager |
| 13 | +def skip_enosys(): |
| 14 | + try: |
| 15 | + yield |
| 16 | + except OSError as e: |
| 17 | + if e.errno == errno.ENOSYS: |
| 18 | + pytest.skip() |
| 19 | + raise |
| 20 | + |
11 | 21 | def test_priorities(): |
12 | 22 | p = journal.JournalHandler.mapPriority |
13 | 23 |
|
@@ -74,7 +84,8 @@ def test_reader_init_path_nondirectory_fd(): |
74 | 84 | def test_reader_init_path_fd(tmpdir): |
75 | 85 | fd = os.open(tmpdir.strpath, os.O_RDONLY) |
76 | 86 |
|
77 | | - j1 = journal.Reader(path=fd) |
| 87 | + with skip_enosys(): |
| 88 | + j1 = journal.Reader(path=fd) |
78 | 89 | assert list(j1) == [] |
79 | 90 |
|
80 | 91 | j2 = journal.Reader(journal.SYSTEM, path=fd) |
@@ -115,47 +126,31 @@ def test_reader_this_machine(tmpdir): |
115 | 126 | def test_reader_query_unique(tmpdir): |
116 | 127 | j = journal.Reader(path=tmpdir.strpath) |
117 | 128 | with j: |
118 | | - try: |
| 129 | + with skip_enosys(): |
119 | 130 | ans = j.query_unique('FOOBAR') |
120 | | - except OSError as e: |
121 | | - if e.errno == errno.ENOSYS: |
122 | | - return |
123 | | - raise |
124 | 131 | assert isinstance(ans, set) |
125 | 132 | assert ans == set() |
126 | 133 |
|
127 | 134 | def test_reader_enumerate_fields(tmpdir): |
128 | 135 | j = journal.Reader(path=tmpdir.strpath) |
129 | 136 | with j: |
130 | | - try: |
| 137 | + with skip_enosys(): |
131 | 138 | ans = j.enumerate_fields() |
132 | | - except OSError as e: |
133 | | - if e.errno == errno.ENOSYS: |
134 | | - pytest.skip() |
135 | | - raise |
136 | 139 | assert isinstance(ans, set) |
137 | 140 | assert ans == set() |
138 | 141 |
|
139 | 142 | def test_reader_has_runtime_files(tmpdir): |
140 | 143 | j = journal.Reader(path=tmpdir.strpath) |
141 | 144 | with j: |
142 | | - try: |
| 145 | + with skip_enosys(): |
143 | 146 | ans = j.has_runtime_files() |
144 | | - except OSError as e: |
145 | | - if e.errno == errno.ENOSYS: |
146 | | - pytest.skip() |
147 | | - raise |
148 | 147 | assert ans == False |
149 | 148 |
|
150 | 149 | def test_reader_has_persistent_files(tmpdir): |
151 | 150 | j = journal.Reader(path=tmpdir.strpath) |
152 | 151 | with j: |
153 | | - try: |
| 152 | + with skip_enosys(): |
154 | 153 | ans = j.has_runtime_files() |
155 | | - except OSError as e: |
156 | | - if e.errno == errno.ENOSYS: |
157 | | - pytest.skip() |
158 | | - raise |
159 | 154 | assert ans == False |
160 | 155 |
|
161 | 156 | def test_reader_converters(tmpdir): |
|
0 commit comments