test(io): move utility function to util.py

The function `match_log` should be in `util.py` so it can be reused
in other modules.

Signed-off-by: Taimoor Zaeem <taimoorzaeem@gmail.com>
This commit is contained in:
Taimoor Zaeem
2026-05-19 10:01:51 +05:00
parent 15b83ff4da
commit f2932bffea
2 changed files with 20 additions and 14 deletions
+14
View File
@@ -1,3 +1,4 @@
import re
import threading
import jwt
@@ -21,6 +22,19 @@ class Thread(threading.Thread):
raise self._exception
def match_log(output, matchers):
ito = iter(output)
itm = iter(matchers)
nextMatcher = next(itm, None)
while nextMatcher is not None and (line := next(ito, None)) is not None:
if re.match(nextMatcher, line) is not None:
nextMatcher = next(itm, None)
if nextMatcher is not None:
raise AssertionError(
f"Expected log line matching {nextMatcher} not found in output"
)
def authheader(token):
"Bearer token HTTP authorization header."
return {"Authorization": f"Bearer {token}"}