示例#1
0
 def test_from_json_positive(self, *mocks):
     """Test case for from_json method positive result."""
     json_disc = {
         "name": "name",
         "author": AUTHOR,
         "version": "0.1.0",
         "license": "license",
         "description": "description",
         "speech_acts": {"arg1": "arg1", "arg2": "arg2"},
     }
     ProtocolSpecification.from_json(json_disc)
示例#2
0
def test_protocol_specification_attributes():
    protocol_specification = ProtocolSpecification("name", "author", "0.1.0")

    # test getter and setter for 'protobuf_snippets'
    assert protocol_specification.protobuf_snippets == {}
    protocol_specification.protobuf_snippets = {"a": 1}
    assert protocol_specification.protobuf_snippets == {"a": 1}

    # test getter and setter for 'dialogue_config'
    assert protocol_specification.dialogue_config == {}
    protocol_specification.dialogue_config = {"a": 1}
    assert protocol_specification.dialogue_config == {"a": 1}
示例#3
0
    def test__check_consistency_positive(self):
        """Test case for _check_consistency method positive result."""
        obj = ProtocolSpecification(name="my_protocol", author="fetchai")
        with self.assertRaises(ProtocolSpecificationParseError):
            obj._check_consistency()

        obj.speech_acts = mock.Mock()
        read_all_mock = mock.Mock(return_value=[(1, 2)])
        obj.speech_acts.read_all = read_all_mock
        with self.assertRaises(ProtocolSpecificationParseError):
            obj._check_consistency()

        read_all_mock = mock.Mock(return_value=[["", 1]])
        obj.speech_acts.read_all = read_all_mock
        with self.assertRaises(ProtocolSpecificationParseError):
            obj._check_consistency()

        speech_act_content_config = mock.Mock()
        speech_act_content_config.args = {1: 2}
        read_all_mock = mock.Mock(
            return_value=[["1", speech_act_content_config]])
        obj.speech_acts.read_all = read_all_mock
        obj._check_consistency()
示例#4
0
 def test_json_positive(self):
     """Test case for json property positive result."""
     obj = ProtocolSpecification(name="my_protocol", author="fetchai")
     obj.json
示例#5
0
 def test_init_positive(self):
     """Test case for __init__ method positive result."""
     ProtocolSpecification(name="my_protocol", author="fetchai")
示例#6
0
def _raise_yamlerror(*args, **kwargs):
    raise yaml.YAMLError("some yaml error")


def _raise_fnfError(*args, **kwargs):
    raise FileNotFoundError("some fnf error")


@mock.patch("aea.protocols.generator.common.open_file", mock.mock_open())
@mock.patch("aea.cli.generate.open_file", mock.mock_open())
@mock.patch(
    "aea.protocols.generator.common.ConfigLoader.load_protocol_specification",
    return_value=ProtocolSpecification(
        name="name",
        author="author",
        version="1.0.0",
        protocol_specification_id="author/name:0.1.0",
    ),
)
@mock.patch("aea.cli.utils.decorators._cast_ctx")
class GenerateItemTestCase(TestCase):
    """Test case for fetch_agent_locally method."""
    def test__generate_item_file_exists(self, *_mocks):
        """Test for fetch_agent_locally method file exists result."""
        ctx_mock = ContextMock()
        with self.assertRaises(ClickException):
            _generate_protocol(ctx_mock, "path")

    @mock.patch("aea.protocols.generator.base.shutil.which", _which_mock)
    def test__generate_item_no_res(self, *_mocks):
        """Test for fetch_agent_locally method no black."""
示例#7
0
 def test_json_positive(self):
     """Test case for json property positive result."""
     obj = ProtocolSpecification()
     obj.json
示例#8
0
 def test_init_positive(self):
     """Test case for __init__ method positive result."""
     ProtocolSpecification()