# -*- coding: utf-8 -*-
# ------------------------------------------------------------------------------
#
#   Copyright 2018-2019 Fetch.AI Limited
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.
#
# ------------------------------------------------------------------------------

"""This test module contains the tests for aea.cli.utils module."""

from builtins import FileNotFoundError
from typing import cast
from unittest import TestCase, mock

from click import BadParameter, ClickException

from jsonschema import ValidationError

from yaml import YAMLError

from aea.cli.utils.click_utils import AEAJsonPathType, PublicIdParameter
from aea.cli.utils.config import (
    _init_cli_config,
    get_or_create_cli_config,
    update_cli_config,
)
from aea.cli.utils.context import Context
from aea.cli.utils.decorators import _validate_config_consistency, clean_after
from aea.cli.utils.formatting import format_items
from aea.cli.utils.generic import is_readme_present
from aea.cli.utils.package_utils import (
    find_item_in_distribution,
    find_item_locally,
    is_fingerprint_correct,
    try_get_balance,
    try_get_item_source_path,
    try_get_item_target_path,
    validate_author_name,
    validate_package_name,
)

from tests.conftest import FETCHAI
from tests.test_cli.tools_for_testing import (
    ConfigLoaderMock,
    ContextMock,
    PublicIdMock,
    StopTest,
    raise_stoptest,
)

AUTHOR = "author"


class FormatItemsTestCase(TestCase):
    """Test case for format_items method."""

    def testformat_items_positive(self):
        """Test format_items positive result."""
        items = [
            {
                "public_id": "author/name:version",
                "name": "obj-name",
                "description": "Some description",
                "author": "author",
                "version": "1.0",
            }
        ]
        result = format_items(items)
        expected_result = (
            "------------------------------\n"
            "Public ID: author/name:version\n"
            "Name: obj-name\n"
            "Description: Some description\n"
            "Author: author\n"
            "Version: 1.0\n"
            "------------------------------\n"
        )
        self.assertEqual(result, expected_result)


@mock.patch("aea.cli.utils.package_utils.os.path.join", return_value="some-path")
class TryGetItemSourcePathTestCase(TestCase):
    """Test case for try_get_item_source_path method."""

    @mock.patch("aea.cli.utils.package_utils.os.path.exists", return_value=True)
    def test_get_item_source_path_positive(self, exists_mock, join_mock):
        """Test for get_item_source_path positive result."""
        result = try_get_item_source_path("cwd", AUTHOR, "skills", "skill-name")
        expected_result = "some-path"
        self.assertEqual(result, expected_result)
        join_mock.assert_called_once_with("cwd", AUTHOR, "skills", "skill-name")
        exists_mock.assert_called_once_with("some-path")

        result = try_get_item_source_path("cwd", None, "skills", "skill-name")
        self.assertEqual(result, expected_result)

    @mock.patch("aea.cli.utils.package_utils.os.path.exists", return_value=False)
    def test_get_item_source_path_not_exists(self, exists_mock, join_mock):
        """Test for get_item_source_path item already exists."""
        with self.assertRaises(ClickException):
            try_get_item_source_path("cwd", AUTHOR, "skills", "skill-name")


@mock.patch("aea.cli.utils.package_utils.os.path.join", return_value="some-path")
class TryGetItemTargetPathTestCase(TestCase):
    """Test case for try_get_item_target_path method."""

    @mock.patch("aea.cli.utils.package_utils.os.path.exists", return_value=False)
    def test_get_item_target_path_positive(self, exists_mock, join_mock):
        """Test for get_item_source_path positive result."""
        result = try_get_item_target_path("packages", AUTHOR, "skills", "skill-name")
        expected_result = "some-path"
        self.assertEqual(result, expected_result)
        join_mock.assert_called_once_with("packages", AUTHOR, "skills", "skill-name")
        exists_mock.assert_called_once_with("some-path")

    @mock.patch("aea.cli.utils.package_utils.os.path.exists", return_value=True)
    def test_get_item_target_path_already_exists(self, exists_mock, join_mock):
        """Test for get_item_target_path item already exists."""
        with self.assertRaises(ClickException):
            try_get_item_target_path("skills", AUTHOR, "skill-name", "packages_path")


class PublicIdParameterTestCase(TestCase):
    """Test case for PublicIdParameter class."""

    def test_get_metavar_positive(self):
        """Test for get_metavar positive result."""
        result = PublicIdParameter.get_metavar("obj", "param")
        expected_result = "PUBLIC_ID"
        self.assertEqual(result, expected_result)


@mock.patch("aea.cli.utils.config.os.path.dirname", return_value="dir-name")
@mock.patch("aea.cli.utils.config.os.path.exists", return_value=False)
@mock.patch("aea.cli.utils.config.os.makedirs")
@mock.patch("builtins.open")
class InitConfigFolderTestCase(TestCase):
    """Test case for _init_cli_config method."""

    def test_init_cli_config_positive(
        self, open_mock, makedirs_mock, exists_mock, dirname_mock
    ):
        """Test for _init_cli_config method positive result."""
        _init_cli_config()
        dirname_mock.assert_called_once()
        exists_mock.assert_called_once_with("dir-name")
        makedirs_mock.assert_called_once_with("dir-name")


