Skip to content

Commit 3f3374c

Browse files
committed
chore: tests
1 parent d4a1bd3 commit 3f3374c

1 file changed

Lines changed: 89 additions & 33 deletions

File tree

tests/test_datasets.py

Lines changed: 89 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ def test_get_dataset_runs():
220220

221221
langfuse.flush()
222222
time.sleep(1) # Give API time to process
223-
runs = langfuse.api.datasets.get_runs(dataset_name)
223+
runs = langfuse.get_dataset_runs(dataset_name=dataset_name)
224224

225225
assert len(runs.data) == 2
226226
assert runs.data[0].name == run_name_2
@@ -421,52 +421,108 @@ def execute_dataset_item(item, run_name):
421421
assert trace.output == expected_input
422422

423423

424-
def test_dataset_runs_with_special_characters():
425-
"""Test that dataset runs work correctly with special characters in names."""
424+
def test_get_dataset_with_folder_name():
425+
"""Test that get_dataset works with folder-format names containing slashes."""
426426
langfuse = Langfuse(debug=False)
427427

428-
# Test with various special characters that need URL encoding
429-
dataset_name = f"test/dataset with spaces & special chars {create_uuid()[:5]}"
430-
run_name = f"run/name with % and # {create_uuid()[:5]}"
428+
# Create a dataset with slashes in the name (folder format)
429+
folder_name = f"folder/subfolder/dataset-{create_uuid()[:8]}"
430+
langfuse.create_dataset(name=folder_name)
431431

432-
langfuse.create_dataset(name=dataset_name)
433-
input_data = json.dumps({"input": "Test data"})
434-
langfuse.create_dataset_item(dataset_name=dataset_name, input=input_data)
432+
# Fetch the dataset using the wrapper method
433+
dataset = langfuse.get_dataset(folder_name)
434+
assert dataset.name == folder_name
435+
assert "/" in dataset.name # Verify slashes are preserved
435436

436-
dataset = langfuse.get_dataset(dataset_name)
437+
438+
def test_get_dataset_runs_with_folder_name():
439+
"""Test that get_dataset_runs works with folder-format dataset names."""
440+
langfuse = Langfuse(debug=False)
441+
442+
# Create a dataset with slashes in the name
443+
folder_name = f"folder/subfolder/dataset-{create_uuid()[:8]}"
444+
langfuse.create_dataset(name=folder_name)
445+
446+
# Create a dataset item
447+
langfuse.create_dataset_item(dataset_name=folder_name, input={"test": "data"})
448+
dataset = langfuse.get_dataset(folder_name)
437449
assert len(dataset.items) == 1
438450

439-
# Create a dataset run with special characters in the run name
451+
# Create a run
452+
run_name = f"run-{create_uuid()[:8]}"
440453
for item in dataset.items:
441-
with item.run(
442-
run_name=run_name,
443-
run_metadata={"test": "value"},
444-
run_description="Test run with special chars",
445-
):
454+
with item.run(run_name=run_name):
446455
pass
447456

448457
langfuse.flush()
449-
time.sleep(1)
458+
time.sleep(1) # Give API time to process
450459

451-
# Test get_dataset_runs with special characters in dataset name
452-
runs = langfuse.get_dataset_runs(dataset_name=dataset_name)
460+
# Fetch runs using the new wrapper method
461+
runs = langfuse.get_dataset_runs(dataset_name=folder_name)
453462
assert len(runs.data) == 1
454463
assert runs.data[0].name == run_name
455-
assert runs.data[0].metadata == {"test": "value"}
456-
assert runs.data[0].description == "Test run with special chars"
457464

458-
# Test get_dataset_run with special characters in both dataset and run name
459-
run = langfuse.get_dataset_run(dataset_name=dataset_name, run_name=run_name)
465+
466+
def test_get_dataset_run_with_folder_names():
467+
"""Test that get_dataset_run works with folder-format dataset and run names."""
468+
langfuse = Langfuse(debug=False)
469+
470+
# Create a dataset with slashes in the name
471+
folder_name = f"folder/subfolder/dataset-{create_uuid()[:8]}"
472+
langfuse.create_dataset(name=folder_name)
473+
474+
# Create a dataset item
475+
langfuse.create_dataset_item(dataset_name=folder_name, input={"test": "data"})
476+
dataset = langfuse.get_dataset(folder_name)
477+
assert len(dataset.items) == 1
478+
479+
# Create a run with slashes in the name
480+
run_name = f"run/nested/{create_uuid()[:8]}"
481+
for item in dataset.items:
482+
with item.run(run_name=run_name, run_metadata={"key": "value"}):
483+
pass
484+
485+
langfuse.flush()
486+
time.sleep(1) # Give API time to process
487+
488+
# Fetch the specific run using the new wrapper method
489+
run = langfuse.get_dataset_run(dataset_name=folder_name, run_name=run_name)
460490
assert run.run_name == run_name
461-
assert run.dataset_name == dataset_name
462-
assert len(run.dataset_run_items) == 1
491+
assert run.metadata == {"key": "value"}
492+
assert "/" in folder_name # Verify slashes are preserved
463493

464-
# Test delete_dataset_run with special characters
465-
delete_response = langfuse.delete_dataset_run(
466-
dataset_name=dataset_name, run_name=run_name
467-
)
468-
assert delete_response.deleted_run_items_count == 1
469494

470-
# Verify the run was deleted
471-
runs_after_delete = langfuse.get_dataset_runs(dataset_name=dataset_name)
472-
assert len(runs_after_delete.data) == 0
495+
def test_delete_dataset_run_with_folder_names():
496+
"""Test that delete_dataset_run works with folder-format dataset and run names."""
497+
langfuse = Langfuse(debug=False)
498+
499+
# Create a dataset with slashes in the name
500+
folder_name = f"folder/subfolder/dataset-{create_uuid()[:8]}"
501+
langfuse.create_dataset(name=folder_name)
502+
503+
# Create a dataset item
504+
langfuse.create_dataset_item(dataset_name=folder_name, input={"test": "data"})
505+
dataset = langfuse.get_dataset(folder_name)
506+
507+
# Create a run with slashes in the name
508+
run_name = f"run/to/delete/{create_uuid()[:8]}"
509+
for item in dataset.items:
510+
with item.run(run_name=run_name):
511+
pass
512+
513+
langfuse.flush()
514+
time.sleep(1) # Give API time to process
515+
516+
# Verify the run exists
517+
runs_before = langfuse.get_dataset_runs(dataset_name=folder_name)
518+
assert len(runs_before.data) == 1
519+
520+
# Delete the run using the new wrapper method
521+
result = langfuse.delete_dataset_run(dataset_name=folder_name, run_name=run_name)
522+
assert result.deleted_run_items_count == 1
523+
524+
time.sleep(1) # Give API time to process deletion
525+
526+
# Verify the run is deleted
527+
runs_after = langfuse.get_dataset_runs(dataset_name=folder_name)
528+
assert len(runs_after.data) == 0

0 commit comments

Comments
 (0)