Skip to content

Commit

Permalink
Remove pytest hack
Browse files Browse the repository at this point in the history
  • Loading branch information
collindutter committed Aug 8, 2024
1 parent 1711933 commit 6f386fe
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 129 deletions.
5 changes: 0 additions & 5 deletions docs/assets/css/extra.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,3 @@
.md-typeset table:not([class]) {
display: table;
}

/* Hide the code block title since we're using it for other purposes.*/
.filename {
display: none !important
}
2 changes: 1 addition & 1 deletion docs/examples/load-query-and-chat-marqo.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
```python title="PYTEST_IGNORE"
```python
--8<-- "docs/examples/src/load_query_and_chat_marqo_1.py"
```
14 changes: 1 addition & 13 deletions docs/examples/src/multi_agent_workflow_1.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os

from griptape.drivers import GoogleWebSearchDriver, LocalStructureRunDriver, WebhookEventListenerDriver
from griptape.events import EventListener, FinishStructureRunEvent, event_bus
from griptape.drivers import GoogleWebSearchDriver, LocalStructureRunDriver
from griptape.rules import Rule, Ruleset
from griptape.structures import Agent, Workflow
from griptape.tasks import PromptTask, StructureRunTask
Expand All @@ -24,17 +23,6 @@
},
]

event_bus.add_event_listeners(
[
EventListener(
event_types=[FinishStructureRunEvent],
driver=WebhookEventListenerDriver(
webhook_url=os.environ["WEBHOOK_URL"],
),
)
]
)


def build_researcher() -> Agent:
"""Builds a Researcher Structure."""
Expand Down
6 changes: 3 additions & 3 deletions docs/griptape-framework/drivers/embedding-drivers.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ The [OpenAiEmbeddingDriver](../../reference/griptape/drivers/embedding/openai_em
Many services such as [LMStudio](https://lmstudio.ai/) and [OhMyGPT](https://www.ohmygpt.com/) provide OpenAI-compatible APIs. You can use the [OpenAiEmbeddingDriver](../../reference/griptape/drivers/embedding/openai_embedding_driver.md) to interact with these services.
Simply set the `base_url` to the service's API endpoint and the `model` to the model name. If the service requires an API key, you can set it in the `api_key` field.

```python title="PYTEST_IGNORE"
```python
--8<-- "docs/griptape-framework/drivers/src/embedding_drivers_2.py"
```

