Skip to content

Commit

Permalink
Accept "17rc1" as server version in tests
Browse files Browse the repository at this point in the history
The old coding assumed that PG server versions would always contain a
dot, but that's not true while in beta or rc.
  • Loading branch information
df7cb authored and tlocke committed Sep 14, 2024
1 parent 9d7b1f4 commit 9e62f81
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
6 changes: 4 additions & 2 deletions test/dbapi/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import pytest

from test.utils import parse_server_version

import pg8000.dbapi


Expand Down Expand Up @@ -57,5 +59,5 @@ def pg_version(cursor):
cursor.execute("select current_setting('server_version')")
retval = cursor.fetchall()
version = retval[0][0]
idx = version.index(".")
return int(version[:idx])
major = parse_server_version(version)
return int(major)
6 changes: 4 additions & 2 deletions test/native/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import pytest

from test.utils import parse_server_version

import pg8000.native


Expand Down Expand Up @@ -45,5 +47,5 @@ def fin():
def pg_version(con):
retval = con.run("select current_setting('server_version')")
version = retval[0][0]
idx = version.index(".")
return int(version[:idx])
major = parse_server_version(version)
return int(major)
5 changes: 5 additions & 0 deletions test/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from test.utils import parse_server_version


def test_parse_server_version():
assert parse_server_version("17rc1") == 17
6 changes: 6 additions & 0 deletions test/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import re


def parse_server_version(version):
major = re.match(r"\d+", version).group() # leading digits in 17.0, 17rc1
return int(major)

0 comments on commit 9e62f81

Please sign in to comment.