@@ -23,15 +23,16 @@ def ensure_directory(directory):
23
23
os .makedirs (directory )
24
24
25
25
26
- def ensure_removed (file_path ):
27
-
28
- if os .path .exists (file_path ):
29
- os .unlink (file_path )
26
+ def ensure_removed (path ):
27
+ if os .path .exists (path ):
28
+ if os .path .isfile (path ):
29
+ os .unlink (path )
30
+ elif os .path .isdir (path ):
31
+ shutil .rmtree (path )
30
32
31
33
32
34
@contextmanager
33
35
def temp_directory (files = None ):
34
-
35
36
temp_dir = tempfile .mkdtemp ()
36
37
print (temp_dir )
37
38
try :
@@ -77,26 +78,33 @@ def test_help():
77
78
78
79
79
80
def test_module_run ():
80
-
81
- rc = main (['-m' , 'ping' ,
82
- '--hosts' , 'localhost' ,
83
- 'run' ,
84
- 'ping' ])
85
- assert rc == 0
81
+ try :
82
+ rc = main (['-m' , 'ping' ,
83
+ '--hosts' , 'localhost' ,
84
+ 'run' ,
85
+ 'ping' ])
86
+ assert os .path .exists ('./ping' )
87
+ assert os .path .exists ('./ping/artifacts' )
88
+ assert rc == 0
89
+ finally :
90
+ shutil .rmtree ('./ping' )
86
91
87
92
88
93
def test_module_run_debug ():
89
-
90
- rc = main (['-m' , 'ping' ,
91
- '--hosts' , 'localhost' ,
92
- '--debug' ,
93
- 'run' ,
94
- 'ping' ])
95
- assert rc == 0
94
+ try :
95
+ rc = main (['-m' , 'ping' ,
96
+ '--hosts' , 'localhost' ,
97
+ '--debug' ,
98
+ 'run' ,
99
+ 'ping' ])
100
+ assert os .path .exists ('./ping' )
101
+ assert os .path .exists ('./ping/artifacts' )
102
+ assert rc == 0
103
+ finally :
104
+ shutil .rmtree ('./ping' )
96
105
97
106
98
107
def test_module_run_clean ():
99
-
100
108
with temp_directory () as temp_dir :
101
109
rc = main (['-m' , 'ping' ,
102
110
'--hosts' , 'localhost' ,
@@ -106,13 +114,13 @@ def test_module_run_clean():
106
114
107
115
108
116
def test_role_run ():
109
-
110
117
rc = main (['-r' , 'benthomasson.hello_role' ,
111
118
'--hosts' , 'localhost' ,
112
119
'--roles-path' , 'test/integration/roles' ,
113
120
'run' ,
114
121
"test/integration" ])
115
122
assert rc == 0
123
+ ensure_removed ("test/integration/artifacts" )
116
124
117
125
118
126
def test_role_run_abs ():
@@ -126,25 +134,32 @@ def test_role_run_abs():
126
134
127
135
128
136
def test_role_logfile ():
129
-
130
- rc = main (['-r' , 'benthomasson.hello_role' ,
131
- '--hosts' , 'localhost' ,
132
- '--roles-path' , 'test/integration/project/roles' ,
133
- '--logfile' , 'new_logfile' ,
134
- 'run' ,
135
- 'test/integration' ])
136
- assert rc == 0
137
-
138
-
139
- def test_role_logfile_abs ():
140
- with temp_directory () as temp_dir :
137
+ try :
141
138
rc = main (['-r' , 'benthomasson.hello_role' ,
142
139
'--hosts' , 'localhost' ,
143
- '--roles-path' , os . path . join ( HERE , ' project/roles') ,
140
+ '--roles-path' , 'test/integration/ project/roles' ,
144
141
'--logfile' , 'new_logfile' ,
145
142
'run' ,
146
- temp_dir ])
147
- assert rc == 0
143
+ 'test/integration' ])
144
+ assert os .path .exists ('new_logfile' )
145
+ assert rc == 0
146
+ finally :
147
+ ensure_removed ("test/integration/artifacts" )
148
+
149
+
150
+ def test_role_logfile_abs ():
151
+ try :
152
+ with temp_directory () as temp_dir :
153
+ rc = main (['-r' , 'benthomasson.hello_role' ,
154
+ '--hosts' , 'localhost' ,
155
+ '--roles-path' , os .path .join (HERE , 'project/roles' ),
156
+ '--logfile' , 'new_logfile' ,
157
+ 'run' ,
158
+ temp_dir ])
159
+ assert os .path .exists ('new_logfile' )
160
+ assert rc == 0
161
+ finally :
162
+ ensure_removed ("new_logfile" )
148
163
149
164
150
165
def test_role_bad_project_dir ():
@@ -162,6 +177,7 @@ def test_role_bad_project_dir():
162
177
'bad_project_dir' ])
163
178
finally :
164
179
os .unlink ('bad_project_dir' )
180
+ ensure_removed ("new_logfile" )
165
181
166
182
167
183
def test_role_run_clean ():
@@ -172,6 +188,7 @@ def test_role_run_clean():
172
188
'run' ,
173
189
"test/integration" ])
174
190
assert rc == 0
191
+ ensure_removed ("test/integration/artifacts" )
175
192
176
193
177
194
def test_role_run_cmd_line_abs ():
@@ -185,19 +202,14 @@ def test_role_run_cmd_line_abs():
185
202
186
203
187
204
def test_role_run_artifacts_dir ():
188
-
189
- try :
190
- tmpdir = tempfile .mkdtemp ()
191
- rc = main (['-r' , 'benthomasson.hello_role' ,
192
- '--hosts' , 'localhost' ,
193
- '--roles-path' , 'test/integration/roles' ,
194
- '--artifact-dir' , os .path .join (tmpdir , 'otherartifacts' ),
195
- 'run' ,
196
- "test/integration" ])
197
- assert os .path .exists (os .path .join (tmpdir , 'otherartifacts' ))
198
- assert rc == 0
199
- finally :
200
- shutil .rmtree (tmpdir )
205
+ rc = main (['-r' , 'benthomasson.hello_role' ,
206
+ '--hosts' , 'localhost' ,
207
+ '--roles-path' , 'test/integration/roles' ,
208
+ '--artifact-dir' , 'otherartifacts' ,
209
+ 'run' ,
210
+ "test/integration" ])
211
+ assert rc == 0
212
+ ensure_removed ("test/integration/artifacts" )
201
213
202
214
203
215
def test_role_run_artifacts_dir_abs ():
@@ -331,4 +343,3 @@ def test_playbook_start():
331
343
332
344
rc = main (['stop' , temp_dir ])
333
345
assert rc == 1
334
-
0 commit comments