Expand Down Expand Up @@ -91,7 +91,7 @@ The [HuggingFaceHubEmbeddingDriver](../../reference/griptape/drivers/embedding/h

The [OllamaEmbeddingDriver](../../reference/griptape/drivers/embedding/ollama_embedding_driver.md) uses the [Ollama Embeddings API](https://ollama.com/blog/embedding-models).

```python title="PYTEST_IGNORE"
```python
--8<-- "docs/griptape-framework/drivers/src/embedding_drivers_6.py"
```

Expand All @@ -102,7 +102,7 @@ The [AmazonSageMakerJumpstartEmbeddingDriver](../../reference/griptape/drivers/e
!!! info
This driver requires the `drivers-embedding-amazon-sagemaker` [extra](../index.md#extras).

```python title="PYTEST_IGNORE"
```python
--8<-- "docs/griptape-framework/drivers/src/embedding_drivers_7.py"
```

Expand Down
6 changes: 3 additions & 3 deletions docs/griptape-framework/drivers/image-generation-drivers.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ The [Stable Diffusion 3 Image Generation Pipeline Driver](../../reference/gripta

Image generation consumes substantial memory. On devices with limited VRAM, it may be necessary to enable the `enable_model_cpu_offload` or `drop_t5_encoder` configurations. For more information, see [HuggingFace's documentation](https://huggingface.co/docs/diffusers/en/optimization/memory) on reduced memory usage.

```python title="PYTEST_IGNORE"
```python
--8<-- "docs/griptape-framework/drivers/src/image_generation_drivers_7.py"
```

Expand All @@ -104,7 +104,7 @@ Image generation consumes substantial memory. On devices with limited VRAM, it m

The [Stable Diffusion 3 Img2Img Image Generation Pipeline Driver](../../reference/griptape/drivers/image_generation_pipeline/stable_diffusion_3_img_2_img_image_generation_pipeline_driver.md) provides a `StableDiffusion3Img2ImgPipeline` for image-to-image generations, accepting a text prompt and input image. This Driver accepts a text prompt, an input image, and configurations including Stable Diffusion 3 model, output image size, inference steps, generation seed, and strength of generation over the input image.

```python title="PYTEST_IGNORE"
```python
--8<-- "docs/griptape-framework/drivers/src/image_generation_drivers_8.py"
```

Expand All @@ -115,6 +115,6 @@ The [Stable Diffusion 3 Img2Img Image Generation Pipeline Driver](../../referenc

The [StableDiffusion3ControlNetImageGenerationPipelineDriver](../../reference/griptape/drivers/image_generation_pipeline/stable_diffusion_3_controlnet_image_generation_pipeline_driver.md) provides a `StableDiffusion3ControlNetPipeline` for image-to-image generations, accepting a text prompt and a control image. This Driver accepts a text prompt, a control image, and configurations including Stable Diffusion 3 model, ControlNet model, output image size, generation seed, inference steps, and the degree to which the model adheres to the control image.

```python title="PYTEST_IGNORE"
```python
--8<-- "docs/griptape-framework/drivers/src/image_generation_drivers_9.py"
```
4 changes: 2 additions & 2 deletions docs/griptape-framework/drivers/observability-drivers.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ The Griptape Cloud Observability Driver instruments `@observable` functions and
Here is an example of how to use the `GriptapeCloudObservabilityDriver` with the `Observability` context manager to send the telemetry to Griptape Cloud:


```python title="PYTEST_IGNORE"
```python
--8<-- "docs/griptape-framework/drivers/src/observability_drivers_1.py"
```

Expand All @@ -43,7 +43,7 @@ The [OpenTelemetry](https://opentelemetry.io/) Observability Driver instruments

Here is an example of how to use the `OpenTelemetryObservabilityDriver` with the `Observability` context manager to output the telemetry directly to the console:

```python title="PYTEST_IGNORE"
```python
--8<-- "docs/griptape-framework/drivers/src/observability_drivers_2.py"
```

Expand Down
6 changes: 3 additions & 3 deletions docs/griptape-framework/drivers/prompt-drivers.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ This driver uses [OpenAi function calling](https://platform.openai.com/docs/guid
Many services such as [LMStudio](https://lmstudio.ai/) and [OhMyGPT](https://www.ohmygpt.com/) provide OpenAI-compatible APIs. You can use the [OpenAiChatPromptDriver](../../reference/griptape/drivers/prompt/openai_chat_prompt_driver.md) to interact with these services.
Simply set the `base_url` to the service's API endpoint and the `model` to the model name. If the service requires an API key, you can set it in the `api_key` field.

```python title="PYTEST_IGNORE"
```python
--8<-- "docs/griptape-framework/drivers/src/prompt_drivers_4.py"
```

Expand Down Expand Up @@ -138,7 +138,7 @@ The [HuggingFaceHubPromptDriver](../../reference/griptape/drivers/prompt/hugging

The [HuggingFaceHubPromptDriver](#hugging-face-hub) also supports [Text Generation Interface](https://huggingface.co/docs/text-generation-inference/basic_tutorials/consuming_tgi#inference-client) for running models locally. To use Text Generation Interface, just set `model` to a TGI endpoint.

```python title="PYTEST_IGNORE"
```python
--8<-- "docs/griptape-framework/drivers/src/prompt_drivers_12.py"
```

Expand Down Expand Up @@ -168,6 +168,6 @@ This Driver has been primarily _chat-optimized_ models that have a [Huggingface
If your model does not fit this use-case, we suggest sub-classing [AmazonSageMakerJumpstartPromptDriver](../../reference/griptape/drivers/prompt/amazon_sagemaker_jumpstart_prompt_driver.md) and overriding the `_to_model_input` and `_to_model_params` methods.


```python title="PYTEST_IGNORE"
```python
--8<-- "docs/griptape-framework/drivers/src/prompt_drivers_14.py"
```
4 changes: 2 additions & 2 deletions docs/griptape-framework/structures/observability.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The [Observability](../../reference/griptape/observability/observability.md) con

Observability is completely optional. To opt in, wrap your application code with the [Observability](../../reference/griptape/observability/observability.md) context manager, for example:

```python title="PYTEST_IGNORE"
```python
--8<-- "docs/griptape-framework/structures/src/observability_1.py"
```

Expand All @@ -22,6 +22,6 @@ All functions and methods annotated with the `@observable` decorator will be tra

For example:

```python title="PYTEST_IGNORE"
```python
--8<-- "docs/griptape-framework/structures/src/observability_2.py"
```
2 changes: 1 addition & 1 deletion docs/griptape-tools/official-tools/computer.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This tool enables LLMs to execute Python code and run shell commands inside a Do

You can specify a local working directory and environment variables during tool initialization:

```python title="PYTEST_IGNORE"
```python
--8<-- "docs/griptape-tools/official-tools/src/computer_1.py"
```
```
Expand Down
50 changes: 37 additions & 13 deletions tests/integration/test_code_blocks.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,46 @@
import io
import os
import subprocess

import pytest

from tests.utils.code_blocks import check_py_string, get_all_code_blocks
SKIP_FILES = [
"docs/griptape-tools/official-tools/src/computer_1.py",
"docs/examples/src/load_query_and_chat_marqo_1.py",
"docs/griptape-framework/drivers/src/embedding_drivers_6.py",
"docs/griptape-framework/drivers/src/embedding_drivers_7.py",
"docs/griptape-framework/drivers/src/image_generation_drivers_7.py",
"docs/griptape-framework/drivers/src/image_generation_drivers_8.py",
"docs/griptape-framework/drivers/src/image_generation_drivers_9.py",
"docs/griptape-framework/drivers/src/prompt_drivers_4.py",
"docs/griptape-framework/drivers/src/prompt_drivers_12.py",
"docs/griptape-framework/drivers/src/prompt_drivers_14.py",
"docs/griptape-framework/drivers/src/observability_drivers_1.py",
"docs/griptape-framework/drivers/src/observability_drivers_2.py",
"docs/griptape-framework/structures/src/observability_1.py",
"docs/griptape-framework/structures/src/observability_2.py",
]

if "DOCS_ALL_CHANGED_FILES" in os.environ and os.environ["DOCS_ALL_CHANGED_FILES"] != "":
docs_all_changed_files = os.environ["DOCS_ALL_CHANGED_FILES"].split()

all_code_blocks = [get_all_code_blocks(changed_file) for changed_file in docs_all_changed_files]
all_code_blocks = [block for sublist in all_code_blocks for block in sublist]
else:
all_code_blocks = get_all_code_blocks("docs/**/*.md")
def discover_python_files(directory):
python_files = []
for root, _, files in os.walk(directory):
for file in files:
if file.endswith(".py"):
path = os.path.join(root, file)
python_files.append(
pytest.param(path, marks=pytest.mark.skipif(path in SKIP_FILES, reason="Skip file"))
)
return python_files


@pytest.mark.parametrize("block", all_code_blocks, ids=[f["id"] for f in all_code_blocks])
def test_code_block(block, monkeypatch):
# Send some stdin for tests that use the Chat util
monkeypatch.setattr("sys.stdin", io.StringIO("Hi\nexit\n"))
@pytest.mark.parametrize("python_file", discover_python_files("docs"))
def test_python_file_execution(python_file):
"""Test that the Python file executes successfully."""
result = subprocess.run(
["poetry", "run", "python", python_file],
capture_output=True,
text=True,
input="Hi\nexit\n",
)

check_py_string(block["code"])
assert result.returncode == 0, f"Execution failed for {python_file} with error: {result.stderr}"
83 changes: 0 additions & 83 deletions tests/utils/code_blocks.py

This file was deleted.

0 comments on commit 6f386fe

Please sign in to comment.