Skip to content

Commit 8583b69

Browse files
committed
Test exception handling paths of long_running_operation result
Signed-off-by: mulhern <amulhern@redhat.com>
1 parent da3205e commit 8583b69

File tree

2 files changed

+62
-2
lines changed

2 files changed

+62
-2
lines changed

src/stratis_cli/_actions/_utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,12 +297,11 @@ def wrapper(namespace: Namespace):
297297
try:
298298
func(namespace)
299299
except DPClientInvocationError as err:
300-
# sim engine completes all operations rapidly
301300
if not any(
302301
isinstance(e, DBusException)
303302
and e.get_dbus_name() == "org.freedesktop.DBus.Error.NoReply"
304303
for e in get_errors(err)
305-
): # pragma: no cover
304+
):
306305
raise err
307306
print("Operation initiated", file=sys.stderr)
308307

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Copyright 2025 Red Hat, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
"""
15+
Test 'long_running_operation'.
16+
"""
17+
18+
# isort: STDLIB
19+
import unittest
20+
21+
# isort: THIRDPARTY
22+
import dbus
23+
24+
# isort: FIRSTPARTY
25+
from dbus_python_client_gen import DPClientInvocationError
26+
27+
# isort: LOCAL
28+
from stratis_cli._actions._utils import long_running_operation
29+
30+
31+
class LongRunningOperationTestCase(unittest.TestCase):
32+
"""
33+
Test long_running_operation error paths that don't show up in the sim
34+
engine.
35+
"""
36+
37+
def test_raise_dbus_exception(self):
38+
"""
39+
Should succeed because it catches the distinguishing NoReply D-Bus
40+
error.
41+
"""
42+
43+
def raises_error(_):
44+
raise DPClientInvocationError(
45+
"fake", "intf", None
46+
) from dbus.exceptions.DBusException(
47+
name="org.freedesktop.DBus.Error.NoReply"
48+
)
49+
50+
self.assertIsNone(long_running_operation(raises_error)(None))
51+
52+
def test_no_dbus_exception(self):
53+
"""
54+
Should raise an exception that was previously raised.
55+
"""
56+
57+
def raises_error(_):
58+
raise DPClientInvocationError("fake", "intf", None)
59+
60+
with self.assertRaises(DPClientInvocationError):
61+
long_running_operation(raises_error)(None)

0 commit comments

Comments
 (0)