From f2932bffea377cec4b785106eb717c51543885e0 Mon Sep 17 00:00:00 2001 From: Taimoor Zaeem Date: Mon, 18 May 2026 17:33:41 +0500 Subject: [PATCH] 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 --- test/io/test_io.py | 20 ++++++-------------- test/io/util.py | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/test/io/test_io.py b/test/io/test_io.py index 31a5b82a6..fd4cc60a8 100644 --- a/test/io/test_io.py +++ b/test/io/test_io.py @@ -8,7 +8,12 @@ import time import pytest from config import CONFIGSDIR, FIXTURES, SECRET -from util import Thread, jwtauthheader, parse_server_timings_header +from util import ( + Thread, + jwtauthheader, + parse_server_timings_header, + match_log, +) from postgrest import ( freeport, is_ipv6, @@ -22,19 +27,6 @@ from postgrest import ( ) -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 test_connect_with_dburi(dburi, defaultenv): "Connecting with db-uri instead of LIPQ* environment variables should work." defaultenv_without_libpq = { diff --git a/test/io/util.py b/test/io/util.py index e1a8d0977..67ba26b03 100644 --- a/test/io/util.py +++ b/test/io/util.py @@ -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}"}