pytest_gee.utils#

functions used to build the API that we don’t want to expose to end users.

Danger

This module is for internal use only and should not be used directly.

Attributes#

Functions#

_create_container(asset_request)

Create a container for the asset request depending on the requested type.

build_fullpath(datadir, request, extension[, ...])

Generate a fullpath from parameters of the test.

check_serialized(object, path, datadir, ...[, ...])

Check if the serialized GEE object is the same as the saved one.

delete_assets(asset_id[, dry_run])

Delete the selected asset and all its content.

export_asset(object, asset_id, description)

Export assets to the GEE platform, only working for very simple objects.

get_assets(folder)

Get all the assets from the parameter folder. every nested asset will be displayed.

get_task(task_descripsion)

Search for the described task in the user Task list return None if nothing is found.

init_tree(structure, prefix, root)

Create an EarthEngine folder tree from a dictionary.

round_data(data[, prescision])

Recusrsively Round the values of a list to the given prescision.

wait(task[, timeout])

Wait until the selected process is finished or we reached timeout value.

Module Contents#

pytest_gee.utils._create_container(asset_request)[source]#

Create a container for the asset request depending on the requested type.

Parameters:

asset_request (str) – the asset request specifying the type of asset to create. Convention is <asset_id>::<asset_type>

Returns:

the asset_id of the container

Return type:

str

pytest_gee.utils.build_fullpath(datadir, request, extension, basename=None, fullpath=None, with_test_class_names=False)[source]#

Generate a fullpath from parameters of the test.

Parameters:
  • datadir (pathlib.Path) – Fixture embed_data.

  • request (pytest.FixtureRequest) – Pytest request object.

  • extension (str) – Extension of files compared by this check.

  • basename (Optional[str]) – basename of the file to test/record. If not given the name of the test is used. Use either basename or fullpath.

  • fullpath (Optional[os.PathLike[str]]) – complete path to use as a reference file. This option will ignore datadir fixture when reading expected files but will still use it to write obtained files. Useful if a reference file is located in the session data dir for example.

  • with_test_class_names (bool) – if true it will use the test class name (if any) to compose the basename.

Return type:

pathlib.Path

pytest_gee.utils.check_serialized(object, path, datadir, original_datadir, request, force_regen=False, with_test_class_names=False)[source]#

Check if the serialized GEE object is the same as the saved one.

Parameters:
  • object (ee.ComputedObject) – the earthnegine object to check

  • path (pathlib.Path) – the full path to the file to check against.

  • datadir (pathlib.Path) – Fixture embed_data.

  • original_datadir (pathlib.Path) – Fixture embed_data.

  • request (pytest.FixtureRequest) – Pytest request object.

  • force_regen (bool) – if True, the file will be regenerated even if it exists.

  • with_test_class_names (bool) – if true it will use the test class name (if any) to compose the basename.

Raises:

AssertionError if the serialized object is different from the saved one.

pytest_gee.utils.delete_assets(asset_id, dry_run=True)[source]#

Delete the selected asset and all its content.

This method will delete all the files and folders existing in an asset folder. By default a dry run will be launched and if you are satisfyed with the displayed names, change the dry_run variable to False. No other warnng will be displayed.

Warning

If this method is used on the root directory you will loose all your data, it’s highly recommended to use a dry run first and carefully review the destroyed files.

Parameters:
  • asset_id (Union[str, pathlib.Path]) – the Id of the asset or a folder

  • dry_run (bool) – whether or not a dry run should be launched. dry run will only display the files name without deleting them.

Returns:

a list of all the files deleted or to be deleted

Return type:

list

pytest_gee.utils.export_asset(object, asset_id, description)[source]#

Export assets to the GEE platform, only working for very simple objects.

Parameters:
  • object (ee.ComputedObject) – the object to export

  • asset_id (Union[str, pathlib.Path]) – the name of the asset to create

  • description (str) – the description of the task

Returns:

the path of the created asset

Return type:

pathlib.PurePosixPath

pytest_gee.utils.get_assets(folder)[source]#

Get all the assets from the parameter folder. every nested asset will be displayed.

Parameters:

folder (Union[str, pathlib.Path]) – the initial GEE folder

Returns:

‘type’, ‘name’ and ‘id’

Return type:

the asset list. each asset is a dict with 3 keys

pytest_gee.utils.get_task(task_descripsion)[source]#

Search for the described task in the user Task list return None if nothing is found.

Parameters:

task_descripsion (str) – the task description

Returns:

return the found task else None

Return type:

Optional[ee.batch.Task]

pytest_gee.utils.init_tree(structure, prefix, root)[source]#

Create an EarthEngine folder tree from a dictionary.

The input ditionary should described the structure of the folder you want to create. The keys are the folder names and the values are the subfolders. Once you reach an ee.FeatureCollection and/or an ee.Image set it in the dictionary and the function will export the object.

Parameters:
  • structure (dict) – the structure of the folder to create

  • prefix (str) – the prefix to use on every item (folder, tasks, asset_id, etc.)

  • root (Union[str, pathlib.PurePosixPath]) – the root folder of the test where to create the test folder.

Returns:

the path of the created folder

Return type:

pathlib.PurePosixPath

Examples

>>> structure = {
...     "folder_1": {
...         "image": ee.image(1),
...         "fc": ee.FeatureCollection(ee.Geometry.Point([0, 0])),
...     },
... }
... init_tree(structure, "toto")
pytest_gee.utils.round_data(data, prescision=6)[source]#

Recusrsively Round the values of a list to the given prescision.

Parameters:
Return type:

Union[list, dict]

pytest_gee.utils.wait(task, timeout=10 * 60)[source]#

Wait until the selected process is finished or we reached timeout value.

Parameters:
  • task (Union[ee.batch.Task, str]) – name of the running task or the Task object itself.

  • timeout (int) – timeout in seconds. if set to 0 the parameter is ignored. default to 1 minutes.

Returns:

the final state of the task

Return type:

str

pytest_gee.utils.TASK_FINISHED_STATES: tuple[str, str, str][source]#