3
3
# Licensed under the MIT License. See License.txt in the project root for license information.
4
4
# --------------------------------------------------------------------------------------------
5
5
6
- from __future__ import print_function
7
- import datetime
8
6
import unittest
9
7
import os
10
8
import inspect
29
27
from .utilities import create_random_name
30
28
from .decorators import live_only
31
29
32
- logger = logging .getLogger ('azuer .cli.testsdk' )
30
+ logger = logging .getLogger ('azure .cli.testsdk' )
33
31
34
32
35
33
class IntegrationTestBase (unittest .TestCase ):
36
34
def __init__ (self , method_name ):
37
35
super (IntegrationTestBase , self ).__init__ (method_name )
38
36
self .diagnose = os .environ .get (ENV_TEST_DIAGNOSE , None ) == 'True'
39
37
40
- def cmd (self , command , checks = None , expect_failure = False ):
41
- if self .diagnose :
42
- begin = datetime .datetime .now ()
43
- print ('\n Executing command: {}' .format (command ))
44
-
45
- result = execute (command , expect_failure = expect_failure )
46
-
47
- if self .diagnose :
48
- duration = datetime .datetime .now () - begin
49
- print ('\n Command accomplished in {} s. Exit code {}.\n {}' .format (
50
- duration .total_seconds (), result .exit_code , result .output ))
51
-
52
- return result .assert_with_checks (checks )
38
+ @classmethod
39
+ def cmd (cls , command , checks = None , expect_failure = False ):
40
+ return execute (command , expect_failure = expect_failure ).assert_with_checks (checks )
53
41
54
42
def create_random_name (self , prefix , length ): # pylint: disable=no-self-use
55
43
return create_random_name (prefix = prefix , length = length )
@@ -238,17 +226,21 @@ def _custom_request_query_matcher(cls, r1, r2):
238
226
239
227
class ExecutionResult (object ): # pylint: disable=too-few-public-methods
240
228
def __init__ (self , command , expect_failure = False , in_process = True ):
241
- logger .info ('Execute command %s' , command )
242
229
if in_process :
243
230
self ._in_process_execute (command )
244
231
else :
245
232
self ._out_of_process_execute (command )
246
233
247
234
if expect_failure and self .exit_code == 0 :
248
- raise AssertionError ('The command is expected to fail but it doesn\' .' )
235
+ logger .error ('Command "%s" => %d. (It did not fail as expected) Output: %s' , command ,
236
+ self .exit_code , self .output )
237
+ raise AssertionError ('The command did not fail as it was expected.' )
249
238
elif not expect_failure and self .exit_code != 0 :
239
+ logger .error ('Command "%s" => %d. Output: %s' , command , self .exit_code , self .output )
250
240
raise AssertionError ('The command failed. Exit code: {}' .format (self .exit_code ))
251
241
242
+ logger .info ('Command "%s" => %d.' , command , self .exit_code )
243
+
252
244
self .json_value = None
253
245
self .skip_assert = os .environ .get (ENV_SKIP_ASSERT , None ) == 'True'
254
246
@@ -260,8 +252,6 @@ def assert_with_checks(self, *args):
260
252
elif callable (each ):
261
253
checks .append (each )
262
254
263
- logger .info ('Checkers to be executed %s' , len (checks ))
264
-
265
255
if not self .skip_assert :
266
256
for c in checks :
267
257
c (self )
0 commit comments