Skip to content

Fix get_pg_version for linux mint #101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions testgres/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,20 +177,23 @@ def get_pg_version(bin_dir=None):
Return PostgreSQL version provided by postmaster.
"""

# get raw version (e.g. postgres (PostgreSQL) 9.5.7)
# Get raw version (e.g., postgres (PostgreSQL) 9.5.7)
postgres_path = os.path.join(bin_dir, 'postgres') if bin_dir else get_bin_path('postgres')
_params = [postgres_path, '--version']
raw_ver = tconf.os_ops.exec_command(_params, encoding='utf-8')

# Remove "(Homebrew)" if present
raw_ver = raw_ver.replace('(Homebrew)', '').strip()
return parse_pg_version(raw_ver)

# cook version of PostgreSQL
version = raw_ver.strip().split(' ')[-1] \

def parse_pg_version(version_out):
# Generalize removal of system-specific suffixes (anything in parentheses)
raw_ver = re.sub(r'\([^)]*\)', '', version_out).strip()

# Cook version of PostgreSQL
version = raw_ver.split(' ')[-1] \
.partition('devel')[0] \
.partition('beta')[0] \
.partition('rc')[0]

return version


Expand Down
12 changes: 11 additions & 1 deletion tests/test_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

# NOTE: those are ugly imports
from testgres import bound_ports
from testgres.utils import PgVer
from testgres.utils import PgVer, parse_pg_version
from testgres.node import ProcessProxy


Expand Down Expand Up @@ -1023,6 +1023,16 @@ def test_upgrade_node(self):
node_new.start()
self.assertTrue(b'Upgrade Complete' in res)

def test_parse_pg_version(self):
# Linux Mint
assert parse_pg_version("postgres (PostgreSQL) 15.5 (Ubuntu 15.5-1.pgdg22.04+1)") == "15.5"
# Linux Ubuntu
assert parse_pg_version("postgres (PostgreSQL) 12.17") == "12.17"
# Windows
assert parse_pg_version("postgres (PostgreSQL) 11.4") == "11.4"
# Macos
assert parse_pg_version("postgres (PostgreSQL) 14.9 (Homebrew)") == "14.9"


if __name__ == '__main__':
if os.environ.get('ALT_CONFIG'):
Expand Down