# Path: testbench/error.py
# class RestException(Exception):
#     def __init__(self, msg, code):
#     def as_response(self):
#     def handler(ex):
# def _simple_json_error(msg):
# def generic(msg, rest_code, grpc_code, context):
# def csek(context, rest_code=400, grpc_code=grpc.StatusCode.INVALID_ARGUMENT):
# def invalid(msg, context, rest_code=400, grpc_code=grpc.StatusCode.INVALID_ARGUMENT):
# def missing(name, context, rest_code=400, grpc_code=grpc.StatusCode.INVALID_ARGUMENT):
# def mismatch(
#     msg,
#     expect,
#     actual,
#     context,
#     rest_code=412,
#     grpc_code=grpc.StatusCode.FAILED_PRECONDITION,
# ):
# def notchanged(msg, context, rest_code=304, grpc_code=grpc.StatusCode.ABORTED):
# def notfound(name, context, rest_code=404, grpc_code=grpc.StatusCode.NOT_FOUND):
# def notallowed(context=None, rest_code=405, grpc_code=None):
# def already_exists(context=None):


import unittest
import grpc
from unittest.mock import ANY, Mock
from testbench import error
        self.assertEqual(rest.exception.code, 400)

        context = Mock()
        error.csek(context)
        context.abort.assert_called_once_with(grpc.StatusCode.INVALID_ARGUMENT, ANY)

    def test_invalid(self):
        with self.assertRaises(error.RestException) as rest:
            error.invalid("bad bucket name", None)
        self.assertEqual(rest.exception.code, 400)

        context = Mock()
        error.invalid("bad bucket name", context)
        context.abort.assert_called_once_with(grpc.StatusCode.INVALID_ARGUMENT, ANY)

    def test_missing(self):
        with self.assertRaises(error.RestException) as rest:
            error.missing("object name", None)
        self.assertEqual(rest.exception.code, 400)

        context = Mock()
        error.missing("object name", context)
        context.abort.assert_called_once_with(grpc.StatusCode.INVALID_ARGUMENT, ANY)

    def test_mismatch(self):
        with self.assertRaises(error.RestException) as rest:
            error.mismatch("ifGenerationMatch", "0", "123", None)
        self.assertEqual(rest.exception.code, 412)

        context = Mock()

# Path: testbench/error.py
# class RestException(Exception):
#     def __init__(self, msg, code):
#     def as_response(self):
#     def handler(ex):
# def _simple_json_error(msg):
# def generic(msg, rest_code, grpc_code, context):
# def csek(context, rest_code=400, grpc_code=grpc.StatusCode.INVALID_ARGUMENT):
# def invalid(msg, context, rest_code=400, grpc_code=grpc.StatusCode.INVALID_ARGUMENT):
# def missing(name, context, rest_code=400, grpc_code=grpc.StatusCode.INVALID_ARGUMENT):
# def mismatch(
#     msg,
#     expect,
#     actual,
#     context,
#     rest_code=412,
#     grpc_code=grpc.StatusCode.FAILED_PRECONDITION,
# ):
# def notchanged(msg, context, rest_code=304, grpc_code=grpc.StatusCode.ABORTED):
# def notfound(name, context, rest_code=404, grpc_code=grpc.StatusCode.NOT_FOUND):
# def notallowed(context=None, rest_code=405, grpc_code=None):
# def already_exists(context=None):


# Path: tests/test_error.py
import unittest
import grpc
from unittest.mock import ANY, Mock
from testbench import error

        self.assertEqual(rest.exception.code, 400)

        context = Mock()
        error.csek(context)
        context.abort.assert_called_once_with(grpc.StatusCode.INVALID_ARGUMENT, ANY)

    def test_invalid(self):
        with self.assertRaises(error.RestException) as rest:
            error.invalid("bad bucket name", None)
        self.assertEqual(rest.exception.code, 400)

        context = Mock()
        error.invalid("bad bucket name", context)
        context.abort.assert_called_once_with(grpc.StatusCode.INVALID_ARGUMENT, ANY)

    def test_missing(self):
        with self.assertRaises(error.RestException) as rest:
            error.missing("object name", None)
        self.assertEqual(rest.exception.code, 400)

        context = Mock()
        error.missing("object name", context)
        context.abort.assert_called_once_with(grpc.StatusCode.INVALID_ARGUMENT, ANY)

    def test_mismatch(self):
        with self.assertRaises(error.RestException) as rest:
            error.mismatch("ifGenerationMatch", "0", "123", None)
        self.assertEqual(rest.exception.code, 412)

        context = Mock()

        error.mismatch("ifGenerationMatch", "0", "123", context)