File: test_incus_cli.py

package info (click to toggle)
incant 0.5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 30,640 kB
  • sloc: python: 1,730; sh: 35; makefile: 10; ruby: 1
file content (28 lines) | stat: -rw-r--r-- 922 bytes parent folder | download
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