dkutils.datakitchen_api.tests_utils module

class dkutils.datakitchen_api.tests_utils.TestInfo(test: str, datestamp: str, description: str, kitchen: str, recipe: str, node: str, failure_action: str, variable: str, metric: str, comparison: str, expression: str)[source]

Bases: object

get(field_name, default=None)[source]
classmethod keys()[source]
comparison: str
datestamp: str
description: str
expression: str
failure_action: str
kitchen: str
metric: str
node: str
recipe: str
test: str
variable: str
dkutils.datakitchen_api.tests_utils.extract_tests_from_files(client, datestamp, test_paths, kitchen=None, recipe=None) List[dkutils.datakitchen_api.tests_utils.TestInfo][source]

Extract tests from the provided test_paths. The kitchen and recipe are derived from the client, unless otherwise specified as optional input arguments. If kitchen and/or recipe arguments are provided, they are set accordingly on the provided client.

Parameters
  • client (DataKitchenClient) – DataKitchenClient instance with kitchen and/or recipe set accordingly, unless optional kitchen and/or recipe arguments are provided

  • datestamp (datetime) – Datestamp indicating approximate time when tests were extracted.

  • test_paths (list) – List of paths to all recipe files that potentially contain tests.

  • kitchen (str, optional) – If None, use the kitchen currently set on the client, otherwise set the kitchen accordingly.

  • recipe (str, optional) – If None, use the recipe currently set on the client, otherwise, set the recipe accordingly.

Returns

List of TestInfo objects, one per test found in the provided test_paths.

Return type

list

dkutils.datakitchen_api.tests_utils.get_recipe_test_paths(client, kitchen=None, recipe=None) List[str][source]

Return a list of paths to all recipe files that potentially contain tests. The kitchen and and recipe that are interrogated for tests are derived from the client, unless otherwise specified as optional input arguments. If kitchen and/or recipe arguments are provided, they are set accordingly on the provided client.

Parameters
  • client (DataKitchenClient) – DataKitchenClient instance with kitchen and/or recipe set accordingly, unless optional kitchen and/or recipe arguments are provided

  • kitchen (str, optional) – If None, use the kitchen currently set on the client, otherwise set the kitchen accordingly.

  • recipe (str, optional) – If None, use the recipe currently set on the client, otherwise, set the recipe accordingly.

Returns

List of paths to all recipe files that potentially contain tests.

Return type

list

dkutils.datakitchen_api.tests_utils.get_test_infos(client, datestamp, recipes, kitchen=None) List[dkutils.datakitchen_api.tests_utils.TestInfo][source]

For a set of recipes in a kitchen, retrieve all the defined tests and their associated metadata. Return a list of test_info dictionaries, one per test.

Parameters
  • client (DataKitchenClient) – DataKitchenClient instance with kitchen set accordingly, unless optional kitchen argument is provided

  • datestamp (datetime) – Datestamp indicating approximate time when tests were extracted.

  • recipes (list) – List of paths to all recipe files that potentially contain tests.

  • kitchen (str, optional) – If None, use the kitchen currently set on the client, otherwise set the kitchen accordingly.

Returns

List of TestInfo objects, one per test found in the provided kitchen recipes.

Return type

list

dkutils.datakitchen_api.tests_utils.is_valid_test_directory(base_path, file_depth) bool[source]

Only node directories and their immediate subdirectories may contain tests. This function takes a recipe subdirectory and returns True if it may contain tests or False otherwise.

Parameters
  • base_path (Path) – Recipe subdirectory path that may or may not contain tests. This path is relative to a recipe’s root directory (e.g. Recipe/Node/data_sinks).

  • file_depth (int) – Depth of directory containing recipe files (e.g. Recipe/Node/notebook.json has file_depth==2). Tests may only be defined in files in the root of a node directory or direct subdirectories (i.e. file_depth == 2 or 3)

Returns

True if the recipe base_path may contain tests, False otherwise.

Return type

boolean

dkutils.datakitchen_api.tests_utils.is_valid_test_file(file_path, file_depth) bool[source]

Only certain files may contain tests. This function returns True if the provided file may contain tests or False otherwise.

Parameters
  • file_path (Path) – Path to a recipe file relative to the root of the recipe (e.g. Recipe/Node/notebook.json)

  • file_depth (int) – Subdirectory depth of recipe file (e.g. Recipe/Node/notebook.json file depth is 2)

Returns

True if the file may contain tests, otherwise False.

Return type

boolean

dkutils.datakitchen_api.tests_utils.write_test_infos_csv(test_infos, output_csv_path) None[source]

Write a list of TestInfo objects to a CSV file.

Parameters
  • test_infos (list) – List of TestInfo object

  • output_csv_path (str) – Output CSV file path