1414import asyncpg
1515from asyncpg import _testbase as tb
1616from asyncpg .connection import _parse_connect_params
17+ from asyncpg .serverversion import split_server_version_string
1718
1819_system = platform .uname ().system
1920
@@ -25,6 +26,33 @@ async def test_get_settings_01(self):
2526 self .con .get_settings ().client_encoding ,
2627 'UTF8' )
2728
29+ async def test_server_version_01 (self ):
30+ version = self .con .get_server_version ()
31+ version_num = await self .con .fetchval ("SELECT current_setting($1)" ,
32+ 'server_version_num' , column = 0 )
33+ ver_maj = int (version_num [:- 4 ])
34+ ver_min = int (version_num [- 4 :- 2 ])
35+ ver_fix = int (version_num [- 2 :])
36+
37+ self .assertEqual (version [:3 ], (ver_maj , ver_min , ver_fix ))
38+
39+ def test_server_version_02 (self ):
40+ versions = [
41+ ("9.2" , (9 , 2 , 0 , 'final' , 0 ),),
42+ ("9.2.1" , (9 , 2 , 1 , 'final' , 0 ),),
43+ ("9.4beta1" , (9 , 4 , 0 , 'beta' , 1 ),),
44+ ("10devel" , (10 , 0 , 0 , 'devel' , 0 ),),
45+ ("10beta2" , (10 , 0 , 0 , 'beta' , 2 ),),
46+
47+ # Despite the fact after version 10 Postgre's second number
48+ # means "micro", it is parsed "as is" to be
49+ # less confusing in comparisons.
50+ ("10.1" , (10 , 1 , 0 , 'final' , 0 ),),
51+ ]
52+ for version , expected in versions :
53+ result = split_server_version_string (version )
54+ self .assertEqual (expected , result )
55+
2856
2957class TestAuthentication (tb .ConnectedTestCase ):
3058 def setUp (self ):
0 commit comments