File tree 2 files changed +20
-7
lines changed
2 files changed +20
-7
lines changed Original file line number Diff line number Diff line change @@ -177,20 +177,23 @@ def get_pg_version(bin_dir=None):
177
177
Return PostgreSQL version provided by postmaster.
178
178
"""
179
179
180
- # get raw version (e.g. postgres (PostgreSQL) 9.5.7)
180
+ # Get raw version (e.g., postgres (PostgreSQL) 9.5.7)
181
181
postgres_path = os .path .join (bin_dir , 'postgres' ) if bin_dir else get_bin_path ('postgres' )
182
182
_params = [postgres_path , '--version' ]
183
183
raw_ver = tconf .os_ops .exec_command (_params , encoding = 'utf-8' )
184
184
185
- # Remove "(Homebrew)" if present
186
- raw_ver = raw_ver .replace ('(Homebrew)' , '' ).strip ()
185
+ return parse_pg_version (raw_ver )
187
186
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 ] \
190
194
.partition ('devel' )[0 ] \
191
195
.partition ('beta' )[0 ] \
192
196
.partition ('rc' )[0 ]
193
-
194
197
return version
195
198
196
199
Original file line number Diff line number Diff line change 48
48
49
49
# NOTE: those are ugly imports
50
50
from testgres import bound_ports
51
- from testgres .utils import PgVer
51
+ from testgres .utils import PgVer , parse_pg_version
52
52
from testgres .node import ProcessProxy
53
53
54
54
@@ -1023,6 +1023,16 @@ def test_upgrade_node(self):
1023
1023
node_new .start ()
1024
1024
self .assertTrue (b'Upgrade Complete' in res )
1025
1025
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
+
1026
1036
1027
1037
if __name__ == '__main__' :
1028
1038
if os .environ .get ('ALT_CONFIG' ):
You can’t perform that action at this time.
0 commit comments