aboutsummaryrefslogtreecommitdiff
path: root/tests/aiet/test_cli_common.py
blob: d018e44578b7f906b6f7847883d9766cf156f71e (plain)
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
29
30
31
32
33
34
35
36
37
# SPDX-FileCopyrightText: Copyright 2022, Arm Limited and/or its affiliates.
# SPDX-License-Identifier: Apache-2.0
"""Test for cli common module."""
from typing import Any

import pytest

from aiet.cli.common import print_command_details
from aiet.cli.common import raise_exception_at_signal


def test_print_command_details(capsys: Any) -> None:
    """Test print_command_details function."""
    command = {
        "command_strings": ["echo test"],
        "user_params": [
            {"name": "param_name", "description": "param_description"},
            {
                "name": "param_name2",
                "description": "param_description2",
                "alias": "alias2",
            },
        ],
    }
    print_command_details(command)
    captured = capsys.readouterr()
    assert "echo test" in captured.out
    assert "param_name" in captured.out
    assert "alias2" in captured.out


def test_raise_exception_at_signal() -> None:
    """Test raise_exception_at_signal graceful shutdown."""
    with pytest.raises(Exception) as err:
        raise_exception_at_signal(1, "")

    assert str(err.value) == "Middleware shutdown requested"