Skip to content

Commit ee257ff

Browse files
rm failure
1 parent 234912e commit ee257ff

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

moler/cmd/unix/rm.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
"""
55

66
__author__ = 'Bartosz Odziomek, Marcin Usielski'
7-
__copyright__ = 'Copyright (C) 2018-2023, Nokia'
7+
__copyright__ = 'Copyright (C) 2018-2025, Nokia'
88
99

10-
from moler.cmd.unix.genericunix import GenericUnixCommand
11-
10+
from moler.helpers import copy_list
11+
from moler.cmd.unix.genericunix import GenericUnixCommand, cmd_failure_causes
12+
import re
1213

1314
class Rm(GenericUnixCommand):
1415
def __init__(self, connection, file, options=None, prompt=None, newline_chars=None, runner=None):
@@ -25,6 +26,11 @@ def __init__(self, connection, file, options=None, prompt=None, newline_chars=No
2526
self.file = file
2627
self.options = options
2728
self.ret_required = False
29+
_cmd_failure_causes = copy_list(cmd_failure_causes)
30+
_cmd_failure_causes.append(r"cannot remove\s*'.*':\s*Permission denied")
31+
r_cmd_failure_cause_alternatives = "|".join(_cmd_failure_causes)
32+
self.re_fail = re.compile(r_cmd_failure_cause_alternatives, re.IGNORECASE)
33+
2834

2935
def build_command_string(self):
3036
"""

test/cmd/unix/test_cmd_rm.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,31 @@
33
Rm command module.
44
"""
55

6-
__author__ = 'Bartosz Odziomek'
7-
__copyright__ = 'Copyright (C) 2018, Nokia'
8-
__email__ = '[email protected]'
6+
__author__ = 'Bartosz Odziomek, Marcin Usielski'
7+
__copyright__ = 'Copyright (C) 2018-2025, Nokia'
8+
99

1010

1111
def test_rm_returns_proper_command_string(buffer_connection):
1212
from moler.cmd.unix.rm import Rm
1313
rm_cmd = Rm(connection=buffer_connection.moler_connection, file="test.txt")
1414
assert "rm test.txt" == rm_cmd.command_string
1515

16+
17+
18+
def test_rm_permission_denied(buffer_connection):
19+
from moler.cmd.unix.rm import Rm
20+
from moler.exceptions import MolerException
21+
output = """rm protected.txt
22+
rm: cannot remove 'protected.txt': Permission denied
23+
cannot remove'.*': Permission denied
24+
moler_bash#"""
25+
26+
rm_cmd = Rm(connection=buffer_connection.moler_connection, file="protected.txt")
27+
buffer_connection.remote_inject_response([output])
28+
try:
29+
rm_cmd()
30+
except MolerException as exc:
31+
assert "Permission denied" in str(exc)
32+
else:
33+
assert False, "Exception not raised for permission denied"

0 commit comments

Comments
 (0)