Skip to content

Commit bb309f5

Browse files
author
vshepard
committed
Fix get_pg_version for linux mint
issue #100
1 parent 5218b11 commit bb309f5

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

testgres/utils.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,20 +177,23 @@ def get_pg_version(bin_dir=None):
177177
Return PostgreSQL version provided by postmaster.
178178
"""
179179

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

185-
# Remove "(Homebrew)" if present
186-
raw_ver = raw_ver.replace('(Homebrew)', '').strip()
185+
return parse_pg_version(raw_ver)
187186

188-
# cook version of PostgreSQL
189-
version = raw_ver.strip().split(' ')[-1] \
187+
188+
def parse_pg_version(version_out):
189+
# Generalize removal of system-specific suffixes (anything in parentheses)
190+
raw_ver = re.sub(r'\([^)]*\)', '', version_out).strip()
191+
192+
# Cook version of PostgreSQL
193+
version = raw_ver.split(' ')[-1] \
190194
.partition('devel')[0] \
191195
.partition('beta')[0] \
192196
.partition('rc')[0]
193-
194197
return version
195198

196199

tests/test_simple.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848

4949
# NOTE: those are ugly imports
5050
from testgres import bound_ports
51-
from testgres.utils import PgVer
51+
from testgres.utils import PgVer, parse_pg_version
5252
from testgres.node import ProcessProxy
5353

5454

@@ -1023,6 +1023,16 @@ def test_upgrade_node(self):
10231023
node_new.start()
10241024
self.assertTrue(b'Upgrade Complete' in res)
10251025

1026+
def test_parse_pg_version(self):
1027+
# Linux Mint
1028+
assert parse_pg_version("postgres (PostgreSQL) 15.5 (Ubuntu 15.5-1.pgdg22.04+1)") == "15.5"
1029+
# Linux Ubuntu
1030+
assert parse_pg_version("postgres (PostgreSQL) 12.17") == "12.17"
1031+
# Windows
1032+
assert parse_pg_version("postgres (PostgreSQL) 11.4") == "11.4"
1033+
# Macos
1034+
assert parse_pg_version("postgres (PostgreSQL) 14.9 (Homebrew)") == "14.9"
1035+
10261036

10271037
if __name__ == '__main__':
10281038
if os.environ.get('ALT_CONFIG'):

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy