# -------------------------------------------------------------------------
# This file is part of the MindStudio project.
# Copyright (c) 2025 Huawei Technologies Co.,Ltd.
#
# MindStudio is licensed under Mulan PSL v2.
# You can use this software according to the terms and conditions of the Mulan PSL v2.
# You may obtain a copy of Mulan PSL v2 at:
#
#          http://license.coscl.org.cn/MulanPSL2
#
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
# See the Mulan PSL v2 for more details.
# -------------------------------------------------------------------------

from unittest.mock import Mock, patch
import pytest

from ms_service_profiler.utils.check.rule import Rule


def test_rule_none():
    mock_checker = Mock()
    mock_checker.is_none.return_value = mock_checker

    with patch("ms_service_profiler.utils.check.rule.Checker", return_value=mock_checker):
        result = Rule.none()
        mock_checker.is_none.assert_called_once()
        assert result == mock_checker


def test_rule_path():
    mock_path_checker = Mock()
    with patch("ms_service_profiler.utils.check.rule.PathChecker", return_value=mock_path_checker):
        result = Rule.path()
        assert result == mock_path_checker


def test_rule_config_file():
    mock_path_checker = Mock()

    methods = ["exists", "is_file", "as_default"]
    for method in methods:
        getattr(mock_path_checker, method).return_value = mock_path_checker

    with patch("ms_service_profiler.utils.check.rule.PathChecker", return_value=mock_path_checker):
        Rule.config_file()

        mock_path_checker.exists.assert_called_once()
        mock_path_checker.is_file.assert_called_once()
        mock_path_checker.as_default.assert_called_once()


@pytest.mark.parametrize(
    "method_name, expected_args",
    [
        ("exists", ()),
        ("is_file", ()),
        ("as_default", ()),
    ],
)
def test_config_file_methods(method_name, expected_args):
    mock_path_checker = Mock()

    methods = ["exists", "is_file", "as_default"]
    for method in methods:
        getattr(mock_path_checker, method).return_value = mock_path_checker

    with patch("ms_service_profiler.utils.check.rule.PathChecker", return_value=mock_path_checker):
        Rule.config_file()
        getattr(mock_path_checker, method_name).assert_called_once_with(*expected_args)