-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtest_incus_cli.py
More file actions
28 lines (22 loc) · 922 Bytes
/
test_incus_cli.py
File metadata and controls
28 lines (22 loc) · 922 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from unittest.mock import patch
from incant.incus_cli import IncusCLI
from incant.reporter import Reporter
class TestIncusCLI:
def test_constructor(self):
reporter = Reporter()
IncusCLI(reporter=reporter)
def test_shell_handles_nonzero_exit(self):
"""
Verify that incus shell is called with check=False to avoid raising exception on exit code.
"""
reporter = Reporter()
incus_cli = IncusCLI(reporter)
with patch("subprocess.run") as mock_run:
mock_run.return_value.returncode = 1
# This should not raise any exception and return the exit code
ret = incus_cli.shell("test-instance")
assert ret == 1
# Verify called arguments
args, kwargs = mock_run.call_args
assert args[0] == ["incus", "shell", "test-instance"]
assert kwargs.get("check") is False