2828from firebird .driver .types import ImpData , ImpDataOld
2929from firebird .driver import (NetProtocol , connect , Isolation , tpb , DefaultAction ,
3030 DbInfoCode , DbWriteMode , DbAccessMode , DbSpaceReservation ,
31- driver_config )
31+ driver_config , NotSupportedError )
3232
3333def test_connect_helper ():
3434 DB_LINUX_PATH = '/path/to/db/employee.fdb'
@@ -69,34 +69,34 @@ def test_connect_helper():
6969 # URL-Style Connection Strings (with protocol)
7070 # 1. Loopback connection
7171 dsn = driver .core ._connect_helper (None , None , None , DB_ALIAS , NetProtocol .INET )
72- assert dsn == f'inet://{ DB_ALIAS } '
72+ assert dsn == f'inet:/// { DB_ALIAS } '
7373 dsn = driver .core ._connect_helper (None , None , None , DB_LINUX_PATH , NetProtocol .INET )
7474 assert dsn == f'inet://{ DB_LINUX_PATH } '
7575 dsn = driver .core ._connect_helper (None , None , None , DB_WIN_PATH , NetProtocol .INET )
7676 assert dsn == f'inet://{ DB_WIN_PATH } '
7777 dsn = driver .core ._connect_helper (None , None , None , DB_ALIAS , NetProtocol .WNET )
78- assert dsn == f'wnet://{ DB_ALIAS } '
78+ assert dsn == f'wnet:/// { DB_ALIAS } '
7979 dsn = driver .core ._connect_helper (None , None , None , DB_ALIAS , NetProtocol .XNET )
80- assert dsn == f'xnet://{ DB_ALIAS } '
80+ assert dsn == f'xnet:/// { DB_ALIAS } '
8181 # 2. TCP/IP
8282 dsn = driver .core ._connect_helper (None , HOST , None , DB_ALIAS , NetProtocol .INET )
8383 assert dsn == f'inet://{ HOST } /{ DB_ALIAS } '
8484 dsn = driver .core ._connect_helper (None , IP , None , DB_LINUX_PATH , NetProtocol .INET )
85- assert dsn == f'inet://{ IP } /{ DB_LINUX_PATH } '
85+ assert dsn == f'inet://{ IP } /{ DB_LINUX_PATH } ' # Double slash for absolute path
8686 dsn = driver .core ._connect_helper (None , HOST , None , DB_WIN_PATH , NetProtocol .INET )
87- assert dsn == f'inet://{ HOST } / { DB_WIN_PATH } '
87+ assert dsn == f'inet://{ HOST } { DB_WIN_PATH } '
8888 # 3. TCP/IP with Port
8989 dsn = driver .core ._connect_helper (None , HOST , PORT , DB_ALIAS , NetProtocol .INET )
9090 assert dsn == f'inet://{ HOST } :{ PORT } /{ DB_ALIAS } '
9191 dsn = driver .core ._connect_helper (None , IP , PORT , DB_LINUX_PATH , NetProtocol .INET )
92- assert dsn == f'inet://{ IP } :{ PORT } /{ DB_LINUX_PATH } '
92+ assert dsn == f'inet://{ IP } :{ PORT } /{ DB_LINUX_PATH } ' # Double slash for absolute path
9393 dsn = driver .core ._connect_helper (None , HOST , SVC_NAME , DB_WIN_PATH , NetProtocol .INET )
94- assert dsn == f'inet://{ HOST } :{ SVC_NAME } / { DB_WIN_PATH } '
94+ assert dsn == f'inet://{ HOST } :{ SVC_NAME } { DB_WIN_PATH } '
9595 # 4. Named pipes
9696 dsn = driver .core ._connect_helper (None , NPIPE_HOST , None , DB_ALIAS , NetProtocol .WNET )
9797 assert dsn == f'wnet://{ NPIPE_HOST } /{ DB_ALIAS } '
9898 dsn = driver .core ._connect_helper (None , NPIPE_HOST , SVC_NAME , DB_WIN_PATH , NetProtocol .WNET )
99- assert dsn == f'wnet://{ NPIPE_HOST } :{ SVC_NAME } / { DB_WIN_PATH } '
99+ assert dsn == f'wnet://{ NPIPE_HOST } :{ SVC_NAME } { DB_WIN_PATH } '
100100
101101def test_connect_dsn (dsn , db_file ):
102102 with connect (dsn ) as con :
@@ -108,21 +108,14 @@ def test_connect_dsn(dsn, db_file):
108108def test_connect_config (fb_vars , db_file , driver_cfg ):
109109 host = fb_vars ['host' ]
110110 port = fb_vars ['port' ]
111+
112+ # Construct server config
111113 if host is None :
112114 srv_config = f"""
113115 [server.local]
114116 user = { fb_vars ['user' ]}
115117 password = { fb_vars ['password' ]}
116118 """
117- db_config = f"""
118- [test_db1]
119- server = server.local
120- database = { db_file }
121- utf8filename = true
122- charset = UTF8
123- sql_dialect = 3
124- """
125- dsn = str (db_file )
126119 else :
127120 srv_config = f"""
128121 [server.local]
@@ -131,15 +124,23 @@ def test_connect_config(fb_vars, db_file, driver_cfg):
131124 password = { fb_vars ['password' ]}
132125 port = { port if port else '' }
133126 """
134- db_config = f"""
135- [test_db1]
136- server = server.local
137- database = { db_file }
138- utf8filename = true
139- charset = UTF8
140- sql_dialect = 3
141- """
142- dsn = f'{ host } /{ port } :{ db_file } ' if port else f'{ host } :{ db_file } '
127+
128+ # Database config is uniform - always use the file path
129+ db_config = f"""
130+ [test_db1]
131+ server = server.local
132+ database = { db_file }
133+ utf8filename = true
134+ charset = UTF8
135+ sql_dialect = 3
136+ """
137+
138+ # Construct DSN
139+ if host is None :
140+ dsn = str (db_file )
141+ else :
142+ dsn = f'{ host } /{ port } :{ str (db_file )} ' if port else f'{ host } :{ str (db_file )} '
143+
143144 # Ensure config sections don't exist from previous runs
144145 if driver_cfg .get_server ('server.local' ):
145146 driver_cfg .servers .value = [s for s in driver_cfg .servers .value if s .name != 'server.local' ]
@@ -162,7 +163,12 @@ def test_connect_config(fb_vars, db_file, driver_cfg):
162163
163164 if host :
164165 # protocols
165- dsn = f'{ host } /{ port } /{ db_file } ' if port else f'{ host } /{ db_file } '
166+ # For protocol URLs with absolute paths, we need double slash to preserve leading /
167+ # inet://host//absolute/path so Firebird doesn't strip the leading /
168+ if str (db_file ).startswith ('/' ):
169+ dsn = f'{ host } :{ port } /{ db_file } ' # Extra / for absolute paths
170+ else :
171+ dsn = f'{ host } :{ port } { db_file } '
166172 cfg = driver_cfg .get_database ('test_db1' )
167173 cfg .protocol .value = NetProtocol .INET
168174 with connect ('test_db1' ) as con :
@@ -372,11 +378,17 @@ def test_db_info(db_connection, fb_vars, db_file):
372378 assert isinstance (con .info .get_info (DbInfoCode .ODS_MINOR_VERSION ), int )
373379
374380 assert con .info .get_info (DbInfoCode .CRYPT_KEY ) == ''
375- assert con .info .get_info (DbInfoCode .CRYPT_PLUGIN ) == ''
381+ try :
382+ assert con .info .get_info (DbInfoCode .CRYPT_PLUGIN ) == ''
383+ except NotSupportedError :
384+ pass
376385 # DB_GUID can vary, just check format if needed
377- guid = con .info .get_info (DbInfoCode .DB_GUID )
378- assert isinstance (guid , str )
379- assert len (guid ) == 38 # Example check for {GUID} format
386+ try :
387+ guid = con .info .get_info (DbInfoCode .DB_GUID )
388+ assert isinstance (guid , str )
389+ assert len (guid ) == 38 # Example check for {GUID} format
390+ except NotSupportedError :
391+ pass
380392
381393def test_connect_with_driver_config_server_defaults_local (driver_cfg , db_file , fb_vars ):
382394 """
0 commit comments