mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-09-03 16:15:27 +00:00
Use custom WatchLog timeout exception
The TimeoutError is raised when system functions time out. Define a custom WatchLogTimeout to improve clarity.
This commit is contained in:
@@ -24,6 +24,10 @@ class WatchLogException(Exception):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class WatchLogTimeout(WatchLogException):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class LogFile:
|
class LogFile:
|
||||||
"""
|
"""
|
||||||
Log file wrapper with a path and means to find a string in its contents.
|
Log file wrapper with a path and means to find a string in its contents.
|
||||||
@@ -165,7 +169,7 @@ class WatchLog(abc.ABC):
|
|||||||
return the match, allowing access to the matched line, the regex
|
return the match, allowing access to the matched line, the regex
|
||||||
groups, and the regex which matched. See re.Match for more.
|
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.
|
`patterns` in the allotted time.
|
||||||
|
|
||||||
Recommended use:
|
Recommended use:
|
||||||
@@ -224,7 +228,7 @@ class WatchLog(abc.ABC):
|
|||||||
... watcher.wait_for_line("bar") #doctest: +ELLIPSIS
|
... watcher.wait_for_line("bar") #doctest: +ELLIPSIS
|
||||||
Traceback (most recent call last):
|
Traceback (most recent call last):
|
||||||
...
|
...
|
||||||
TimeoutError: Timeout reached watching ...
|
isctest.log.watchlog.WatchLogTimeout: ...
|
||||||
>>> with tempfile.NamedTemporaryFile("w") as file:
|
>>> with tempfile.NamedTemporaryFile("w") as file:
|
||||||
... print("foo bar baz", file=file, flush=True)
|
... print("foo bar baz", file=file, flush=True)
|
||||||
... with WatchLogFromHere(file.name) as watcher:
|
... with WatchLogFromHere(file.name) as watcher:
|
||||||
@@ -268,7 +272,7 @@ class WatchLog(abc.ABC):
|
|||||||
|
|
||||||
All the matches are returned as a list.
|
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.
|
`patterns` in the given order in the allotted time.
|
||||||
|
|
||||||
>>> import tempfile
|
>>> import tempfile
|
||||||
@@ -295,7 +299,7 @@ class WatchLog(abc.ABC):
|
|||||||
... ret = watcher.wait_for_sequence(seq) #doctest: +ELLIPSIS
|
... ret = watcher.wait_for_sequence(seq) #doctest: +ELLIPSIS
|
||||||
Traceback (most recent call last):
|
Traceback (most recent call last):
|
||||||
...
|
...
|
||||||
TimeoutError: Timeout reached watching ...
|
isctest.log.watchlog.WatchLogTimeout: ...
|
||||||
|
|
||||||
>>> import tempfile
|
>>> import tempfile
|
||||||
>>> seq = ['a', 'b', 'c']
|
>>> seq = ['a', 'b', 'c']
|
||||||
@@ -307,7 +311,7 @@ class WatchLog(abc.ABC):
|
|||||||
... ret = watcher.wait_for_sequence(seq) #doctest: +ELLIPSIS
|
... ret = watcher.wait_for_sequence(seq) #doctest: +ELLIPSIS
|
||||||
Traceback (most recent call last):
|
Traceback (most recent call last):
|
||||||
...
|
...
|
||||||
TimeoutError: Timeout reached watching ...
|
isctest.log.watchlog.WatchLogTimeout: ...
|
||||||
|
|
||||||
>>> import tempfile
|
>>> import tempfile
|
||||||
>>> seq = ['a', 'b', 'c']
|
>>> seq = ['a', 'b', 'c']
|
||||||
@@ -320,7 +324,7 @@ class WatchLog(abc.ABC):
|
|||||||
... ret = watcher.wait_for_sequence(seq) #doctest: +ELLIPSIS
|
... ret = watcher.wait_for_sequence(seq) #doctest: +ELLIPSIS
|
||||||
Traceback (most recent call last):
|
Traceback (most recent call last):
|
||||||
...
|
...
|
||||||
TimeoutError: Timeout reached watching ...
|
isctest.log.watchlog.WatchLogTimeout: ...
|
||||||
"""
|
"""
|
||||||
regexes = self._prepare_patterns(patterns)
|
regexes = self._prepare_patterns(patterns)
|
||||||
self._wait_function_called = True
|
self._wait_function_called = True
|
||||||
@@ -348,7 +352,7 @@ class WatchLog(abc.ABC):
|
|||||||
matches are included. To pair matches with the patterns, re.Match.re
|
matches are included. To pair matches with the patterns, re.Match.re
|
||||||
may be used.
|
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.
|
`patterns` in the allotted time.
|
||||||
|
|
||||||
>>> import tempfile
|
>>> import tempfile
|
||||||
@@ -388,7 +392,7 @@ class WatchLog(abc.ABC):
|
|||||||
... ret = watcher.wait_for_all(patterns) #doctest: +ELLIPSIS
|
... ret = watcher.wait_for_all(patterns) #doctest: +ELLIPSIS
|
||||||
Traceback (most recent call last):
|
Traceback (most recent call last):
|
||||||
...
|
...
|
||||||
TimeoutError: Timeout reached watching ...
|
isctest.log.watchlog.WatchLogTimeout: ...
|
||||||
"""
|
"""
|
||||||
regexes = self._prepare_patterns(patterns)
|
regexes = self._prepare_patterns(patterns)
|
||||||
self._wait_function_called = True
|
self._wait_function_called = True
|
||||||
@@ -411,7 +415,7 @@ class WatchLog(abc.ABC):
|
|||||||
if match:
|
if match:
|
||||||
return match
|
return match
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
raise TimeoutError(
|
raise WatchLogTimeout(
|
||||||
f"Timeout reached watching {self._path} for "
|
f"Timeout reached watching {self._path} for "
|
||||||
f"{' | '.join([regex.pattern for regex in regexes])}"
|
f"{' | '.join([regex.pattern for regex in regexes])}"
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user