Skip to content

Commit

Permalink
chore(weave): Adds test for recent dictify change (#3461)
Browse files Browse the repository at this point in the history
* init

* init

* lint
  • Loading branch information
tssweeney authored Jan 22, 2025
1 parent 7b2b7e0 commit eddbff1
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions tests/trace/test_dictifiable.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import weave


def test_dictifiable(client):
class NonDictifiable:
attr: int

def __init__(self, attr: int):
self.attr = attr

class Dictifiable:
attr: int

def __init__(self, attr: int):
self.attr = attr

def to_dict(self):
return {"attr": self.attr}

@weave.op
def func(d: Dictifiable, nd: NonDictifiable) -> dict:
return {
"d": Dictifiable(d.attr),
"nd": NonDictifiable(nd.attr),
}

val = 42
d = Dictifiable(val)
nd = NonDictifiable(val)
res = func(d, nd)
assert isinstance(res["d"], Dictifiable)
assert res["d"].attr == val
assert isinstance(res["nd"], NonDictifiable)
assert res["nd"].attr == val

call = func.calls()[0]

assert call.inputs["d"] == {"attr": val}
assert call.inputs["nd"].startswith(
"<test_dictifiable.test_dictifiable.<locals>.NonDictifiable object at"
)
assert call.output["d"] == {"attr": val}
assert call.output["nd"].startswith(
"<test_dictifiable.test_dictifiable.<locals>.NonDictifiable object at"
)

0 comments on commit eddbff1

Please sign in to comment.