@mock.patch("aea.cli.utils.config.get_or_create_cli_config")
@mock.patch("aea.cli.utils.generic.yaml.dump")
@mock.patch("builtins.open", mock.mock_open())
class UpdateCLIConfigTestCase(TestCase):
    """Test case for update_cli_config method."""

    def testupdate_cli_config_positive(self, dump_mock, icf_mock):
        """Test for update_cli_config method positive result."""
        update_cli_config({"some": "config"})
        icf_mock.assert_called_once()
        dump_mock.assert_called_once()


def _raise_yamlerror(*args):
    raise YAMLError()


def _raise_file_not_found_error(*args):
    raise FileNotFoundError()


@mock.patch("builtins.open", mock.mock_open())
class GetOrCreateCLIConfigTestCase(TestCase):
    """Test case for read_cli_config method."""

    @mock.patch(
        "aea.cli.utils.generic.yaml.safe_load", return_value={"correct": "output"}
    )
    def testget_or_create_cli_config_positive(self, safe_load_mock):
        """Test for get_or_create_cli_config method positive result."""
        result = get_or_create_cli_config()
        expected_result = {"correct": "output"}
        self.assertEqual(result, expected_result)
        safe_load_mock.assert_called_once()

    @mock.patch("aea.cli.utils.generic.yaml.safe_load", _raise_yamlerror)
    def testget_or_create_cli_config_bad_yaml(self):
        """Test for rget_or_create_cli_config method bad yaml behavior."""
        with self.assertRaises(ClickException):
            get_or_create_cli_config()


class CleanAfterTestCase(TestCase):
    """Test case for clean_after decorator method."""

    @mock.patch("aea.cli.utils.decorators.os.path.exists", return_value=True)
    @mock.patch("aea.cli.utils.decorators._cast_ctx", lambda x: x)
    @mock.patch("aea.cli.utils.decorators.shutil.rmtree")
    def test_clean_after_positive(self, rmtree_mock, *mocks):
        """Test clean_after decorator method for positive result."""

        @clean_after
        def func(click_context):
            ctx = cast(Context, click_context.obj)
            ctx.clean_paths.append("clean/path")
            raise ClickException("Message")

        with self.assertRaises(ClickException):
            func(ContextMock())
            rmtree_mock.assert_called_once_with("clean/path")


@mock.patch("aea.cli.utils.package_utils.click.echo", raise_stoptest)
class ValidateAuthorNameTestCase(TestCase):
    """Test case for validate_author_name method."""

    @mock.patch(
        "aea.cli.utils.package_utils.click.prompt", return_value="correct_author"
    )
    def test_validate_author_name_positive(self, prompt_mock):
        """Test validate_author_name for positive result."""
        author = "valid_author"
        result = validate_author_name(author=author)
        self.assertEqual(result, author)

        result = validate_author_name()
        self.assertEqual(result, "correct_author")
        prompt_mock.assert_called_once()

    @mock.patch(
        "aea.cli.utils.package_utils.click.prompt", return_value="inv@l1d_@uth&r"
    )
    def test_validate_author_name_negative(self, prompt_mock):
        """Test validate_author_name for negative result."""
        with self.assertRaises(StopTest):
            validate_author_name()

        prompt_mock.return_value = "skills"
        with self.assertRaises(StopTest):
            validate_author_name()


class ValidatePackageNameTestCase(TestCase):
    """Test case for validate_package_name method."""

    def test_validate_package_name_positive(self):
        """Test validate_package_name for positive result."""
        validate_package_name("correct_name")

    def test_validate_package_name_negative(self):
        """Test validate_package_name for negative result."""
        with self.assertRaises(BadParameter):
            validate_package_name("incorrect-name")


def _raise_validation_error(*args, **kwargs):
    raise ValidationError("Message.")


class FindItemLocallyTestCase(TestCase):
    """Test case for find_item_locally method."""

    @mock.patch("aea.cli.utils.package_utils.Path.exists", return_value=True)
    @mock.patch(
        "aea.cli.utils.package_utils.ConfigLoader.from_configuration_type",
        _raise_validation_error,
    )
    def test_find_item_locally_bad_config(self, *mocks):
        """Test find_item_locally for bad config result."""
        public_id = PublicIdMock.from_str("fetchai/echo:0.5.0")
        with self.assertRaises(ClickException) as cm:
            find_item_locally(ContextMock(), "skill", public_id)

        self.assertIn("configuration file not valid", cm.exception.message)

    @mock.patch("aea.cli.utils.package_utils.Path.exists", return_value=True)
    @mock.patch("aea.cli.utils.package_utils.Path.open", mock.mock_open())
    @mock.patch(
        "aea.cli.utils.package_utils.ConfigLoader.from_configuration_type",
        return_value=ConfigLoaderMock(),
    )
    def test_find_item_locally_cant_find(self, from_conftype_mock, *mocks):
        """Test find_item_locally for can't find result."""
        public_id = PublicIdMock.from_str("fetchai/echo:0.5.0")
        with self.assertRaises(ClickException) as cm:
            find_item_locally(ContextMock(), "skill", public_id)

        self.assertEqual(
            cm.exception.message, "Cannot find skill with author and version specified."
        )


