Skip to content

Commit 124f787

Browse files
committed
add test for save_data
1 parent e86c503 commit 124f787

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import json
2+
import os
3+
4+
from dspy.clients.utils_finetune import save_data
5+
6+
7+
def test_save_data_writes_jsonl_to_finetune_directory(tmp_path, monkeypatch):
8+
monkeypatch.setenv("DSPY_FINETUNEDIR", str(tmp_path))
9+
data = [
10+
{"messages": [{"role": "user", "content": "What is 1 + 1?"}]},
11+
{"messages": [{"role": "assistant", "content": "2"}]},
12+
]
13+
14+
file_path = save_data(data)
15+
16+
assert os.path.isabs(file_path)
17+
assert os.path.dirname(file_path) == os.path.abspath(str(tmp_path))
18+
assert file_path.endswith(".jsonl")
19+
20+
with open(file_path, encoding="utf-8") as f:
21+
assert [json.loads(line) for line in f] == data

0 commit comments

Comments
 (0)