def test_copy_from_proto_with_invalid_proto(self): owner = model_card.Owner() wrong_proto = model_card_pb2.Version() with self.assertRaisesRegex( TypeError, "<class 'model_card_toolkit.proto.model_card_pb2.Owner'> is expected. " "However <class 'model_card_toolkit.proto.model_card_pb2.Version'> is " "provided."): owner.copy_from_proto(wrong_proto)
def test_to_proto_sucess(self): # Test fields convert. owner = model_card.Owner() self.assertEqual(owner.to_proto(), model_card_pb2.Owner()) owner.name = "my_name" self.assertEqual(owner.to_proto(), model_card_pb2.Owner(name="my_name")) owner.contact = "my_contact" self.assertEqual( owner.to_proto(), model_card_pb2.Owner(name="my_name", contact="my_contact")) # Test message convert. model_details = model_card.ModelDetails( owners=[model_card.Owner(name="my_name", contact="my_contact")]) self.assertEqual( model_details.to_proto(), model_card_pb2.ModelDetails(owners=[ model_card_pb2.Owner(name="my_name", contact="my_contact") ], version=model_card_pb2.Version()))
def test_merge_from_proto_with_invalid_proto(self): owner = model_card.Owner() wrong_proto = model_card_pb2.Version() with self.assertRaisesRegex(TypeError, ".*expected .*Owner got .*Version.*"): owner.merge_from_proto(wrong_proto)