example/background_cloud_function.py
def simulated_cloud_function(event, context, data_path: Optional[Path] = None):
    """
    This function is a wrapper of the background function.

    `data_path` allows giving the function any arbitrary folder as "cloud storage bucket simulator".
    This is useful for pytest and its tmpdir fixture.

    Its default value sets the `data` folder at the root of the repo as the default "cloud storage bucket simulator".

    This function allows developers to use the function-framework very straightforwardly:
    `functions-framework --target=simulated_cloud_function --source=background_cloud_function.py --signature-type=event`
    """
    if data_path is None:  # pragma: no cover
        data_path = Path(__file__).parent / ".." / "data"

    from unittest import mock
    from gcs_simulator.storage import MockClient

    root_folder = Path(data_path).absolute().resolve().as_posix()

    class FakeClient(MockClient):
        """ This allows to mock a "google.cloud.storage.Client" object and use the `root_folder` as bucket simulator
        """

        def __init__(self, *args, **kwargs):
            super().__init__(*args, **kwargs)

            self.set_local_root_folder_used_for_simulation(root_folder)

    @mock.patch("google.cloud.storage.Client", FakeClient)
    def run_function_with_simulator(event, context):
        demo_background_cloud_function(event, context)

    run_function_with_simulator(event, context)

    This function is a wrapper of the background function.

    `data_path` allows giving the function any arbitrary folder as "cloud storage bucket simulator".
    This is useful for pytest and its tmpdir fixture.

    Its default value sets the `data` folder at the root of the repo as the default "cloud storage bucket simulator".

    This function allows developers to use the function-framework very straightforwardly:
    `functions-framework --target=simulated_cloud_function --source=background_cloud_function.py --signature-type=event`
    
This function is a wrapper of the background function.
`data_path` allows giving the function any arbitrary folder as "cloud storage bucket simulator".
This is useful for pytest and its tmpdir fixture.

Its default value sets the `data` folder at the root of the repo as the default "cloud storage bucket simulator".


This function is a wrapper of the background function . ` data_path ` allows giving the function any arbitrary folder as " cloud storage bucket simulator " . This is useful for pytest and its tmpdir fixture . Its default value sets the ` data ` folder at the root of the repo as the default " cloud storage bucket simulator " .
def simulated_cloud_function(event, context, data_path: Optional[Path] = None):
    if data_path is None:  
        data_path = Path(__file__).parent / ".." / "data"
    from unittest import mock
    from gcs_simulator.storage import MockClient
    root_folder = Path(data_path).absolute().resolve().as_posix()
    class FakeClient(MockClient):
        def __init__(self, *args, **kwargs):
            super().__init__(*args, **kwargs)
            self.set_local_root_folder_used_for_simulation(root_folder)
    @mock.patch("google.cloud.storage.Client", FakeClient)
    def run_function_with_simulator(event, context):
        demo_background_cloud_function(event, context)
    run_function_with_simulator(event, context)
def simulated_cloud_function ( event , context , data_path : Optional [ Path ] = None ) : if data_path is None : data_path = Path ( __file__ ) . parent / ".." / "data" from unittest import mock from gcs_simulator . storage import MockClient root_folder = Path ( data_path ) . absolute ( ) . resolve ( ) . as_posix ( ) class FakeClient ( MockClient ) : """ This allows to mock a "google.cloud.storage.Client" object and use the `root_folder` as bucket simulator
        """ def __init__ ( self , * args , ** kwargs ) : super ( ) . __init__ ( * args , ** kwargs ) self . set_local_root_folder_used_for_simulation ( root_folder ) @ mock . patch ( "google.cloud.storage.Client" , FakeClient ) def run_function_with_simulator ( event , context ) : demo_background_cloud_function ( event , context ) run_function_with_simulator ( event , context )
This function is a wrapper of the background function.
This function is a wrapper of the background function .
"""
    This function is a wrapper of the background function.

    `data_path` allows giving the function any arbitrary folder as "cloud storage bucket simulator".
    This is useful for pytest and its tmpdir fixture.

    Its default value sets the `data` folder at the root of the repo as the default "cloud storage bucket simulator".

    This function allows developers to use the function-framework very straightforwardly:
    `functions-framework --target=simulated_cloud_function --source=background_cloud_function.py --signature-type=event`
    """ # pragma: no cover """ This allows to mock a "google.cloud.storage.Client" object and use the `root_folder` as bucket simulator
        """
event
context
data_path
Optional[Path]