File size: 1,722 Bytes
cbf01bb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""
This file contains tests for the API of your model. You can run these tests by installing test requirements:

    ```bash
    pip install -r requirements-test.txt
    ```
Then execute `pytest` in the directory of this file.

- Change `NewModel` to the name of the class in your model.py file.
- Change the `request` and `expected_response` variables to match the input and output of your model.
"""

import pytest
import json
from model import BertClassifier


@pytest.fixture
def client():
    from _wsgi import init_app
    app = init_app(model_class=BertClassifier)
    app.config['TESTING'] = True
    with app.test_client() as client:
        yield client


def test_predict(client):
    request = {
        'tasks': [{
            'data': {
                'text': 'Today is a great day to play football.'
            }
        }],
        # Your labeling configuration here
        'label_config':
            '<View>'
            '<Text name="text" value="$text" />'
            '<Choices name="topic" toName="text" choice="single">'
            '<Choice value="sports" />'
            '<Choice value="politics" />'
            '<Choice value="technology" />'
            '</Choices>'
            '</View>'
    }

    expected_response_results = [{
        'result': [{
            'from_name': 'topic',
            'to_name': 'text',
            'type': 'choices',
            'value': {'choices': ['sports']}
        }]
    }]

    response = client.post('/predict', data=json.dumps(request), content_type='application/json')
    assert response.status_code == 200
    response = json.loads(response.data)
    assert len(expected_response_results) == len(response['results'])


# TODO
# Implement test_fit()