Пример #1
0
    def test_unauthorized(self):
        mock_client = _create_mock_client()
        error = test_util.grpc_error(grpc.StatusCode.PERMISSION_DENIED, "nope")
        mock_client.DeleteExperiment.side_effect = error

        with self.assertRaises(uploader_lib.PermissionDeniedError):
            uploader_lib.delete_experiment(mock_client, "123")
Пример #2
0
    def test_not_found(self):
        mock_client = _create_mock_client()
        error = test_util.grpc_error(grpc.StatusCode.NOT_FOUND, "nope")
        mock_client.DeleteExperiment.side_effect = error

        with self.assertRaises(uploader_lib.ExperimentNotFoundError):
            uploader_lib.delete_experiment(mock_client, "123")
Пример #3
0
    def test_success(self):
        mock_client = _create_mock_client()
        response = write_service_pb2.DeleteExperimentResponse()
        mock_client.DeleteExperiment.return_value = response

        uploader_lib.delete_experiment(mock_client, "123")

        expected_request = write_service_pb2.DeleteExperimentRequest()
        expected_request.experiment_id = "123"
        mock_client.DeleteExperiment.assert_called_once()
        (args, _) = mock_client.DeleteExperiment.call_args
        self.assertEqual(args[0], expected_request)
Пример #4
0
 def execute(self, server_info, channel):
     api_client = write_service_pb2_grpc.TensorBoardWriterServiceStub(
         channel)
     if not self.experiment_id_list:
         raise base_plugin.FlagsError(
             "Must specify at least one experiment ID to delete.")
     # Map from eid to (msg, action) pair.
     results = {}
     NO_ACTION = "NO_ACTION"
     DIE_ACTION = "DIE_ACTION"
     for experiment_id in set(self.experiment_id_list):
         if not experiment_id:
             results[experiment_id] = (
                 "Skipping empty experiment_id.",
                 NO_ACTION,
             )
             continue
         try:
             uploader_lib.delete_experiment(api_client, experiment_id)
             results[experiment_id] = (
                 "Deleted experiment %s." % experiment_id,
                 NO_ACTION,
             )
         except uploader_lib.ExperimentNotFoundError:
             results[experiment_id] = (
                 "No such experiment %s. Either it never existed or it has "
                 "already been deleted." % experiment_id,
                 DIE_ACTION,
             )
         except uploader_lib.PermissionDeniedError:
             results[experiment_id] = (
                 "Cannot delete experiment %s because it is owned by a "
                 "different user." % experiment_id,
                 DIE_ACTION,
             )
         except grpc.RpcError as e:
             results[experiment_id] = (
                 ("Internal error deleting experiment %s: %s." %
                  (experiment_id, e)),
                 DIE_ACTION,
             )
     # business logic on the receipt
     any_die_action = False
     err_msg = ""
     for (msg, action) in results.values():
         if action == NO_ACTION:
             print(msg)
         if action == DIE_ACTION:
             err_msg += msg + "\n"
             any_die_action = True
     if any_die_action:
         _die(err_msg)
Пример #5
0
 def execute(self, server_info, channel):
     api_client = write_service_pb2_grpc.TensorBoardWriterServiceStub(
         channel)
     experiment_id = self.experiment_id
     if not experiment_id:
         raise base_plugin.FlagsError(
             "Must specify a non-empty experiment ID to delete.")
     try:
         uploader_lib.delete_experiment(api_client, experiment_id)
     except uploader_lib.ExperimentNotFoundError:
         _die("No such experiment %s. Either it never existed or it has "
              "already been deleted." % experiment_id)
     except uploader_lib.PermissionDeniedError:
         _die("Cannot delete experiment %s because it is owned by a "
              "different user." % experiment_id)
     except grpc.RpcError as e:
         _die("Internal error deleting experiment: %s" % e)
     print("Deleted experiment %s." % experiment_id)