예제 #1
0
 def test_fipa_protocol(self):
     """Test the fetchai/fipa:0.5.0 documentation."""
     offset = 15
     locals_dict = {"Enum": Enum}
     compile_and_exec(self.code_blocks[offset]["text"],
                      locals_dict=locals_dict)
     ActualFipaPerformative = locals_dict["Performative"]
     ExpectedFipaPerformative = FipaMessage.Performative
     compare_enum_classes(ExpectedFipaPerformative, ActualFipaPerformative)
예제 #2
0
    def test_oef_search_protocol(self):
        """Test the fetchai/oef_search:0.4.0 protocol documentation."""
        # this is the offset of code blocks for the section under testing
        offset = 4

        # define a data model and a description
        locals_dict = {"Enum": Enum}
        compile_and_exec(self.code_blocks[offset]["text"],
                         locals_dict=locals_dict)
        ActualPerformative = locals_dict["Performative"]
        compare_enum_classes(OefSearchMessage.Performative, ActualPerformative)

        compile_and_exec(self.code_blocks[offset + 1]["text"],
                         locals_dict=locals_dict)
        # mind the indexes: +3 before +2
        compile_and_exec(self.code_blocks[offset + 3]["text"],
                         locals_dict=locals_dict)
        compile_and_exec(self.code_blocks[offset + 2]["text"],
                         locals_dict=locals_dict)

        # test the construction of OEF Search Messages does not contain trivial errors.
        locals_dict["OefSearchMessage"] = OefSearchMessage
        compile_and_exec(self.code_blocks[offset + 4]["text"],
                         locals_dict=locals_dict)
        compile_and_exec(self.code_blocks[offset + 5]["text"],
                         locals_dict=locals_dict)
        compile_and_exec(self.code_blocks[offset + 6]["text"],
                         locals_dict=locals_dict)
        compile_and_exec(self.code_blocks[offset + 7]["text"],
                         locals_dict=locals_dict)
        compile_and_exec(self.code_blocks[offset + 8]["text"],
                         locals_dict=locals_dict)
        compile_and_exec(self.code_blocks[offset + 9]["text"],
                         locals_dict=locals_dict)
        # this is just to test that something has actually run
        assert locals_dict["query_data"] == {
            "search_term": "country",
            "search_value": "UK",
            "constraint_type": "==",
        }

        # test the definition of OefErrorOperation
        compile_and_exec(self.code_blocks[offset + 10]["text"],
                         locals_dict=locals_dict)
        ActualOefErrorOperation = locals_dict["OefErrorOperation"]
        ExpectedOefErrorOperation = OefErrorOperation
        compare_enum_classes(ExpectedOefErrorOperation,
                             ActualOefErrorOperation)
예제 #3
0
    def test_custom_protocol(self):
        """Test the code in the 'Custom protocol' section."""
        # this is the offset of code blocks for the section under testing
        offset = 0
        locals_dict = {}
        compile_and_exec(self.code_blocks[offset]["text"],
                         locals_dict=locals_dict)
        ActualPerformative = locals_dict["Performative"]
        compare_enum_classes(ActualPerformative, DefaultMessage.Performative)

        # load the example of default message of type BYTES
        compile_and_exec(self.code_blocks[offset + 1]["text"],
                         locals_dict=locals_dict)

        # load the definition of the ErrorCode enumeration
        compile_and_exec(self.code_blocks[offset + 2]["text"],
                         locals_dict=locals_dict)
        ExpectedErrorCode = locals_dict["ErrorCode"]
        compare_enum_classes(ExpectedErrorCode, DefaultMessage.ErrorCode)

        # load the example of default message of type ERROR
        _ = compile_and_exec(self.code_blocks[offset + 3]["text"],
                             locals_dict=locals_dict)