Skip to content

Commit

Permalink
Appease code cov
Browse files Browse the repository at this point in the history
  • Loading branch information
collindutter committed Sep 10, 2024
1 parent 52bd7f2 commit 27c1701
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion griptape/artifacts/boolean_artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __add__(self, other: BaseArtifact) -> BooleanArtifact:
raise ValueError("Cannot add BooleanArtifact with other artifacts")

def __eq__(self, value: object) -> bool:
return self.value is value
return self.value == value

def to_text(self) -> str:
return str(self.value).lower()
10 changes: 10 additions & 0 deletions tests/unit/artifacts/test_blob_artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ def test_value_type_conversion(self):
def test_to_text(self):
assert BlobArtifact(b"foobar", name="foobar.txt").to_text() == "foobar"

def test_to_bytes(self):
assert BlobArtifact(b"foo").to_bytes() == b"foo"

def test_to_text_encoding(self):
assert (
BlobArtifact("ß".encode("ascii", errors="backslashreplace"), name="foobar.txt", encoding="ascii").to_text()
Expand Down Expand Up @@ -50,6 +53,13 @@ def test_deserialization(self):
def test_name(self):
assert BlobArtifact(b"foo", name="bar").name == "bar"

def test_mime_type(self):
assert BlobArtifact(b"foo").mime_type == "application/octet-stream"

def test___add__(self):
with pytest.raises(TypeError):
BlobArtifact(b"foo") + BlobArtifact(b"bar")

def test___bool__(self):
assert not bool(BlobArtifact(b""))
assert bool(BlobArtifact(b"foo"))
11 changes: 11 additions & 0 deletions tests/unit/artifacts/test_boolean_artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def test_parse_bool(self):
assert BooleanArtifact.parse_bool("false").value is False
assert BooleanArtifact.parse_bool("True").value is True
assert BooleanArtifact.parse_bool("False").value is False
assert BooleanArtifact.parse_bool(True).value is True

with pytest.raises(ValueError):
BooleanArtifact.parse_bool("foo")
Expand All @@ -35,3 +36,13 @@ def test_value_type_conversion(self):
assert BooleanArtifact([]).value is False
assert BooleanArtifact(False).value is False
assert BooleanArtifact(True).value is True

def test_to_text(self):
assert BooleanArtifact(True).to_text() == "true"
assert BooleanArtifact(False).to_text() == "false"

def test__eq__(self):
assert BooleanArtifact(True) == BooleanArtifact(True)
assert BooleanArtifact(False) == BooleanArtifact(False)
assert BooleanArtifact(True) != BooleanArtifact(False)
assert BooleanArtifact(False) != BooleanArtifact(True)
5 changes: 5 additions & 0 deletions tests/unit/artifacts/test_text_artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ def test___add__(self):
def test_to_dict(self):
assert TextArtifact("foobar").to_dict()["value"] == "foobar"

def test_to_bytes(self):
artifact = TextArtifact("foobar")

assert artifact.to_bytes() == b"foobar"

def test_from_dict(self):
assert BaseArtifact.from_dict(TextArtifact("foobar").to_dict()).value == "foobar"

Expand Down

0 comments on commit 27c1701

Please sign in to comment.