@@ -41,9 +41,17 @@ def test_exec_command_failure(self):
41
41
try :
42
42
self .operations .exec_command (cmd , verbose = True , wait_exit = True )
43
43
except ExecUtilException as e :
44
- assert e .message == "Utility exited with non-zero code (127). Error: `bash: line 1: nonexistent_command: command not found`"
44
+ assert type (e .exit_code ) == int # noqa: E721
45
+ assert e .exit_code == 127
46
+
47
+ assert type (e .message ) == str # noqa: E721
45
48
assert type (e .error ) == bytes # noqa: E721
46
- assert e .error .strip () == b"bash: line 1: nonexistent_command: command not found"
49
+
50
+ assert e .message .startswith ("Utility exited with non-zero code (127). Error:" )
51
+ assert "nonexistent_command" in e .message
52
+ assert "not found" in e .message
53
+ assert b"nonexistent_command" in e .error
54
+ assert b"not found" in e .error
47
55
break
48
56
raise Exception ("We wait an exception!" )
49
57
@@ -55,9 +63,11 @@ def test_exec_command_failure__expect_error(self):
55
63
56
64
exit_status , result , error = self .operations .exec_command (cmd , verbose = True , wait_exit = True , shell = True , expect_error = True )
57
65
58
- assert error == b'bash: line 1: nonexistent_command: command not found\n '
59
66
assert exit_status == 127
60
67
assert result == b''
68
+ assert type (error ) == bytes # noqa: E721
69
+ assert b"nonexistent_command" in error
70
+ assert b"not found" in error
61
71
62
72
def test_is_executable_true (self ):
63
73
"""
@@ -344,11 +354,13 @@ def test_read__unknown_file(self):
344
354
Test RemoteOperations::read with unknown file.
345
355
"""
346
356
347
- with pytest .raises (
348
- ExecUtilException ,
349
- match = re .escape ("cat: /dummy: No such file or directory" )):
357
+ with pytest .raises (ExecUtilException ) as x :
350
358
self .operations .read ("/dummy" )
351
359
360
+ assert "Utility exited with non-zero code (1)." in str (x .value )
361
+ assert "No such file or directory" in str (x .value )
362
+ assert "/dummy" in str (x .value )
363
+
352
364
def test_read_binary__spec (self ):
353
365
"""
354
366
Test RemoteOperations::read_binary.
@@ -388,9 +400,13 @@ def test_read_binary__spec__unk_file(self):
388
400
Test RemoteOperations::read_binary with unknown file.
389
401
"""
390
402
391
- with pytest .raises (ExecUtilException , match = re . escape ( "tail: cannot open '/dummy' for reading: No such file or directory" )) :
403
+ with pytest .raises (ExecUtilException ) as x :
392
404
self .operations .read_binary ("/dummy" , 0 )
393
405
406
+ assert "Utility exited with non-zero code (1)." in str (x .value )
407
+ assert "No such file or directory" in str (x .value )
408
+ assert "/dummy" in str (x .value )
409
+
394
410
def test_read_binary__spec__negative_offset (self ):
395
411
"""
396
412
Test RemoteOperations::read_binary with negative offset.
@@ -419,9 +435,13 @@ def test_get_file_size__unk_file(self):
419
435
Test RemoteOperations::get_file_size.
420
436
"""
421
437
422
- with pytest .raises (ExecUtilException , match = re . escape ( "du: cannot access '/dummy': No such file or directory" )) :
438
+ with pytest .raises (ExecUtilException ) as x :
423
439
self .operations .get_file_size ("/dummy" )
424
440
441
+ assert "Utility exited with non-zero code (1)." in str (x .value )
442
+ assert "No such file or directory" in str (x .value )
443
+ assert "/dummy" in str (x .value )
444
+
425
445
def test_touch (self ):
426
446
"""
427
447
Test touch for creating a new file or updating access and modification times of an existing file.
0 commit comments