Skip to content

Commit

Permalink
audio artifact unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewfrench committed Apr 24, 2024
1 parent d05e557 commit 41f8f0c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion griptape/artifacts/audio_artifact.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from attr import define, field
from attr import define

from griptape.artifacts import MediaArtifact

Expand Down
34 changes: 34 additions & 0 deletions tests/unit/artifacts/test_audio_artifact.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import pytest
from griptape.artifacts import AudioArtifact, BaseArtifact


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

def test_mime_type(self, audio_artifact: AudioArtifact):
assert audio_artifact.mime_type == "audio/pcm"

def test_to_text(self, audio_artifact: AudioArtifact):
assert audio_artifact.to_text() == "Media, type: audio/pcm, size: 22 bytes"

def test_to_dict(self, audio_artifact: AudioArtifact):
audio_dict = audio_artifact.to_dict()

assert audio_dict["format"] == "pcm"
assert audio_dict["model"] == "provider/model"
assert audio_dict["prompt"] == "two words"
assert audio_dict["value"] == "c29tZSBiaW5hcnkgYXVkaW8gZGF0YQ=="

def test_deserialization(self, audio_artifact):
artifact_dict = audio_artifact.to_dict()
deserialized_artifact = BaseArtifact.from_dict(artifact_dict)

assert isinstance(deserialized_artifact, AudioArtifact)

assert deserialized_artifact.value == b"some binary audio data"
assert deserialized_artifact.mime_type == "audio/pcm"
assert deserialized_artifact.format == "pcm"
assert deserialized_artifact.model == "provider/model"
assert deserialized_artifact.prompt == "two words"

0 comments on commit 41f8f0c

Please sign in to comment.