File tree Expand file tree Collapse file tree 1 file changed +13
-3
lines changed
Filter options
ml_engine/online_prediction Expand file tree Collapse file tree 1 file changed +13
-3
lines changed
Original file line number Diff line number Diff line change 22
22
MODEL = 'census'
23
23
JSON_VERSION = 'v2json'
24
24
PROJECT = 'python-docs-samples-tests'
25
+ CONF_KEY = u'confidence'
26
+ PRED_KEY = u'predictions'
25
27
EXPECTED_OUTPUT = {
26
- u'confidence' : 0.7760370969772339 ,
27
- u'predictions' : u' <=50K'
28
+ CONF_KEY : 0.7760370969772339 ,
29
+ PRED_KEY : u' <=50K'
28
30
}
31
+ CONFIDENCE_EPSILON = 1e-4
29
32
30
33
# Raise the socket timeout. The requests involved in the sample can take
31
34
# a long time to complete.
40
43
def test_predict_json ():
41
44
result = predict .predict_json (
42
45
PROJECT , MODEL , [JSON , JSON ], version = JSON_VERSION )
43
- assert [EXPECTED_OUTPUT , EXPECTED_OUTPUT ] == result
46
+ # Result contains two identical predictions
47
+ assert len (result ) == 2 and result [0 ] == result [1 ]
48
+ # Each prediction has `confidence` and `predictions`
49
+ assert result [0 ].keys () == EXPECTED_OUTPUT .keys ()
50
+ # Prediction matches
51
+ assert result [0 ][PRED_KEY ] == EXPECTED_OUTPUT [PRED_KEY ]
52
+ # Confidence within epsilon
53
+ assert abs (result [0 ][CONF_KEY ] - EXPECTED_OUTPUT [CONF_KEY ]) < CONFIDENCE_EPSILON
44
54
45
55
46
56
@pytest .mark .flaky
You can’t perform that action at this time.
0 commit comments