3
3
import pandas as pd
4
4
from unittest .mock import Mock , patch , mock_open
5
5
from judgeval .data .datasets .dataset import EvalDataset
6
+ from judgeval .data .datasets .eval_dataset_client import EvalDatasetClient
6
7
from judgeval .data import Example
7
8
from judgeval .data .datasets .ground_truth import GroundTruthExample
8
9
@@ -38,6 +39,10 @@ def sample_ground_truth():
38
39
def dataset ():
39
40
return EvalDataset (judgment_api_key = "test_key" )
40
41
42
+ @pytest .fixture
43
+ def eval_dataset_client ():
44
+ return EvalDatasetClient (judgment_api_key = "test_key" )
45
+
41
46
def test_init ():
42
47
dataset = EvalDataset (judgment_api_key = "test_key" )
43
48
assert dataset .judgment_api_key == "test_key"
@@ -57,7 +62,7 @@ def test_add_ground_truth(dataset, sample_ground_truth):
57
62
assert dataset .ground_truths [0 ] == sample_ground_truth
58
63
59
64
@patch ('requests.post' )
60
- def test_push_success (mock_post , dataset , sample_example ):
65
+ def test_push_success (mock_post , dataset , sample_example , eval_dataset_client ):
61
66
# Setup mock response
62
67
mock_response = Mock ()
63
68
mock_response .status_code = 200
@@ -66,26 +71,26 @@ def test_push_success(mock_post, dataset, sample_example):
66
71
67
72
# Add example and push
68
73
dataset .add_example (sample_example )
69
- result = dataset .push ("test_alias" )
74
+ result = eval_dataset_client .push (dataset , "test_alias" )
70
75
71
76
assert result is True
72
77
assert dataset ._alias == "test_alias"
73
78
assert dataset ._id == "test_id"
74
79
mock_post .assert_called_once ()
75
80
76
81
@patch ('requests.post' )
77
- def test_push_server_error (mock_post , dataset ):
82
+ def test_push_server_error (mock_post , dataset , eval_dataset_client ):
78
83
mock_response = Mock ()
79
84
mock_response .status_code = 500
80
85
mock_post .return_value = mock_response
81
86
82
- result = dataset .push ("test_alias" )
87
+ result = eval_dataset_client .push (dataset , "test_alias" )
83
88
assert result is False
84
89
85
90
mock_post .assert_called_once ()
86
91
87
92
@patch ('requests.post' )
88
- def test_pull_success (mock_post , dataset ):
93
+ def test_pull_success (mock_post , eval_dataset_client ):
89
94
mock_response = Mock ()
90
95
mock_response .status_code = 200
91
96
mock_response .json .return_value = {
@@ -96,11 +101,11 @@ def test_pull_success(mock_post, dataset):
96
101
}
97
102
mock_post .return_value = mock_response
98
103
99
- dataset .pull ("test_alias" )
100
- assert len (dataset .ground_truths ) == 1
101
- assert len (dataset .examples ) == 1
102
- assert dataset ._alias == "test_alias"
103
- assert dataset ._id == "test_id"
104
+ pulled_dataset = eval_dataset_client .pull ("test_alias" )
105
+ assert len (pulled_dataset .ground_truths ) == 1
106
+ assert len (pulled_dataset .examples ) == 1
107
+ assert pulled_dataset ._alias == "test_alias"
108
+ assert pulled_dataset ._id == "test_id"
104
109
105
110
@patch ('builtins.open' , new_callable = mock_open )
106
111
def test_add_from_json (mock_file , dataset ):
0 commit comments