class FindItemInDistributionTestCase(TestCase):
    """Test case for find_item_in_distribution method."""

    @mock.patch("aea.cli.utils.package_utils.Path.exists", return_value=True)
    @mock.patch(
        "aea.cli.utils.package_utils.ConfigLoader.from_configuration_type",
        _raise_validation_error,
    )
    def testfind_item_in_distribution_bad_config(self, *mocks):
        """Test find_item_in_distribution for bad config result."""
        public_id = PublicIdMock.from_str("fetchai/echo:0.5.0")
        with self.assertRaises(ClickException) as cm:
            find_item_in_distribution(ContextMock(), "skill", public_id)

        self.assertIn("configuration file not valid", cm.exception.message)

    @mock.patch("aea.cli.utils.package_utils.Path.exists", return_value=False)
    def testfind_item_in_distribution_not_found(self, *mocks):
        """Test find_item_in_distribution for not found result."""
        public_id = PublicIdMock.from_str("fetchai/echo:0.5.0")
        with self.assertRaises(ClickException) as cm:
            find_item_in_distribution(ContextMock(), "skill", public_id)

        self.assertIn("Cannot find skill", cm.exception.message)

    @mock.patch("aea.cli.utils.package_utils.Path.exists", return_value=True)
    @mock.patch("aea.cli.utils.package_utils.Path.open", mock.mock_open())
    @mock.patch(
        "aea.cli.utils.package_utils.ConfigLoader.from_configuration_type",
        return_value=ConfigLoaderMock(),
    )
    def testfind_item_in_distribution_cant_find(self, from_conftype_mock, *mocks):
        """Test find_item_locally for can't find result."""
        public_id = PublicIdMock.from_str("fetchai/echo:0.5.0")
        with self.assertRaises(ClickException) as cm:
            find_item_in_distribution(ContextMock(), "skill", public_id)

        self.assertEqual(
            cm.exception.message, "Cannot find skill with author and version specified."
        )


class ValidateConfigConsistencyTestCase(TestCase):
    """Test case for _validate_config_consistency method."""

    @mock.patch("aea.cli.utils.config.Path.exists", _raise_validation_error)
    def test__validate_config_consistency_cant_find(self, *mocks):
        """Test _validate_config_consistency can't find result"""
        with self.assertRaises(ValueError) as cm:
            _validate_config_consistency(ContextMock(protocols=["some"]))

        self.assertIn("Cannot find", str(cm.exception))


@mock.patch(
    "aea.cli.utils.package_utils._compute_fingerprint",
    return_value={"correct": "fingerprint"},
)
class IsFingerprintCorrectTestCase(TestCase):
    """Test case for adding skill with invalid fingerprint."""

    def test_is_fingerprint_correct_positive(self, *mocks):
        """Test is_fingerprint_correct method for positive result."""
        item_config = mock.Mock()
        item_config.fingerprint = {"correct": "fingerprint"}
        item_config.fingerprint_ignore_patterns = []
        result = is_fingerprint_correct("package_path", item_config)
        self.assertTrue(result)

    def test_is_fingerprint_correct_negative(self, *mocks):
        """Test is_fingerprint_correct method for negative result."""
        item_config = mock.Mock()
        item_config.fingerprint = {"incorrect": "fingerprint"}
        item_config.fingerprint_ignore_patterns = []
        package_path = "package_dir"
        result = is_fingerprint_correct(package_path, item_config)
        self.assertFalse(result)


@mock.patch("aea.cli.config.click.ParamType")
class AEAJsonPathTypeTestCase(TestCase):
    """Test case for AEAJsonPathType class."""

    @mock.patch("aea.cli.utils.click_utils.Path.exists", return_value=True)
    def test_convert_root_vendor_positive(self, *mocks):
        """Test for convert method with root "vendor" positive result."""
        value = "vendor.author.protocols.package_name.attribute_name"
        ctx_mock = ContextMock()
        ctx_mock.obj = mock.Mock()
        ctx_mock.obj.set_config = mock.Mock()
        obj = AEAJsonPathType()
        obj.convert(value, "param", ctx_mock)

    @mock.patch("aea.cli.utils.click_utils.Path.exists", return_value=False)
    def test_convert_root_vendor_path_not_exists(self, *mocks):
        """Test for convert method with root "vendor" path not exists."""
        value = "vendor.author.protocols.package_name.attribute_name"
        obj = AEAJsonPathType()
        with self.assertRaises(BadParameter):
            obj.convert(value, "param", "ctx")


@mock.patch("aea.cli.utils.package_utils.LedgerApis", mock.MagicMock())
class TryGetBalanceTestCase(TestCase):
    """Test case for try_get_balance method."""

    def test_try_get_balance_positive(self):
        """Test for try_get_balance method positive result."""
        agent_config = mock.Mock()
        agent_config.default_ledger_config = FETCHAI

        wallet_mock = mock.Mock()
        wallet_mock.addresses = {FETCHAI: "some-adress"}
        try_get_balance(agent_config, wallet_mock, FETCHAI)


