Exemple #1
0
 def test_check_prerequisites_negative_protoc_is_not_installed(
         self, mocked_is_installed):
     """Negative test for the 'check_prerequisites' method: protoc isn't installed"""
     with self.assertRaises(FileNotFoundError):
         check_prerequisites()
Exemple #2
0
    def test_compare_latest_generator_output_with_test_protocol(self):
        """Test that the "t_protocol" test protocol matches with what the latest generator generates based on the specification."""
        # Skip if prerequisite applications are not installed
        try:
            check_prerequisites()
        except FileNotFoundError:
            pytest.skip(
                "Some prerequisite applications are not installed. Skipping this test."
            )

        # Specification
        # protocol_name = "t_protocol"
        path_to_specification = os.path.join(ROOT_DIR, "tests", "data",
                                             "sample_specification.yaml")
        path_to_generated_protocol = self.t
        # path_to_original_protocol = os.path.join(
        #     ROOT_DIR, "tests", "data", "generator", protocol_name
        # )
        path_to_package = "tests.data.generator."

        # Generate the protocol
        protocol_generator = ProtocolGenerator(
            path_to_specification,
            path_to_generated_protocol,
            path_to_protocol_package=path_to_package,
        )
        protocol_generator.generate()

        # # compare __init__.py
        # init_file_generated = Path(self.t, protocol_name, "__init__.py")
        # init_file_original = Path(path_to_original_protocol, "__init__.py",)
        # assert filecmp.cmp(init_file_generated, init_file_original)

        # # compare protocol.yaml
        # protocol_yaml_file_generated = Path(self.t, protocol_name, "protocol.yaml")
        # protocol_yaml_file_original = Path(path_to_original_protocol, "protocol.yaml",)
        # assert filecmp.cmp(protocol_yaml_file_generated, protocol_yaml_file_original)

        # # compare message.py
        # message_file_generated = Path(self.t, protocol_name, "message.py")
        # message_file_original = Path(path_to_original_protocol, "message.py",)
        # assert filecmp.cmp(message_file_generated, message_file_original)

        # # compare serialization.py
        # serialization_file_generated = Path(self.t, protocol_name, "serialization.py")
        # serialization_file_original = Path(
        #     path_to_original_protocol, "serialization.py",
        # )
        # assert filecmp.cmp(serialization_file_generated, serialization_file_original)

        # # compare .proto
        # proto_file_generated = Path(
        #     self.t, protocol_name, "{}.proto".format(protocol_name)
        # )
        # proto_file_original = Path(
        #     path_to_original_protocol, "{}.proto".format(protocol_name),
        # )
        # assert filecmp.cmp(proto_file_generated, proto_file_original)

        # # compare _pb2.py
        # pb2_file_generated = Path(
        #     self.t, protocol_name, "{}_pb2.py".format(protocol_name)
        # )
        # with open(ROOT_DIR + "/x_pb2.py", "w") as fp:
        #     fp.write(pb2_file_generated.read_text())
        # pb2_file_original = Path(
        #     path_to_original_protocol, "{}_pb2.py".format(protocol_name),
        # )
        # assert filecmp.cmp(pb2_file_generated, pb2_file_original)
        assert True
Exemple #3
0
 def test_check_prerequisites_positive(self, mocked_is_installed):
     """Positive test for the 'check_prerequisites' method"""
     try:
         check_prerequisites()
     except FileNotFoundError:
         self.assertTrue(False)