Skip to content

Commit

Permalink
test: add test for string version object read (#2479)
Browse files Browse the repository at this point in the history
  • Loading branch information
gtarpenning authored Sep 25, 2024
1 parent 05e81b0 commit a4ee3ae
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
5 changes: 1 addition & 4 deletions weave/tests/trace/test_client_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
DatetimeMatcher,
FuzzyDateTimeMatcher,
MaybeStringMatcher,
client_is_sqlite,
)
from weave.trace import weave_client
from weave.trace.object_record import ObjectRecord
Expand Down Expand Up @@ -791,10 +792,6 @@ def basic_op(in_val: dict) -> dict:
assert call.inputs["in_val"].get("prim") == seq[i]


def client_is_sqlite(client):
return isinstance(client.server._internal_trace_server, SqliteTraceServer)


def test_trace_call_filter(client):
is_sqlite = client_is_sqlite(client)

Expand Down
32 changes: 31 additions & 1 deletion weave/tests/trace/test_weave_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@
import weave.trace_server.trace_server_interface as tsi
from weave import Evaluation
from weave.legacy.weave import op_def
from weave.tests.trace.util import AnyIntMatcher, DatetimeMatcher, RegexStringMatcher
from weave.tests.trace.util import (
AnyIntMatcher,
DatetimeMatcher,
RegexStringMatcher,
client_is_sqlite,
)
from weave.trace import refs, weave_client
from weave.trace.isinstance import weave_isinstance
from weave.trace.op import Op, is_op
Expand Down Expand Up @@ -1405,6 +1410,9 @@ def f(a):


def test_object_version_read(client):
if client_is_sqlite(client):
return

refs = []
for i in range(10):
refs.append(weave.publish({"a": i}))
Expand Down Expand Up @@ -1439,3 +1447,25 @@ def test_object_version_read(client):
)
assert obj_res.obj.val == {"a": i}
assert obj_res.obj.version_index == i

# now grab the latest version of the object
obj_res = client.server.obj_read(
tsi.ObjReadReq(
project_id=client._project_id(),
object_id=refs[0].name,
digest="latest",
)
)
assert obj_res.obj.val == {"a": 9}
assert obj_res.obj.version_index == 9

# now grab version 5
obj_res = client.server.obj_read(
tsi.ObjReadReq(
project_id=client._project_id(),
object_id=refs[0].name,
digest="v5",
)
)
assert obj_res.obj.val == {"a": 5}
assert obj_res.obj.version_index == 5
6 changes: 6 additions & 0 deletions weave/tests/trace/util.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import datetime
import re

from weave.trace_server.sqlite_trace_server import SqliteTraceServer


def client_is_sqlite(client):
return isinstance(client.server._internal_trace_server, SqliteTraceServer)


class AnyIntMatcher:
"""Matches any integer."""
Expand Down

0 comments on commit a4ee3ae

Please sign in to comment.