@mock.patch("aea.cli.utils.generic.os.path.exists", return_value=True)
class IsReadmePresentTestCase(TestCase):
    """Test case for is_readme_present method."""

    def test_is_readme_present_positive(self, *mocks):
        """Test is_readme_present for positive result."""
        self.assertTrue(is_readme_present("readme/path"))

[((92, 1, 92, 81), 'unittest.mock.patch', 'mock.patch', (), '', False, 'from unittest import TestCase, mock\n'), ((115, 1, 115, 81), 'unittest.mock.patch', 'mock.patch', (), '', False, 'from unittest import TestCase, mock\n'), ((145, 1, 145, 76), 'unittest.mock.patch', 'mock.patch', (), '', False, 'from unittest import TestCase, mock\n'), ((146, 1, 146, 70), 'unittest.mock.patch', 'mock.patch', (), '', False, 'from unittest import TestCase, mock\n'), ((147, 1, 147, 47), 'unittest.mock.patch', 'mock.patch', ({(147, 12, 147, 46): '"""aea.cli.utils.config.os.makedirs"""'}, {}), "('aea.cli.utils.config.os.makedirs')", False, 'from unittest import TestCase, mock\n'), ((148, 1, 148, 28), 'unittest.mock.patch', 'mock.patch', ({(148, 12, 148, 27): '"""builtins.open"""'}, {}), "('builtins.open')", False, 'from unittest import TestCase, mock\n'), ((162, 1, 162, 60), 'unittest.mock.patch', 'mock.patch', ({(162, 12, 162, 59): '"""aea.cli.utils.config.get_or_create_cli_config"""'}, {}), "('aea.cli.utils.config.get_or_create_cli_config')", False, 'from unittest import TestCase, mock\n'), ((163, 1, 163, 46), 'unittest.mock.patch', 'mock.patch', ({(163, 12, 163, 45): '"""aea.cli.utils.generic.yaml.dump"""'}, {}), "('aea.cli.utils.generic.yaml.dump')", False, 'from unittest import TestCase, mock\n'), ((224, 1, 224, 69), 'unittest.mock.patch', 'mock.patch', ({(224, 12, 224, 52): '"""aea.cli.utils.package_utils.click.echo"""', (224, 54, 224, 68): 'raise_stoptest'}, {}), "('aea.cli.utils.package_utils.click.echo', raise_stoptest)", False, 'from unittest import TestCase, mock\n'), ((358, 1, 361, 1), 'unittest.mock.patch', 'mock.patch', (), '', False, 'from unittest import TestCase, mock\n'), ((383, 1, 383, 45), 'unittest.mock.patch', 'mock.patch', ({(383, 12, 383, 44): '"""aea.cli.config.click.ParamType"""'}, {}), "('aea.cli.config.click.ParamType')", False, 'from unittest import TestCase, mock\n'), ((420, 1, 420, 70), 'unittest.mock.patch', 'mock.patch', (), '', False, 'from unittest import TestCase, mock\n'), ((96, 5, 96, 80), 'unittest.mock.patch', 'mock.patch', (), '', False, 'from unittest import TestCase, mock\n'), ((108, 5, 108, 81), 'unittest.mock.patch', 'mock.patch', (), '', False, 'from unittest import TestCase, mock\n'), ((119, 5, 119, 81), 'unittest.mock.patch', 'mock.patch', (), '', False, 'from unittest import TestCase, mock\n'), ((128, 5, 128, 80), 'unittest.mock.patch', 'mock.patch', (), '', False, 'from unittest import TestCase, mock\n'), ((164, 29, 164, 45), 'unittest.mock.mock_open', 'mock.mock_open', ({}, {}), '()', False, 'from unittest import TestCase, mock\n'), ((176, 10, 176, 21), 'yaml.YAMLError', 'YAMLError', ({}, {}), '()', False, 'from yaml import YAMLError\n'), ((180, 10, 180, 29), 'builtins.FileNotFoundError', 'FileNotFoundError', ({}, {}), '()', False, 'from builtins import FileNotFoundError\n'), ((187, 5, 189, 5), 'unittest.mock.patch', 'mock.patch', (), '', False, 'from unittest import TestCase, mock\n'), ((197, 5, 197, 73), 'unittest.mock.patch', 'mock.patch', ({(197, 16, 197, 54): '"""aea.cli.utils.generic.yaml.safe_load"""', (197, 56, 197, 72): '_raise_yamlerror'}, {}), "('aea.cli.utils.generic.yaml.safe_load', _raise_yamlerror)", False, 'from unittest import TestCase, mock\n'), ((183, 29, 183, 45), 'unittest.mock.mock_open', 'mock.mock_open', ({}, {}), '()', False, 'from unittest import TestCase, mock\n'), ((207, 5, 207, 77), 'unittest.mock.patch', 'mock.patch', (), '', False, 'from unittest import TestCase, mock\n'), ((208, 5, 208, 66), 'unittest.mock.patch', 'mock.patch', ({(208, 16, 208, 52): '"""aea.cli.utils.decorators._cast_ctx"""', (208, 54, 208, 65): '(lambda x: x)'}, {}), "('aea.cli.utils.decorators._cast_ctx', lambda x: x)", False, 'from unittest import TestCase, mock\n'), ((209, 5, 209, 57), 'unittest.mock.patch', 'mock.patch', ({(209, 16, 209, 56): '"""aea.cli.utils.decorators.shutil.rmtree"""'}, {}), "('aea.cli.utils.decorators.shutil.rmtree')", False, 'from unittest import TestCase, mock\n'), ((228, 5, 230, 5), 'unittest.mock.patch', 'mock.patch', (), '', False, 'from unittest import TestCase, mock\n'), ((241, 5, 243, 5), 'unittest.mock.patch', 'mock.patch', (), '', False, 'from unittest import TestCase, mock\n'), ((268, 10, 268, 37), 'jsonschema.ValidationError', 'ValidationError', ({(268, 26, 268, 36): '"""Message."""'}, {}), "('Message.')", False, 'from jsonschema import ValidationError\n'), ((274, 5, 274, 77), 'unittest.mock.patch', 'mock.patch', (), '', False, 'from unittest import TestCase, mock\n'), ((275, 5, 278, 5), 'unittest.mock.patch', 'mock.patch', ({(276, 8, 276, 74): '"""aea.cli.utils.package_utils.ConfigLoader.from_configuration_type"""', (277, 8, 277, 31): '_raise_validation_error'}, {}), "('aea.cli.utils.package_utils.ConfigLoader.from_configuration_type',\n    _raise_validation_error)", False, 'from unittest import TestCase, mock\n'), ((287, 5, 287, 77), 'unittest.mock.patch', 'mock.patch', (), '', False, 'from unittest import TestCase, mock\n'), ((307, 5, 307, 77), 'unittest.mock.patch', 'mock.patch', (), '', False, 'from unittest import TestCase, mock\n'), ((308, 5, 311, 5), 'unittest.mock.patch', 'mock.patch', ({(309, 8, 309, 74): '"""aea.cli.utils.package_utils.ConfigLoader.from_configuration_type"""', (310, 8, 310, 31): '_raise_validation_error'}, {}), "('aea.cli.utils.package_utils.ConfigLoader.from_configuration_type',\n    _raise_validation_error)", False, 'from unittest import TestCase, mock\n'), ((320, 5, 320, 78), 'unittest.mock.patch', 'mock.patch', (), '', False, 'from unittest import TestCase, mock\n'), ((329, 5, 329, 77), 'unittest.mock.patch', 'mock.patch', (), '', False, 'from unittest import TestCase, mock\n'), ((349, 5, 349, 76), 'unittest.mock.patch', 'mock.patch', ({(349, 16, 349, 50): '"""aea.cli.utils.config.Path.exists"""', (349, 52, 349, 75): '_raise_validation_error'}, {}), "('aea.cli.utils.config.Path.exists', _raise_validation_error)", False, 'from unittest import TestCase, mock\n'), ((387, 5, 387, 75), 'unittest.mock.patch', 'mock.patch', (), '', False, 'from unittest import TestCase, mock\n'), ((397, 5, 397, 76), 'unittest.mock.patch', 'mock.patch', (), '', False, 'from unittest import TestCase, mock\n'), ((406, 54, 406, 70), 'unittest.mock.MagicMock', 'mock.MagicMock', ({}, {}), '()', False, 'from unittest import TestCase, mock\n'), ((79, 17, 79, 36), 'aea.cli.utils.formatting.format_items', 'format_items', ({(79, 30, 79, 35): 'items'}, {}), '(items)', False, 'from aea.cli.utils.formatting import format_items\n'), ((99, 17, 99, 80), 'aea.cli.utils.package_utils.try_get_item_source_path', 'try_get_item_source_path', ({(99, 42, 99, 47): '"""cwd"""', (99, 49, 99, 55): 'AUTHOR', (99, 57, 99, 65): '"""skills"""', (99, 67, 99, 79): '"""skill-name"""'}, {}), "('cwd', AUTHOR, 'skills', 'skill-name')", False, 'from aea.cli.utils.package_utils import find_item_in_distribution, find_item_locally, is_fingerprint_correct, try_get_balance, try_get_item_source_path, try_get_item_target_path, validate_author_name, validate_package_name\n'), ((105, 17, 105, 78), 'aea.cli.utils.package_utils.try_get_item_source_path', 'try_get_item_source_path', ({(105, 42, 105, 47): '"""cwd"""', (105, 49, 105, 53): 'None', (105, 55, 105, 63): '"""skills"""', (105, 65, 105, 77): '"""skill-name"""'}, {}), "('cwd', None, 'skills', 'skill-name')", False, 'from aea.cli.utils.package_utils import find_item_in_distribution, find_item_locally, is_fingerprint_correct, try_get_balance, try_get_item_source_path, try_get_item_target_path, validate_author_name, validate_package_name\n'), ((122, 17, 122, 85), 'aea.cli.utils.package_utils.try_get_item_target_path', 'try_get_item_target_path', ({(122, 42, 122, 52): '"""packages"""', (122, 54, 122, 60): 'AUTHOR', (122, 62, 122, 70): '"""skills"""', (122, 72, 122, 84): '"""skill-name"""'}, {}), "('packages', AUTHOR, 'skills', 'skill-name')", False, 'from aea.cli.utils.package_utils import find_item_in_distribution, find_item_locally, is_fingerprint_correct, try_get_balance, try_get_item_source_path, try_get_item_target_path, validate_author_name, validate_package_name\n'), ((140, 17, 140, 62), 'aea.cli.utils.click_utils.PublicIdParameter.get_metavar', 'PublicIdParameter.get_metavar', ({(140, 47, 140, 52): '"""obj"""', (140, 54, 140, 61): '"""param"""'}, {}), "('obj', 'param')", False, 'from aea.cli.utils.click_utils import AEAJsonPathType, PublicIdParameter\n'), ((156, 8, 156, 26), 'aea.cli.utils.config._init_cli_config', '_init_cli_config', ({}, {}), '()', False, 'from aea.cli.utils.config import _init_cli_config, get_or_create_cli_config, update_cli_config\n'), ((170, 8, 170, 45), 'aea.cli.utils.config.update_cli_config', 'update_cli_config', ({(170, 26, 170, 44): "{'some': 'config'}"}, {}), "({'some': 'config'})", False, 'from aea.cli.utils.config import _init_cli_config, get_or_create_cli_config, update_cli_config\n'), ((192, 17, 192, 43), 'aea.cli.utils.config.get_or_create_cli_config', 'get_or_create_cli_config', ({}, {}), '()', False, 'from aea.cli.utils.config import _init_cli_config, get_or_create_cli_config, update_cli_config\n'), ((234, 17, 234, 52), 'aea.cli.utils.package_utils.validate_author_name', 'validate_author_name', (), '', False, 'from aea.cli.utils.package_utils import find_item_in_distribution, find_item_locally, is_fingerprint_correct, try_get_balance, try_get_item_source_path, try_get_item_target_path, validate_author_name, validate_package_name\n'), ((237, 17, 237, 39), 'aea.cli.utils.package_utils.validate_author_name', 'validate_author_name', ({}, {}), '()', False, 'from aea.cli.utils.package_utils import find_item_in_distribution, find_item_locally, is_fingerprint_correct, try_get_balance, try_get_item_source_path, try_get_item_target_path, validate_author_name, validate_package_name\n'), ((259, 8, 259, 45), 'aea.cli.utils.package_utils.validate_package_name', 'validate_package_name', ({(259, 30, 259, 44): '"""correct_name"""'}, {}), "('correct_name')", False, 'from aea.cli.utils.package_utils import find_item_in_distribution, find_item_locally, is_fingerprint_correct, try_get_balance, try_get_item_source_path, try_get_item_target_path, validate_author_name, validate_package_name\n'), ((281, 20, 281, 63), 'tests.test_cli.tools_for_testing.PublicIdMock.from_str', 'PublicIdMock.from_str', ({(281, 42, 281, 62): '"""fetchai/echo:0.5.0"""'}, {}), "('fetchai/echo:0.5.0')", False, 'from tests.test_cli.tools_for_testing import ConfigLoaderMock, ContextMock, PublicIdMock, StopTest, raise_stoptest\n'), ((295, 20, 295, 63), 'tests.test_cli.tools_for_testing.PublicIdMock.from_str', 'PublicIdMock.from_str', ({(295, 42, 295, 62): '"""fetchai/echo:0.5.0"""'}, {}), "('fetchai/echo:0.5.0')", False, 'from tests.test_cli.tools_for_testing import ConfigLoaderMock, ContextMock, PublicIdMock, StopTest, raise_stoptest\n'), ((288, 57, 288, 73), 'unittest.mock.mock_open', 'mock.mock_open', ({}, {}), '()', False, 'from unittest import TestCase, mock\n'), ((314, 20, 314, 63), 'tests.test_cli.tools_for_testing.PublicIdMock.from_str', 'PublicIdMock.from_str', ({(314, 42, 314, 62): '"""fetchai/echo:0.5.0"""'}, {}), "('fetchai/echo:0.5.0')", False, 'from tests.test_cli.tools_for_testing import ConfigLoaderMock, ContextMock, PublicIdMock, StopTest, raise_stoptest\n'), ((323, 20, 323, 63), 'tests.test_cli.tools_for_testing.PublicIdMock.from_str', 'PublicIdMock.from_str', ({(323, 42, 323, 62): '"""fetchai/echo:0.5.0"""'}, {}), "('fetchai/echo:0.5.0')", False, 'from tests.test_cli.tools_for_testing import ConfigLoaderMock, ContextMock, PublicIdMock, StopTest, raise_stoptest\n'), ((337, 20, 337, 63), 'tests.test_cli.tools_for_testing.PublicIdMock.from_str', 'PublicIdMock.from_str', ({(337, 42, 337, 62): '"""fetchai/echo:0.5.0"""'}, {}), "('fetchai/echo:0.5.0')", False, 'from tests.test_cli.tools_for_testing import ConfigLoaderMock, ContextMock, PublicIdMock, StopTest, raise_stoptest\n'), ((330, 57, 330, 73), 'unittest.mock.mock_open', 'mock.mock_open', ({}, {}), '()', False, 'from unittest import TestCase, mock\n'), ((367, 22, 367, 33), 'unittest.mock.Mock', 'mock.Mock', ({}, {}), '()', False, 'from unittest import TestCase, mock\n'), ((370, 17, 370, 68), 'aea.cli.utils.package_utils.is_fingerprint_correct', 'is_fingerprint_correct', ({(370, 40, 370, 54): '"""package_path"""', (370, 56, 370, 67): 'item_config'}, {}), "('package_path', item_config)", False, 'from aea.cli.utils.package_utils import find_item_in_distribution, find_item_locally, is_fingerprint_correct, try_get_balance, try_get_item_source_path, try_get_item_target_path, validate_author_name, validate_package_name\n'), ((375, 22, 375, 33), 'unittest.mock.Mock', 'mock.Mock', ({}, {}), '()', False, 'from unittest import TestCase, mock\n'), ((379, 17, 379, 66), 'aea.cli.utils.package_utils.is_fingerprint_correct', 'is_fingerprint_correct', ({(379, 40, 379, 52): 'package_path', (379, 54, 379, 65): 'item_config'}, {}), '(package_path, item_config)', False, 'from aea.cli.utils.package_utils import find_item_in_distribution, find_item_locally, is_fingerprint_correct, try_get_balance, try_get_item_source_path, try_get_item_target_path, validate_author_name, validate_package_name\n'), ((391, 19, 391, 32), 'tests.test_cli.tools_for_testing.ContextMock', 'ContextMock', ({}, {}), '()', False, 'from tests.test_cli.tools_for_testing import ConfigLoaderMock, ContextMock, PublicIdMock, StopTest, raise_stoptest\n'), ((392, 23, 392, 34), 'unittest.mock.Mock', 'mock.Mock', ({}, {}), '()', False, 'from unittest import TestCase, mock\n'), ((393, 34, 393, 45), 'unittest.mock.Mock', 'mock.Mock', ({}, {}), '()', False, 'from unittest import TestCase, mock\n'), ((394, 14, 394, 31), 'aea.cli.utils.click_utils.AEAJsonPathType', 'AEAJsonPathType', ({}, {}), '()', False, 'from aea.cli.utils.click_utils import AEAJsonPathType, PublicIdParameter\n'), ((401, 14, 401, 31), 'aea.cli.utils.click_utils.AEAJsonPathType', 'AEAJsonPathType', ({}, {}), '()', False, 'from aea.cli.utils.click_utils import AEAJsonPathType, PublicIdParameter\n'), ((412, 23, 412, 34), 'unittest.mock.Mock', 'mock.Mock', ({}, {}), '()', False, 'from unittest import TestCase, mock\n'), ((415, 22, 415, 33), 'unittest.mock.Mock', 'mock.Mock', ({}, {}), '()', False, 'from unittest import TestCase, mock\n'), ((417, 8, 417, 59), 'aea.cli.utils.package_utils.try_get_balance', 'try_get_balance', ({(417, 24, 417, 36): 'agent_config', (417, 38, 417, 49): 'wallet_mock', (417, 51, 417, 58): 'FETCHAI'}, {}), '(agent_config, wallet_mock, FETCHAI)', False, 'from aea.cli.utils.package_utils import find_item_in_distribution, find_item_locally, is_fingerprint_correct, try_get_balance, try_get_item_source_path, try_get_item_target_path, validate_author_name, validate_package_name\n'), ((112, 12, 112, 75), 'aea.cli.utils.package_utils.try_get_item_source_path', 'try_get_item_source_path', ({(112, 37, 112, 42): '"""cwd"""', (112, 44, 112, 50): 'AUTHOR', (112, 52, 112, 60): '"""skills"""', (112, 62, 112, 74): '"""skill-name"""'}, {}), "('cwd', AUTHOR, 'skills', 'skill-name')", False, 'from aea.cli.utils.package_utils import find_item_in_distribution, find_item_locally, is_fingerprint_correct, try_get_balance, try_get_item_source_path, try_get_item_target_path, validate_author_name, validate_package_name\n'), ((132, 12, 132, 85), 'aea.cli.utils.package_utils.try_get_item_target_path', 'try_get_item_target_path', ({(132, 37, 132, 45): '"""skills"""', (132, 47, 132, 53): 'AUTHOR', (132, 55, 132, 67): '"""skill-name"""', (132, 69, 132, 84): '"""packages_path"""'}, {}), "('skills', AUTHOR, 'skill-name', 'packages_path')", False, 'from aea.cli.utils.package_utils import find_item_in_distribution, find_item_locally, is_fingerprint_correct, try_get_balance, try_get_item_source_path, try_get_item_target_path, validate_author_name, validate_package_name\n'), ((201, 12, 201, 38), 'aea.cli.utils.config.get_or_create_cli_config', 'get_or_create_cli_config', ({}, {}), '()', False, 'from aea.cli.utils.config import _init_cli_config, get_or_create_cli_config, update_cli_config\n'), ((215, 18, 215, 50), 'typing.cast', 'cast', ({(215, 23, 215, 30): 'Context', (215, 32, 215, 49): 'click_context.obj'}, {}), '(Context, click_context.obj)', False, 'from typing import cast\n'), ((217, 18, 217, 43), 'click.ClickException', 'ClickException', ({(217, 33, 217, 42): '"""Message"""'}, {}), "('Message')", False, 'from click import BadParameter, ClickException\n'), ((247, 12, 247, 34), 'aea.cli.utils.package_utils.validate_author_name', 'validate_author_name', ({}, {}), '()', False, 'from aea.cli.utils.package_utils import find_item_in_distribution, find_item_locally, is_fingerprint_correct, try_get_balance, try_get_item_source_path, try_get_item_target_path, validate_author_name, validate_package_name\n'), ((251, 12, 251, 34), 'aea.cli.utils.package_utils.validate_author_name', 'validate_author_name', ({}, {}), '()', False, 'from aea.cli.utils.package_utils import find_item_in_distribution, find_item_locally, is_fingerprint_correct, try_get_balance, try_get_item_source_path, try_get_item_target_path, validate_author_name, validate_package_name\n'), ((264, 12, 264, 51), 'aea.cli.utils.package_utils.validate_package_name', 'validate_package_name', ({(264, 34, 264, 50): '"""incorrect-name"""'}, {}), "('incorrect-name')", False, 'from aea.cli.utils.package_utils import find_item_in_distribution, find_item_locally, is_fingerprint_correct, try_get_balance, try_get_item_source_path, try_get_item_target_path, validate_author_name, validate_package_name\n'), ((291, 21, 291, 39), 'tests.test_cli.tools_for_testing.ConfigLoaderMock', 'ConfigLoaderMock', ({}, {}), '()', False, 'from tests.test_cli.tools_for_testing import ConfigLoaderMock, ContextMock, PublicIdMock, StopTest, raise_stoptest\n'), ((333, 21, 333, 39), 'tests.test_cli.tools_for_testing.ConfigLoaderMock', 'ConfigLoaderMock', ({}, {}), '()', False, 'from tests.test_cli.tools_for_testing import ConfigLoaderMock, ContextMock, PublicIdMock, StopTest, raise_stoptest\n'), ((426, 24, 426, 56), 'aea.cli.utils.generic.is_readme_present', 'is_readme_present', ({(426, 42, 426, 55): '"""readme/path"""'}, {}), "('readme/path')", False, 'from aea.cli.utils.generic import is_readme_present\n'), ((220, 17, 220, 30), 'tests.test_cli.tools_for_testing.ContextMock', 'ContextMock', ({}, {}), '()', False, 'from tests.test_cli.tools_for_testing import ConfigLoaderMock, ContextMock, PublicIdMock, StopTest, raise_stoptest\n'), ((283, 30, 283, 43), 'tests.test_cli.tools_for_testing.ContextMock', 'ContextMock', ({}, {}), '()', False, 'from tests.test_cli.tools_for_testing import ConfigLoaderMock, ContextMock, PublicIdMock, StopTest, raise_stoptest\n'), ((297, 30, 297, 43), 'tests.test_cli.tools_for_testing.ContextMock', 'ContextMock', ({}, {}), '()', False, 'from tests.test_cli.tools_for_testing import ConfigLoaderMock, ContextMock, PublicIdMock, StopTest, raise_stoptest\n'), ((316, 38, 316, 51), 'tests.test_cli.tools_for_testing.ContextMock', 'ContextMock', ({}, {}), '()', False, 'from tests.test_cli.tools_for_testing import ConfigLoaderMock, ContextMock, PublicIdMock, StopTest, raise_stoptest\n'), ((325, 38, 325, 51), 'tests.test_cli.tools_for_testing.ContextMock', 'ContextMock', ({}, {}), '()', False, 'from tests.test_cli.tools_for_testing import ConfigLoaderMock, ContextMock, PublicIdMock, StopTest, raise_stoptest\n'), ((339, 38, 339, 51), 'tests.test_cli.tools_for_testing.ContextMock', 'ContextMock', ({}, {}), '()', False, 'from tests.test_cli.tools_for_testing import ConfigLoaderMock, ContextMock, PublicIdMock, StopTest, raise_stoptest\n'), ((353, 41, 353, 72), 'tests.test_cli.tools_for_testing.ContextMock', 'ContextMock', (), '', False, 'from tests.test_cli.tools_for_testing import ConfigLoaderMock, ContextMock, PublicIdMock, StopTest, raise_stoptest\n')]