Skip to content

Commit

Permalink
Add flake8-pytest-style
Browse files Browse the repository at this point in the history
  • Loading branch information
collindutter committed Jul 16, 2024
1 parent 2225ca1 commit d71889c
Show file tree
Hide file tree
Showing 163 changed files with 335 additions and 337 deletions.
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ select = [
"COM", # flake8-commas
"C4", # flake8-comprehensions
"ANN", # flake8-annotations
"PT", # flake8-pytest-style
]
ignore = [
"UP007", # non-pep604-annotation
Expand All @@ -237,12 +238,15 @@ ignore = [
"ANN101", # missing-type-self
"ANN102", # missing-type-cls
"ANN401", # any-type
"PT011", # pytest-raises-too-broad
]
[tool.ruff.lint.pydocstyle]
convention = "google"

[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["I"]
"__init__.py" = [
"I" # isort
]
"tests/*" = [
"ANN001", # missing-type-function-argument
"ANN201", # missing-return-type-undocumented-public-function
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ class TestPgVectorVectorStoreDriver:
vec1 = [0.1, 0.2, 0.3]
vec2 = [0.4, 0.5, 0.6]

@pytest.fixture
@pytest.fixture()
def embedding_driver(self):
return MockEmbeddingDriver()

@pytest.fixture
@pytest.fixture()
def vector_store_driver(self, embedding_driver):
driver = PgVectorVectorStoreDriver(
connection_string=self.connection_string, embedding_driver=embedding_driver, table_name=self.table_name
Expand All @@ -30,8 +30,8 @@ def vector_store_driver(self, embedding_driver):
return driver

def test_initialize_requires_engine_or_connection_string(self, embedding_driver):
driver = PgVectorVectorStoreDriver(embedding_driver=embedding_driver, table_name=self.table_name)
with pytest.raises(ValueError):
driver = PgVectorVectorStoreDriver(embedding_driver=embedding_driver, table_name=self.table_name)
driver.setup()

def test_initialize_accepts_engine(self, embedding_driver):
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/artifacts/test_audio_artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


class TestAudioArtifact:
@pytest.fixture
@pytest.fixture()
def audio_artifact(self):
return AudioArtifact(value=b"some binary audio data", format="pcm", model="provider/model", prompt="two words")

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/artifacts/test_base_media_artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class TestMediaArtifact:
class ImaginaryMediaArtifact(MediaArtifact):
media_type: str = "imagination"

@pytest.fixture
@pytest.fixture()
def media_artifact(self):
return self.ImaginaryMediaArtifact(value=b"some binary dream data", format="dream")

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/artifacts/test_image_artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


class TestImageArtifact:
@pytest.fixture
@pytest.fixture()
def image_artifact(self):
return ImageArtifact(
value=b"some binary png image data",
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/chunkers/test_markdown_chunker.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


class TestTextChunker:
@pytest.fixture
@pytest.fixture()
def chunker(self):
return MarkdownChunker(max_tokens=MAX_TOKENS)

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/chunkers/test_pdf_chunker.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


class TestPdfChunker:
@pytest.fixture
@pytest.fixture()
def chunker(self):
return PdfChunker(max_tokens=MAX_TOKENS)

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/chunkers/test_text_chunker.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


class TestTextChunker:
@pytest.fixture
@pytest.fixture()
def chunker(self):
return TextChunker(max_tokens=MAX_TOKENS)

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/common/test_prompt_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


class TestPromptStack:
@pytest.fixture
@pytest.fixture()
def prompt_stack(self):
return PromptStack()

Expand Down
10 changes: 5 additions & 5 deletions tests/unit/config/test_amazon_bedrock_structure_config.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import boto3
from pytest import fixture
import pytest

from griptape.config import AmazonBedrockStructureConfig
from tests.utils.aws import mock_aws_credentials


class TestAmazonBedrockStructureConfig:
@fixture(autouse=True)
def run_before_and_after_tests(self):
@pytest.fixture(autouse=True)
def _run_before_and_after_tests(self):
mock_aws_credentials()

@fixture
@pytest.fixture()
def config(self):
mock_aws_credentials()
return AmazonBedrockStructureConfig()

@fixture
@pytest.fixture()
def config_with_values(self):
return AmazonBedrockStructureConfig(
session=boto3.Session(
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/config/test_anthropic_structure_config.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
from pytest import fixture
import pytest

from griptape.config import AnthropicStructureConfig


class TestAnthropicStructureConfig:
@fixture(autouse=True)
def mock_anthropic(self, mocker):
@pytest.fixture(autouse=True)
def _mock_anthropic(self, mocker):
mocker.patch("anthropic.Anthropic")
mocker.patch("voyageai.Client")

@fixture
@pytest.fixture()
def config(self):
return AnthropicStructureConfig()

Expand Down
6 changes: 3 additions & 3 deletions tests/unit/config/test_azure_openai_structure_config.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from pytest import fixture
import pytest

from griptape.config import AzureOpenAiStructureConfig


class TestAzureOpenAiStructureConfig:
@fixture(autouse=True)
@pytest.fixture(autouse=True)
def mock_openai(self, mocker):
return mocker.patch("openai.AzureOpenAI")

@fixture
@pytest.fixture()
def config(self):
return AzureOpenAiStructureConfig(
azure_endpoint="http://localhost:8080",
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/config/test_cohere_structure_config.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from pytest import fixture
import pytest

from griptape.config import CohereStructureConfig


class TestCohereStructureConfig:
@fixture
@pytest.fixture()
def config(self):
return CohereStructureConfig(api_key="api_key")

Expand Down
6 changes: 3 additions & 3 deletions tests/unit/config/test_google_structure_config.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from pytest import fixture
import pytest

from griptape.config import GoogleStructureConfig


class TestGoogleStructureConfig:
@fixture(autouse=True)
@pytest.fixture(autouse=True)
def mock_openai(self, mocker):
return mocker.patch("google.generativeai.GenerativeModel")

@fixture
@pytest.fixture()
def config(self):
return GoogleStructureConfig()

Expand Down
6 changes: 3 additions & 3 deletions tests/unit/config/test_openai_structure_config.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from pytest import fixture
import pytest

from griptape.config import OpenAiStructureConfig


class TestOpenAiStructureConfig:
@fixture(autouse=True)
@pytest.fixture(autouse=True)
def mock_openai(self, mocker):
return mocker.patch("openai.OpenAI")

@fixture
@pytest.fixture()
def config(self):
return OpenAiStructureConfig()

Expand Down
4 changes: 2 additions & 2 deletions tests/unit/config/test_structure_config.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from pytest import fixture
import pytest

from griptape.config import StructureConfig


class TestStructureConfig:
@fixture
@pytest.fixture()
def config(self):
return StructureConfig()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class TestAmazonBedrockCohereEmbeddingDriver:
@pytest.fixture(autouse=True)
def mock_session(self, mocker):
def _mock_session(self, mocker):
fake_embeddings = '{"embeddings": [[0, 1, 0]] }'

mock_session_class = mocker.patch("boto3.Session")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class TestAmazonBedrockTitanEmbeddingDriver:
@pytest.fixture(autouse=True)
def mock_session(self, mocker):
def _mock_session(self, mocker):
fake_embeddings = '{"embedding": [0, 1, 0]}'

mock_session_class = mocker.patch("boto3.Session")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def mock_openai(self, mocker):

return mock_chat_create

@pytest.fixture
@pytest.fixture()
def driver(self):
return AzureOpenAiEmbeddingDriver(azure_endpoint="foobar", model="gpt-4", azure_deployment="foobar")

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/drivers/embedding/test_base_embedding_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


class TestBaseEmbeddingDriver:
@pytest.fixture
@pytest.fixture()
def driver(self):
return MockEmbeddingDriver()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


class TestDummyEmbeddingDriver:
@pytest.fixture
@pytest.fixture()
def embedding_driver(self):
return DummyEmbeddingDriver()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,17 @@ def test_try_embed_chunk(self, mock_client):
).try_embed_chunk("foobar") == [0, 2, 0]

mock_client.get().read.return_value = b'{"embedding": []}'
with pytest.raises(ValueError) as e:
with pytest.raises(ValueError, match="model response is empty"):
assert AmazonSageMakerJumpstartEmbeddingDriver(
endpoint="test-endpoint",
model="test-model",
tokenizer=OpenAiTokenizer(model=OpenAiTokenizer.DEFAULT_OPENAI_GPT_3_CHAT_MODEL),
).try_embed_chunk("foobar") == [0, 2, 0]
assert str(e) == "model response is empty"

mock_client.get().read.return_value = b"{}"
with pytest.raises(ValueError) as e:
with pytest.raises(ValueError, match="invalid response from model"):
assert AmazonSageMakerJumpstartEmbeddingDriver(
endpoint="test-endpoint",
model="test-model",
tokenizer=OpenAiTokenizer(model=OpenAiTokenizer.DEFAULT_OPENAI_GPT_3_CHAT_MODEL),
).try_embed_chunk("foobar") == [0, 2, 0]
assert str(e) == "invalid response from model"
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import boto3
import pytest
from moto import mock_sqs
from pytest import fixture

from griptape.drivers.event_listener.amazon_sqs_event_listener_driver import AmazonSqsEventListenerDriver
from tests.mocks.mock_event import MockEvent
from tests.utils.aws import mock_aws_credentials


class TestAmazonSqsEventListenerDriver:
@fixture()
def run_before_and_after_tests(self):
@pytest.fixture()
def _run_before_and_after_tests(self):
mock_aws_credentials()

@fixture()
@pytest.fixture()
def driver(self):
mock = mock_sqs()
mock.start()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import boto3
import pytest
from moto import mock_iotdata
from pytest import fixture

from griptape.drivers.event_listener.aws_iot_core_event_listener_driver import AwsIotCoreEventListenerDriver
from tests.mocks.mock_event import MockEvent
Expand All @@ -9,11 +9,11 @@

@mock_iotdata
class TestAwsIotCoreEventListenerDriver:
@fixture(autouse=True)
def run_before_and_after_tests(self):
@pytest.fixture(autouse=True)
def _run_before_and_after_tests(self):
mock_aws_credentials()

@fixture()
@pytest.fixture()
def driver(self):
return AwsIotCoreEventListenerDriver(
iot_endpoint="foo bar", topic="fizz buzz", session=boto3.Session(region_name="us-east-1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
from unittest.mock import Mock

import pytest
from pytest import fixture

from griptape.drivers.event_listener.griptape_cloud_event_listener_driver import GriptapeCloudEventListenerDriver
from tests.mocks.mock_event import MockEvent


class TestGriptapeCloudEventListenerDriver:
@fixture(autouse=True)
@pytest.fixture(autouse=True)
def mock_post(self, mocker):
data = {"data": {"id": "test"}}

Expand All @@ -18,7 +17,7 @@ def mock_post(self, mocker):

return mock_post

@fixture()
@pytest.fixture()
def driver(self):
os.environ["GT_CLOUD_BASE_URL"] = "https://cloud123.griptape.ai"

Expand Down
Loading

0 comments on commit d71889c

Please sign in to comment.