11
11
# License for the specific language governing permissions and limitations
12
12
# under the License.
13
13
import os
14
-
14
+ from typing import Optional
15
15
from testcontainers .core .generic import DbContainer
16
16
17
17
@@ -39,13 +39,9 @@ class PostgresContainer(DbContainer):
39
39
POSTGRES_PASSWORD = os .environ .get ("POSTGRES_PASSWORD" , "test" )
40
40
POSTGRES_DB = os .environ .get ("POSTGRES_DB" , "test" )
41
41
42
- def __init__ (self ,
43
- image = "postgres:latest" ,
44
- port = 5432 , user = None ,
45
- password = None ,
46
- dbname = None ,
47
- driver = "psycopg2" ,
48
- ** kwargs ):
42
+ def __init__ (self , image : str = "postgres:latest" , port : int = 5432 , user : Optional [str ] = None ,
43
+ password : Optional [str ] = None , dbname : Optional [str ] = None ,
44
+ driver : str = "psycopg2" , ** kwargs ) -> None :
49
45
super (PostgresContainer , self ).__init__ (image = image , ** kwargs )
50
46
self .POSTGRES_USER = user or self .POSTGRES_USER
51
47
self .POSTGRES_PASSWORD = password or self .POSTGRES_PASSWORD
@@ -55,15 +51,14 @@ def __init__(self,
55
51
56
52
self .with_exposed_ports (self .port_to_expose )
57
53
58
- def _configure (self ):
54
+ def _configure (self ) -> None :
59
55
self .with_env ("POSTGRES_USER" , self .POSTGRES_USER )
60
56
self .with_env ("POSTGRES_PASSWORD" , self .POSTGRES_PASSWORD )
61
57
self .with_env ("POSTGRES_DB" , self .POSTGRES_DB )
62
58
63
- def get_connection_url (self , host = None ):
64
- return super ()._create_connection_url (dialect = "postgresql+{}" .format (self .driver ),
65
- username = self .POSTGRES_USER ,
66
- password = self .POSTGRES_PASSWORD ,
67
- db_name = self .POSTGRES_DB ,
68
- host = host ,
69
- port = self .port_to_expose )
59
+ def get_connection_url (self , host = None ) -> str :
60
+ return super ()._create_connection_url (
61
+ dialect = "postgresql+{}" .format (self .driver ), username = self .POSTGRES_USER ,
62
+ password = self .POSTGRES_PASSWORD , db_name = self .POSTGRES_DB , host = host ,
63
+ port = self .port_to_expose ,
64
+ )
0 commit comments