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
+6 -14
View File
@@ -8,7 +8,12 @@ import time
import pytest import pytest
from config import CONFIGSDIR, FIXTURES, SECRET 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 ( from postgrest import (
freeport, freeport,
is_ipv6, 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): def test_connect_with_dburi(dburi, defaultenv):
"Connecting with db-uri instead of LIPQ* environment variables should work." "Connecting with db-uri instead of LIPQ* environment variables should work."
defaultenv_without_libpq = { defaultenv_without_libpq = {
+14
View File
@@ -1,3 +1,4 @@
import re
import threading import threading
import jwt import jwt
@@ -21,6 +22,19 @@ class Thread(threading.Thread):
raise self._exception 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): def authheader(token):
"Bearer token HTTP authorization header." "Bearer token HTTP authorization header."
return {"Authorization": f"Bearer {token}"} return {"Authorization": f"Bearer {token}"}