Fail if log.readlines()[sliceargs] is not contained in 'lines'. The log will be searched from the given marker to the next marker. If marker is None, self.lastmarker is used. If the log hasn't been marked (using self.markLog), the entire log will be searched.
(self, sliceargs, lines, marker=None)
| 201 | self._handleLogError(msg, data, marker, log_chunk) |
| 202 | |
| 203 | def assertLog(self, sliceargs, lines, marker=None): |
| 204 | """Fail if log.readlines()[sliceargs] is not contained in 'lines'. |
| 205 | |
| 206 | The log will be searched from the given marker to the next |
| 207 | marker. If marker is None, self.lastmarker is used. If the log |
| 208 | hasn't been marked (using self.markLog), the entire log will be |
| 209 | searched. |
| 210 | """ |
| 211 | data = self._read_marked_region(marker) |
| 212 | if isinstance(sliceargs, int): |
| 213 | # Single arg. Use __getitem__ and allow lines to be str or list. |
| 214 | if isinstance(lines, (tuple, list)): |
| 215 | lines = lines[0] |
| 216 | if isinstance(lines, str): |
| 217 | lines = lines.encode('utf-8') |
| 218 | if lines not in data[sliceargs]: |
| 219 | msg = '%r not found on log line %r' % (lines, sliceargs) |
| 220 | self._handleLogError( |
| 221 | msg, |
| 222 | [data[sliceargs], '--EXTRA CONTEXT--'] + data[ |
| 223 | sliceargs + 1:sliceargs + 6], |
| 224 | marker, |
| 225 | lines) |
| 226 | else: |
| 227 | # Multiple args. Use __getslice__ and require lines to be list. |
| 228 | if isinstance(lines, tuple): |
| 229 | lines = list(lines) |
| 230 | elif isinstance(lines, text_or_bytes): |
| 231 | raise TypeError("The 'lines' arg must be a list when " |
| 232 | "'sliceargs' is a tuple.") |
| 233 | |
| 234 | start, stop = sliceargs |
| 235 | for line, logline in zip(lines, data[start:stop]): |
| 236 | if isinstance(line, str): |
| 237 | line = line.encode('utf-8') |
| 238 | if line not in logline: |
| 239 | msg = '%r not found in log' % line |
| 240 | self._handleLogError(msg, data[start:stop], marker, line) |
no test coverage detected