pass
+class WatchLogTimeout(WatchLogException):
+ pass
+
+
class LogFile:
"""
Log file wrapper with a path and means to find a string in its contents.
return the match, allowing access to the matched line, the regex
groups, and the regex which matched. See re.Match for more.
- A `TimeoutError` is raised if the function fails to find any of the
+ A `WatchLogTimeout` is raised if the function fails to find any of the
`patterns` in the allotted time.
Recommended use:
... watcher.wait_for_line("bar") #doctest: +ELLIPSIS
Traceback (most recent call last):
...
- TimeoutError: Timeout reached watching ...
+ isctest.log.watchlog.WatchLogTimeout: ...
>>> with tempfile.NamedTemporaryFile("w") as file:
... print("foo bar baz", file=file, flush=True)
... with WatchLogFromHere(file.name) as watcher:
All the matches are returned as a list.
- A `TimeoutError` is raised if the function fails to find all of the
+ A `WatchLogTimeout` is raised if the function fails to find all of the
`patterns` in the given order in the allotted time.
>>> import tempfile
... ret = watcher.wait_for_sequence(seq) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
- TimeoutError: Timeout reached watching ...
+ isctest.log.watchlog.WatchLogTimeout: ...
>>> import tempfile
>>> seq = ['a', 'b', 'c']
... ret = watcher.wait_for_sequence(seq) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
- TimeoutError: Timeout reached watching ...
+ isctest.log.watchlog.WatchLogTimeout: ...
>>> import tempfile
>>> seq = ['a', 'b', 'c']
... ret = watcher.wait_for_sequence(seq) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
- TimeoutError: Timeout reached watching ...
+ isctest.log.watchlog.WatchLogTimeout: ...
"""
regexes = self._prepare_patterns(patterns)
self._wait_function_called = True
matches are included. To pair matches with the patterns, re.Match.re
may be used.
- A `TimeoutError` is raised if the function fails to find all of the
+ A `WatchLogTimeout` is raised if the function fails to find all of the
`patterns` in the allotted time.
>>> import tempfile
... ret = watcher.wait_for_all(patterns) #doctest: +ELLIPSIS
Traceback (most recent call last):
...
- TimeoutError: Timeout reached watching ...
+ isctest.log.watchlog.WatchLogTimeout: ...
"""
regexes = self._prepare_patterns(patterns)
self._wait_function_called = True
if match:
return match
time.sleep(0.1)
- raise TimeoutError(
+ raise WatchLogTimeout(
f"Timeout reached watching {self._path} for "
f"{' | '.join([regex.pattern for regex in regexes])}"
)