5
5
import os
6
6
import platform
7
7
import tempfile
8
+ import typing
8
9
9
10
10
- class NodeApp :
11
+ T_DICT_STR_STR = typing .Dict [str , str ]
12
+ T_LIST_STR = typing .List [str ]
13
+
11
14
12
- def __init__ (self , test_path = None , nodes_to_cleanup = None , os_ops = None ):
15
+ class NodeApp :
16
+ _os_ops : OsOperations
17
+ _test_path : str
18
+
19
+ def __init__ (
20
+ self ,
21
+ test_path : typing .Optional [str ] = None ,
22
+ nodes_to_cleanup : typing .Optional [list ] = None ,
23
+ os_ops : typing .Optional [OsOperations ] = None
24
+ ):
25
+ assert test_path is None or type (test_path ) == str # noqa: E721
13
26
assert os_ops is None or isinstance (os_ops , OsOperations )
14
27
15
28
if os_ops is None :
16
29
os_ops = LocalOperations .get_single_instance ()
17
30
18
31
assert isinstance (os_ops , OsOperations )
32
+ self ._os_ops = os_ops
19
33
20
- if test_path :
21
- if os .path .isabs (test_path ):
22
- self .test_path = test_path
23
- else :
24
- self .test_path = os_ops .build_path (os_ops .cwd (), test_path )
34
+ if test_path is None :
35
+ self ._test_path = os_ops .cwd ()
36
+ elif os .path .isabs (test_path ):
37
+ self ._test_path = test_path
25
38
else :
26
- self .test_path = os_ops .cwd ()
39
+ self ._test_path = os_ops .build_path (os_ops .cwd (), test_path )
40
+
27
41
self .nodes_to_cleanup = nodes_to_cleanup if nodes_to_cleanup else []
28
- self .os_ops = os_ops
42
+
43
+ @property
44
+ def os_ops (self ) -> OsOperations :
45
+ assert isinstance (self ._os_ops , OsOperations )
46
+ return self ._os_ops
47
+
48
+ @property
49
+ def test_path (self ) -> str :
50
+ assert isinstance (self ._test_path , OsOperations )
51
+ return self ._test_path
29
52
30
53
def make_empty (
31
54
self ,
32
- base_dir = None ,
33
- port = None ,
34
- bin_dir = None ):
35
- real_base_dir = self .os_ops .build_path (self .test_path , base_dir )
36
- self .os_ops .rmdirs (real_base_dir , ignore_errors = True )
37
- self .os_ops .makedirs (real_base_dir )
55
+ base_dir : typing .Optional [str ] = None ,
56
+ port : typing .Optional [int ] = None ,
57
+ bin_dir : typing .Optional [str ] = None
58
+ ) -> PostgresNode :
59
+ assert base_dir is None or type (base_dir ) == str # noqa: E721
60
+ assert port is None or type (port ) == int # noqa: E721
61
+ assert bin_dir is None or type (bin_dir ) == str # noqa: E721
62
+
63
+ assert isinstance (self ._os_ops , OsOperations )
64
+ assert type (self ._test_path ) == str # noqa: E721
65
+
66
+ real_base_dir = self ._os_ops .build_path (self ._test_path , base_dir )
67
+ self ._os_ops .rmdirs (real_base_dir , ignore_errors = True )
68
+ self ._os_ops .makedirs (real_base_dir )
38
69
39
70
node = PostgresNode (base_dir = real_base_dir , port = port , bin_dir = bin_dir )
40
71
self .nodes_to_cleanup .append (node )
@@ -43,24 +74,40 @@ def make_empty(
43
74
44
75
def make_simple (
45
76
self ,
46
- base_dir = None ,
47
- port = None ,
48
- set_replication = False ,
49
- ptrack_enable = False ,
50
- initdb_params = [],
51
- pg_options = {},
52
- checksum = True ,
53
- bin_dir = None ):
77
+ base_dir : typing .Optional [str ] = None ,
78
+ port : typing .Optional [int ] = None ,
79
+ set_replication : bool = False ,
80
+ ptrack_enable : bool = False ,
81
+ initdb_params : T_LIST_STR = [],
82
+ pg_options : T_DICT_STR_STR = {},
83
+ checksum : bool = True ,
84
+ bin_dir : typing .Optional [str ] = None
85
+ ) -> PostgresNode :
86
+ assert base_dir is None or type (base_dir ) == str # noqa: E721
87
+ assert port is None or type (port ) == int # noqa: E721
88
+ assert type (set_replication ) == bool # noqa: E721
89
+ assert type (ptrack_enable ) == bool # noqa: E721
90
+ assert type (initdb_params ) == list # noqa: E721
54
91
assert type (pg_options ) == dict # noqa: E721
92
+ assert type (checksum ) == bool # noqa: E721
93
+ assert bin_dir is None or type (bin_dir ) == str # noqa: E721
55
94
56
95
if checksum and '--data-checksums' not in initdb_params :
57
96
initdb_params .append ('--data-checksums' )
58
- node = self .make_empty (base_dir , port , bin_dir = bin_dir )
97
+
98
+ node = self .make_empty (
99
+ base_dir ,
100
+ port ,
101
+ bin_dir = bin_dir
102
+ )
103
+
59
104
node .init (
60
- initdb_params = initdb_params , allow_streaming = set_replication )
105
+ initdb_params = initdb_params ,
106
+ allow_streaming = set_replication
107
+ )
61
108
62
109
# set major version
63
- pg_version_file = self .os_ops .read (self .os_ops .build_path (node .data_dir , 'PG_VERSION' ))
110
+ pg_version_file = self ._os_ops .read (self ._os_ops .build_path (node .data_dir , 'PG_VERSION' ))
64
111
node .major_version_str = str (pg_version_file .rstrip ())
65
112
node .major_version = float (node .major_version_str )
66
113
@@ -115,7 +162,7 @@ def make_simple(
115
162
return node
116
163
117
164
@staticmethod
118
- def _gettempdir_for_socket ():
165
+ def _gettempdir_for_socket () -> str :
119
166
platform_system_name = platform .system ().lower ()
120
167
121
168
if platform_system_name == "windows" :
@@ -143,7 +190,7 @@ def _gettempdir_for_socket():
143
190
return "/tmp"
144
191
145
192
@staticmethod
146
- def _gettempdir ():
193
+ def _gettempdir () -> str :
147
194
v = tempfile .gettempdir ()
148
195
149
196
#
0 commit comments