From fa755dc30c8fa5a2037c0265cf6becdb66ea5d73 Mon Sep 17 00:00:00 2001 From: Serge Smertin Date: Wed, 11 Sep 2024 21:19:04 +0200 Subject: [PATCH] Prettify fixture documentation --- README.md | 591 +++++++++--------- scripts/gen-readme.py | 9 +- .../labs/pytester/fixtures/baseline.py | 23 +- 3 files changed, 293 insertions(+), 330 deletions(-) diff --git a/README.md b/README.md index c27f0ac..06788ff 100644 --- a/README.md +++ b/README.md @@ -35,32 +35,30 @@ ### `ws` fixture +Create and provide a Databricks WorkspaceClient object. - Create and provide a Databricks WorkspaceClient object. +This fixture initializes a Databricks WorkspaceClient object, which can be used +to interact with the Databricks workspace API. The created instance of WorkspaceClient +is shared across all test functions within the test session. - This fixture initializes a Databricks WorkspaceClient object, which can be used - to interact with the Databricks workspace API. The created instance of WorkspaceClient - is shared across all test functions within the test session. +See https://databricks-sdk-py.readthedocs.io/en/latest/authentication.html - See https://databricks-sdk-py.readthedocs.io/en/latest/authentication.html +Returns: +-------- +databricks.sdk.WorkspaceClient: + An instance of WorkspaceClient for interacting with the Databricks Workspace APIs. - Returns: - -------- - databricks.sdk.WorkspaceClient: - An instance of WorkspaceClient for interacting with the Databricks Workspace APIs. +Usage: +------ +In your test functions, include this fixture as an argument to use the WorkspaceClient: - Usage: - ------ - In your test functions, include this fixture as an argument to use the WorkspaceClient: +.. code-block:: python - .. code-block:: python + def test_workspace_operations(ws): + clusters = ws.clusters.list_clusters() + assert len(clusters) >= 0 - def test_workspace_operations(ws): - clusters = ws.clusters.list_clusters() - assert len(clusters) >= 0 - - -This fixture is built on top of: [`debug_env`](#debug-env-fixture), [`product_info`](#product-info-fixture) +This fixture is built on top of: [`debug_env`](#debug_env-fixture), [`product_info`](#product_info-fixture) [[back to top](#python-testing-for-databricks)] @@ -68,7 +66,7 @@ This fixture is built on top of: [`debug_env`](#debug-env-fixture), [`product_in ### `debug_env` fixture _No description yet._ -This fixture is built on top of: [`monkeypatch`](#monkeypatch-fixture), [`debug_env_name`](#debug-env-name-fixture) +This fixture is built on top of: [`monkeypatch`](#monkeypatch-fixture), [`debug_env_name`](#debug_env_name-fixture) [[back to top](#python-testing-for-databricks)] @@ -84,40 +82,31 @@ This fixture is built on top of: ### `env_or_skip` fixture _No description yet._ -This fixture is built on top of: [`debug_env`](#debug-env-fixture) +This fixture is built on top of: [`debug_env`](#debug_env-fixture) [[back to top](#python-testing-for-databricks)] ### `make_random` fixture +Fixture to generate random strings. - Fixture to generate random strings. - - This fixture provides a function to generate random strings of a specified length. - The generated strings are created using a character set consisting of uppercase letters, - lowercase letters, and digits. - - Returns: - -------- - function: - A function to generate random strings. - - Usage Example: - -------------- - To generate a random string with default length of 16 characters: +This fixture provides a function to generate random strings of a specified length. +The generated strings are created using a character set consisting of uppercase letters, +lowercase letters, and digits. - .. code-block:: python +To generate a random string with default length of 16 characters: - random_string = make_random() - assert len(random_string) == 16 +```python +random_string = make_random() +assert len(random_string) == 16 +``` - To generate a random string with a specified length: +To generate a random string with a specified length: - .. code-block:: python - - random_string = make_random(k=8) - assert len(random_string) == 8 - +```python +random_string = make_random(k=8) +assert len(random_string) == 8 +``` This fixture is built on top of: @@ -125,390 +114,368 @@ This fixture is built on top of: [[back to top](#python-testing-for-databricks)] ### `make_instance_pool` fixture +Fixture to manage Databricks instance pools. - Fixture to manage Databricks instance pools. - - This fixture provides a function to manage Databricks instance pools using the provided workspace (ws). - Instance pools can be created with specified configurations, and they will be deleted after the test is complete. +This fixture provides a function to manage Databricks instance pools using the provided workspace (ws). +Instance pools can be created with specified configurations, and they will be deleted after the test is complete. - Parameters: - ----------- - ws : WorkspaceClient - A Databricks WorkspaceClient instance. - make_random : function - The make_random fixture to generate unique names. +Parameters: +----------- +ws : WorkspaceClient + A Databricks WorkspaceClient instance. +make_random : function + The make_random fixture to generate unique names. - Returns: - -------- - function: - A function to manage Databricks instance pools. +Returns: +-------- +function: + A function to manage Databricks instance pools. - Usage Example: - -------------- - To manage Databricks instance pools using the make_instance_pool fixture: +Usage Example: +-------------- +To manage Databricks instance pools using the make_instance_pool fixture: - .. code-block:: python +.. code-block:: python - def test_instance_pool_management(make_instance_pool): - instance_pool_info = make_instance_pool(instance_pool_name="my-pool") - assert instance_pool_info is not None - + def test_instance_pool_management(make_instance_pool): + instance_pool_info = make_instance_pool(instance_pool_name="my-pool") + assert instance_pool_info is not None -This fixture is built on top of: [`ws`](#ws-fixture), [`make_random`](#make-random-fixture) +This fixture is built on top of: [`ws`](#ws-fixture), [`make_random`](#make_random-fixture) [[back to top](#python-testing-for-databricks)] ### `make_job` fixture +Fixture to manage Databricks jobs. - Fixture to manage Databricks jobs. +This fixture provides a function to manage Databricks jobs using the provided workspace (ws). +Jobs can be created with specified configurations, and they will be deleted after the test is complete. - This fixture provides a function to manage Databricks jobs using the provided workspace (ws). - Jobs can be created with specified configurations, and they will be deleted after the test is complete. +Parameters: +----------- +ws : WorkspaceClient + A Databricks WorkspaceClient instance. +make_random : function + The make_random fixture to generate unique names. +make_notebook : function + The make_notebook fixture to create a notebook path. - Parameters: - ----------- - ws : WorkspaceClient - A Databricks WorkspaceClient instance. - make_random : function - The make_random fixture to generate unique names. - make_notebook : function - The make_notebook fixture to create a notebook path. +Returns: +-------- +function: + A function to manage Databricks jobs. - Returns: - -------- - function: - A function to manage Databricks jobs. +Usage Example: +-------------- +To manage Databricks jobs using the make_job fixture: - Usage Example: - -------------- - To manage Databricks jobs using the make_job fixture: +.. code-block:: python - .. code-block:: python + def test_job_management(make_job): + job_info = make_job(name="my-job") + assert job_info is not None - def test_job_management(make_job): - job_info = make_job(name="my-job") - assert job_info is not None - - -This fixture is built on top of: [`ws`](#ws-fixture), [`make_random`](#make-random-fixture), [`make_notebook`](#make-notebook-fixture) +This fixture is built on top of: [`ws`](#ws-fixture), [`make_random`](#make_random-fixture), [`make_notebook`](#make_notebook-fixture) [[back to top](#python-testing-for-databricks)] ### `make_cluster` fixture +Fixture to manage Databricks clusters. - Fixture to manage Databricks clusters. - - This fixture provides a function to manage Databricks clusters using the provided workspace (ws). - Clusters can be created with specified configurations, and they will be permanently deleted after the test is complete. +This fixture provides a function to manage Databricks clusters using the provided workspace (ws). +Clusters can be created with specified configurations, and they will be permanently deleted after the test is complete. - Parameters: - ----------- - ws : WorkspaceClient - A Databricks WorkspaceClient instance. - make_random : function - The make_random fixture to generate unique names. +Parameters: +----------- +ws : WorkspaceClient + A Databricks WorkspaceClient instance. +make_random : function + The make_random fixture to generate unique names. - Returns: - -------- - function: - A function to manage Databricks clusters. +Returns: +-------- +function: + A function to manage Databricks clusters. - Usage Example: - -------------- - To manage Databricks clusters using the make_cluster fixture: +Usage Example: +-------------- +To manage Databricks clusters using the make_cluster fixture: - .. code-block:: python +.. code-block:: python - def test_cluster_management(make_cluster): - cluster_info = make_cluster(cluster_name="my-cluster", single_node=True) - assert cluster_info is not None - + def test_cluster_management(make_cluster): + cluster_info = make_cluster(cluster_name="my-cluster", single_node=True) + assert cluster_info is not None -This fixture is built on top of: [`ws`](#ws-fixture), [`make_random`](#make-random-fixture) +This fixture is built on top of: [`ws`](#ws-fixture), [`make_random`](#make_random-fixture) [[back to top](#python-testing-for-databricks)] ### `make_cluster_policy` fixture +Fixture to manage Databricks cluster policies. - Fixture to manage Databricks cluster policies. +This fixture provides a function to manage Databricks cluster policies using the provided workspace (ws). +Cluster policies can be created with a specified name and definition, and they will be deleted after the test is complete. - This fixture provides a function to manage Databricks cluster policies using the provided workspace (ws). - Cluster policies can be created with a specified name and definition, and they will be deleted after the test is complete. +Parameters: +----------- +ws : WorkspaceClient + A Databricks WorkspaceClient instance. +make_random : function + The make_random fixture to generate unique names. - Parameters: - ----------- - ws : WorkspaceClient - A Databricks WorkspaceClient instance. - make_random : function - The make_random fixture to generate unique names. +Returns: +-------- +function: + A function to manage Databricks cluster policies. - Returns: - -------- - function: - A function to manage Databricks cluster policies. +Usage Example: +-------------- +To manage Databricks cluster policies using the make_cluster_policy fixture: - Usage Example: - -------------- - To manage Databricks cluster policies using the make_cluster_policy fixture: +.. code-block:: python - .. code-block:: python + def test_cluster_policy_management(make_cluster_policy): + policy_info = make_cluster_policy(name="my-policy") + assert policy_info is not None - def test_cluster_policy_management(make_cluster_policy): - policy_info = make_cluster_policy(name="my-policy") - assert policy_info is not None - - -This fixture is built on top of: [`ws`](#ws-fixture), [`make_random`](#make-random-fixture) +This fixture is built on top of: [`ws`](#ws-fixture), [`make_random`](#make_random-fixture) [[back to top](#python-testing-for-databricks)] ### `make_group` fixture +Fixture to manage Databricks workspace groups. - Fixture to manage Databricks workspace groups. - - This fixture provides a function to manage Databricks workspace groups using the provided workspace (ws). - Groups can be created with specified members and roles, and they will be deleted after the test is complete. +This fixture provides a function to manage Databricks workspace groups using the provided workspace (ws). +Groups can be created with specified members and roles, and they will be deleted after the test is complete. - Parameters: - ----------- - ws : WorkspaceClient - A Databricks WorkspaceClient instance. - make_random : function - The make_random fixture to generate unique names. +Parameters: +----------- +ws : WorkspaceClient + A Databricks WorkspaceClient instance. +make_random : function + The make_random fixture to generate unique names. - Returns: - -------- - function: - A function to manage Databricks workspace groups. +Returns: +-------- +function: + A function to manage Databricks workspace groups. - Usage Example: - -------------- - To manage Databricks workspace groups using the make_group fixture: +Usage Example: +-------------- +To manage Databricks workspace groups using the make_group fixture: - .. code-block:: python +.. code-block:: python - def test_group_management(make_group): - group_info = make_group(members=["user@example.com"], roles=["viewer"]) - assert group_info is not None - + def test_group_management(make_group): + group_info = make_group(members=["user@example.com"], roles=["viewer"]) + assert group_info is not None -This fixture is built on top of: [`ws`](#ws-fixture), [`make_random`](#make-random-fixture) +This fixture is built on top of: [`ws`](#ws-fixture), [`make_random`](#make_random-fixture) [[back to top](#python-testing-for-databricks)] ### `make_user` fixture +Fixture to manage Databricks workspace users. - Fixture to manage Databricks workspace users. +This fixture provides a function to manage Databricks workspace users using the provided workspace (ws). +Users can be created with a generated user name, and they will be deleted after the test is complete. - This fixture provides a function to manage Databricks workspace users using the provided workspace (ws). - Users can be created with a generated user name, and they will be deleted after the test is complete. +Parameters: +----------- +ws : WorkspaceClient + A Databricks WorkspaceClient instance. +make_random : function + The make_random fixture to generate unique names. - Parameters: - ----------- - ws : WorkspaceClient - A Databricks WorkspaceClient instance. - make_random : function - The make_random fixture to generate unique names. +Returns: +-------- +function: + A function to manage Databricks workspace users. - Returns: - -------- - function: - A function to manage Databricks workspace users. +Usage Example: +-------------- +To manage Databricks workspace users using the make_user fixture: - Usage Example: - -------------- - To manage Databricks workspace users using the make_user fixture: +.. code-block:: python - .. code-block:: python + def test_user_management(make_user): + user_info = make_user() + assert user_info is not None - def test_user_management(make_user): - user_info = make_user() - assert user_info is not None - - -This fixture is built on top of: [`ws`](#ws-fixture), [`make_random`](#make-random-fixture) +This fixture is built on top of: [`ws`](#ws-fixture), [`make_random`](#make_random-fixture) [[back to top](#python-testing-for-databricks)] ### `make_notebook` fixture +Fixture to manage Databricks notebooks. - Fixture to manage Databricks notebooks. - - This fixture provides a function to manage Databricks notebooks using the provided workspace (ws). - Notebooks can be created with a specified path and content, and they will be deleted after the test is complete. +This fixture provides a function to manage Databricks notebooks using the provided workspace (ws). +Notebooks can be created with a specified path and content, and they will be deleted after the test is complete. - Parameters: - ----------- - ws : WorkspaceClient - A Databricks WorkspaceClient instance. - make_random : function - The make_random fixture to generate unique names. +Parameters: +----------- +ws : WorkspaceClient + A Databricks WorkspaceClient instance. +make_random : function + The make_random fixture to generate unique names. - Returns: - -------- - function: - A function to manage Databricks notebooks. +Returns: +-------- +function: + A function to manage Databricks notebooks. - Usage Example: - -------------- - To manage Databricks notebooks using the make_notebook fixture: +Usage Example: +-------------- +To manage Databricks notebooks using the make_notebook fixture: - .. code-block:: python +.. code-block:: python - def test_notebook_management(make_notebook): - notebook_path = make_notebook() - assert notebook_path.startswith("/Users/") and notebook_path.endswith(".py") - + def test_notebook_management(make_notebook): + notebook_path = make_notebook() + assert notebook_path.startswith("/Users/") and notebook_path.endswith(".py") -This fixture is built on top of: [`ws`](#ws-fixture), [`make_random`](#make-random-fixture) +This fixture is built on top of: [`ws`](#ws-fixture), [`make_random`](#make_random-fixture) [[back to top](#python-testing-for-databricks)] ### `make_directory` fixture +Fixture to manage Databricks directories. - Fixture to manage Databricks directories. +This fixture provides a function to manage Databricks directories using the provided workspace (ws). +Directories can be created with a specified path, and they will be deleted after the test is complete. - This fixture provides a function to manage Databricks directories using the provided workspace (ws). - Directories can be created with a specified path, and they will be deleted after the test is complete. +Parameters: +----------- +ws : WorkspaceClient + A Databricks WorkspaceClient instance. +make_random : function + The make_random fixture to generate unique names. - Parameters: - ----------- - ws : WorkspaceClient - A Databricks WorkspaceClient instance. - make_random : function - The make_random fixture to generate unique names. +Returns: +-------- +function: + A function to manage Databricks directories. - Returns: - -------- - function: - A function to manage Databricks directories. +Usage Example: +-------------- +To manage Databricks directories using the make_directory fixture: - Usage Example: - -------------- - To manage Databricks directories using the make_directory fixture: +.. code-block:: python - .. code-block:: python + def test_directory_management(make_directory): + directory_path = make_directory() + assert directory_path.startswith("/Users/") and not directory_path.endswith(".py") - def test_directory_management(make_directory): - directory_path = make_directory() - assert directory_path.startswith("/Users/") and not directory_path.endswith(".py") - - -This fixture is built on top of: [`ws`](#ws-fixture), [`make_random`](#make-random-fixture) +This fixture is built on top of: [`ws`](#ws-fixture), [`make_random`](#make_random-fixture) [[back to top](#python-testing-for-databricks)] ### `make_repo` fixture +Fixture to manage Databricks repos. - Fixture to manage Databricks repos. - - This fixture provides a function to manage Databricks repos using the provided workspace (ws). - Repos can be created with a specified URL, provider, and path, and they will be deleted after the test is complete. +This fixture provides a function to manage Databricks repos using the provided workspace (ws). +Repos can be created with a specified URL, provider, and path, and they will be deleted after the test is complete. - Parameters: - ----------- - ws : WorkspaceClient - A Databricks WorkspaceClient instance. - make_random : function - The make_random fixture to generate unique names. +Parameters: +----------- +ws : WorkspaceClient + A Databricks WorkspaceClient instance. +make_random : function + The make_random fixture to generate unique names. - Returns: - -------- - function: - A function to manage Databricks repos. +Returns: +-------- +function: + A function to manage Databricks repos. - Usage Example: - -------------- - To manage Databricks repos using the make_repo fixture: +Usage Example: +-------------- +To manage Databricks repos using the make_repo fixture: - .. code-block:: python +.. code-block:: python - def test_repo_management(make_repo): - repo_info = make_repo() - assert repo_info is not None - + def test_repo_management(make_repo): + repo_info = make_repo() + assert repo_info is not None -This fixture is built on top of: [`ws`](#ws-fixture), [`make_random`](#make-random-fixture) +This fixture is built on top of: [`ws`](#ws-fixture), [`make_random`](#make_random-fixture) [[back to top](#python-testing-for-databricks)] ### `make_secret_scope` fixture +Fixture to create secret scopes. - Fixture to create secret scopes. +This fixture provides a function to create secret scopes using the provided workspace (ws) +and the make_random function for generating unique names. The created secret scope will be +deleted after the test is complete. - This fixture provides a function to create secret scopes using the provided workspace (ws) - and the make_random function for generating unique names. The created secret scope will be - deleted after the test is complete. +Parameters: +----------- +ws : WorkspaceClient + A Databricks WorkspaceClient instance. +make_random : function + The make_random fixture to generate unique names. - Parameters: - ----------- - ws : WorkspaceClient - A Databricks WorkspaceClient instance. - make_random : function - The make_random fixture to generate unique names. +Returns: +-------- +function: + A function to create secret scopes. - Returns: - -------- - function: - A function to create secret scopes. +Usage Example: +-------------- +To create a secret scope and use it within a test function: - Usage Example: - -------------- - To create a secret scope and use it within a test function: +.. code-block:: python - .. code-block:: python + def test_secret_scope_creation(make_secret_scope): + secret_scope_name = make_secret_scope() + assert secret_scope_name.startswith("sdk-") - def test_secret_scope_creation(make_secret_scope): - secret_scope_name = make_secret_scope() - assert secret_scope_name.startswith("sdk-") - - -This fixture is built on top of: [`ws`](#ws-fixture), [`make_random`](#make-random-fixture) +This fixture is built on top of: [`ws`](#ws-fixture), [`make_random`](#make_random-fixture) [[back to top](#python-testing-for-databricks)] ### `make_secret_scope_acl` fixture +Fixture to manage secret scope access control lists (ACLs). - Fixture to manage secret scope access control lists (ACLs). - - This fixture provides a function to manage access control lists (ACLs) for secret scopes - using the provided workspace (ws). ACLs define permissions for principals (users or groups) - on specific secret scopes. +This fixture provides a function to manage access control lists (ACLs) for secret scopes +using the provided workspace (ws). ACLs define permissions for principals (users or groups) +on specific secret scopes. - Parameters: - ----------- - ws : WorkspaceClient - A Databricks WorkspaceClient instance. +Parameters: +----------- +ws : WorkspaceClient + A Databricks WorkspaceClient instance. - Returns: - -------- - function: - A function to manage secret scope ACLs. +Returns: +-------- +function: + A function to manage secret scope ACLs. - Usage Example: - -------------- - To manage secret scope ACLs using the make_secret_scope_acl fixture: +Usage Example: +-------------- +To manage secret scope ACLs using the make_secret_scope_acl fixture: - .. code-block:: python +.. code-block:: python - def test_secret_scope_acl_management(make_secret_scope_acl): - scope_name = "my_secret_scope" - principal_name = "user@example.com" - permission = workspace.AclPermission.READ + def test_secret_scope_acl_management(make_secret_scope_acl): + scope_name = "my_secret_scope" + principal_name = "user@example.com" + permission = workspace.AclPermission.READ - acl_info = make_secret_scope_acl(scope=scope_name, principal=principal_name, permission=permission) - assert acl_info == (scope_name, principal_name) - + acl_info = make_secret_scope_acl(scope=scope_name, principal=principal_name, permission=permission) + assert acl_info == (scope_name, principal_name) This fixture is built on top of: [`ws`](#ws-fixture) @@ -518,7 +485,7 @@ This fixture is built on top of: [`ws`](#ws-fixture) ### `make_udf` fixture _No description yet._ -This fixture is built on top of: [`ws`](#ws-fixture), [`env_or_skip`](#env-or-skip-fixture), [`sql_backend`](#sql-backend-fixture), [`make_schema`](#make-schema-fixture), [`make_random`](#make-random-fixture) +This fixture is built on top of: [`ws`](#ws-fixture), [`env_or_skip`](#env_or_skip-fixture), [`sql_backend`](#sql_backend-fixture), [`make_schema`](#make_schema-fixture), [`make_random`](#make_random-fixture) [[back to top](#python-testing-for-databricks)] @@ -526,7 +493,7 @@ This fixture is built on top of: [`ws`](#ws-fixture), [`env_or_skip`](#env-or-sk ### `make_catalog` fixture _No description yet._ -This fixture is built on top of: [`ws`](#ws-fixture), [`sql_backend`](#sql-backend-fixture), [`make_random`](#make-random-fixture) +This fixture is built on top of: [`ws`](#ws-fixture), [`sql_backend`](#sql_backend-fixture), [`make_random`](#make_random-fixture) [[back to top](#python-testing-for-databricks)] @@ -534,7 +501,7 @@ This fixture is built on top of: [`ws`](#ws-fixture), [`sql_backend`](#sql-backe ### `make_schema` fixture _No description yet._ -This fixture is built on top of: [`ws`](#ws-fixture), [`sql_backend`](#sql-backend-fixture), [`make_random`](#make-random-fixture) +This fixture is built on top of: [`ws`](#ws-fixture), [`sql_backend`](#sql_backend-fixture), [`make_random`](#make_random-fixture) [[back to top](#python-testing-for-databricks)] @@ -542,7 +509,7 @@ This fixture is built on top of: [`ws`](#ws-fixture), [`sql_backend`](#sql-backe ### `make_table` fixture _No description yet._ -This fixture is built on top of: [`ws`](#ws-fixture), [`sql_backend`](#sql-backend-fixture), [`make_schema`](#make-schema-fixture), [`make_random`](#make-random-fixture) +This fixture is built on top of: [`ws`](#ws-fixture), [`sql_backend`](#sql_backend-fixture), [`make_schema`](#make_schema-fixture), [`make_random`](#make_random-fixture) [[back to top](#python-testing-for-databricks)] @@ -556,25 +523,25 @@ This fixture is built on top of: [[back to top](#python-testing-for-databricks)] ### `sql_backend` fixture -Create and provide a SQL backend for executing statements. +te and provide a SQL backend for executing statements. -This fixture is built on top of: [`ws`](#ws-fixture), [`env_or_skip`](#env-or-skip-fixture) +This fixture is built on top of: [`ws`](#ws-fixture), [`env_or_skip`](#env_or_skip-fixture) [[back to top](#python-testing-for-databricks)] ### `sql_exec` fixture -Execute SQL statement and don't return any results. +ute SQL statement and don't return any results. -This fixture is built on top of: [`sql_backend`](#sql-backend-fixture) +This fixture is built on top of: [`sql_backend`](#sql_backend-fixture) [[back to top](#python-testing-for-databricks)] ### `sql_fetch_all` fixture -Fetch all rows from a SQL statement. +h all rows from a SQL statement. -This fixture is built on top of: [`sql_backend`](#sql-backend-fixture) +This fixture is built on top of: [`sql_backend`](#sql_backend-fixture) [[back to top](#python-testing-for-databricks)] @@ -582,7 +549,7 @@ This fixture is built on top of: [`sql_backend`](#sql-backend-fixture) ### `workspace_library` fixture _No description yet._ -This fixture is built on top of: [`ws`](#ws-fixture), [`fresh_local_wheel_file`](#fresh-local-wheel-file-fixture), [`make_random`](#make-random-fixture) +This fixture is built on top of: [`ws`](#ws-fixture), [`fresh_local_wheel_file`](#fresh_local_wheel_file-fixture), [`make_random`](#make_random-fixture) [[back to top](#python-testing-for-databricks)] diff --git a/scripts/gen-readme.py b/scripts/gen-readme.py index 973c7fb..fb87057 100644 --- a/scripts/gen-readme.py +++ b/scripts/gen-readme.py @@ -23,14 +23,17 @@ class Fixture: @staticmethod def ref(name: str) -> str: - anchor = name.replace("_", "-") - return f"[`{name}`](#{anchor}-fixture)" + return f"[`{name}`](#{name}-fixture)" + + def usage(self) -> str: + lines = "\n".join(_[4:] for _ in self.description.split("\n")) + return lines.strip() def doc(self) -> str: return "\n".join( [ f"### `{self.name}` fixture", - self.description if self.description else "_No description yet._", + self.usage() if self.description else "_No description yet._", "", f"This fixture is built on top of: {', '.join([self.ref(up) for up in self.upstreams])}", "", diff --git a/src/databricks/labs/pytester/fixtures/baseline.py b/src/databricks/labs/pytester/fixtures/baseline.py index a3d5cba..0299b3e 100644 --- a/src/databricks/labs/pytester/fixtures/baseline.py +++ b/src/databricks/labs/pytester/fixtures/baseline.py @@ -32,26 +32,19 @@ def make_random(): The generated strings are created using a character set consisting of uppercase letters, lowercase letters, and digits. - Returns: - -------- - function: - A function to generate random strings. - - Usage Example: - -------------- To generate a random string with default length of 16 characters: - .. code-block:: python - - random_string = make_random() - assert len(random_string) == 16 + ```python + random_string = make_random() + assert len(random_string) == 16 + ``` To generate a random string with a specified length: - .. code-block:: python - - random_string = make_random(k=8) - assert len(random_string) == 8 + ```python + random_string = make_random(k=8) + assert len(random_string) == 8 + ``` """ def inner(k=16) -> str: