File tree 6 files changed +39
-12
lines changed
6 files changed +39
-12
lines changed Original file line number Diff line number Diff line change 3
3
pip install -r requirements.txt
4
4
5
5
test :
6
- python -m pytest -vv --cov=cli --cov=mlib --cov=utilscli test_mlib.py
6
+ python -m pytest -vv --cov=cli --cov=mlib --cov=utilscli --cov=app test_mlib.py
7
7
8
8
format :
9
9
black * .py
Original file line number Diff line number Diff line change 12
12
LOG = create_logger (app )
13
13
LOG .setLevel (logging .INFO )
14
14
15
+
15
16
@app .route ("/" )
16
17
def home ():
17
18
html = f"<h3>Predict the Height From Weight of MLB Players</h3>"
18
19
return html .format (format )
19
20
20
- @app .route ("/predict" , methods = ['POST' ])
21
+
22
+ @app .route ("/predict" , methods = ["POST" ])
21
23
def predict ():
22
24
"""Predicts the Height of MLB Players"""
23
-
25
+
24
26
json_payload = request .json
25
27
LOG .info (f"JSON payload: { json_payload } " )
26
- prediction = mlib .predict (json_payload ['Weight' ])
27
- return jsonify ({'prediction' : prediction })
28
+ prediction = mlib .predict (json_payload ["Weight" ])
29
+ return jsonify ({"prediction" : prediction })
30
+
28
31
29
32
if __name__ == "__main__" :
30
- app .run (host = ' 0.0.0.0' , port = 8080 , debug = True )
33
+ app .run (host = " 0.0.0.0" , port = 8080 , debug = True )
Original file line number Diff line number Diff line change 2
2
import click
3
3
from mlib import predict
4
4
5
- #var=
5
+ # var=
6
+
6
7
7
8
@click .command ()
8
9
@click .option (
Original file line number Diff line number Diff line change @@ -4,7 +4,8 @@ pylint==2.7.2
4
4
pytest == 6.2.2
5
5
black == 20.8b1
6
6
click == 7.1.2
7
- Flask == 1.1.2
7
+ Flask == 1.1.4
8
+ markupsafe == 2.0.1
8
9
joblib == 1.0.1
9
10
pytest-cov == 2.11.1
10
11
requests == 2.25.1
Original file line number Diff line number Diff line change 4
4
from click .testing import CliRunner
5
5
from cli import predictcli
6
6
import utilscli
7
+ from app import app as flask_app
7
8
8
9
9
10
@pytest .fixture
@@ -12,6 +13,15 @@ def test_array():
12
13
feature = val .reshape (- 1 , 1 )
13
14
return feature
14
15
16
+ @pytest .fixture
17
+ def app ():
18
+ yield flask_app
19
+
20
+
21
+ @pytest .fixture
22
+ def client (app ):
23
+ return app .test_client ()
24
+
15
25
16
26
def test_format_input (test_array ):
17
27
assert test_array .shape == format_input (2 ).shape
@@ -37,3 +47,11 @@ def test_retrain():
37
47
runner = CliRunner ()
38
48
result = runner .invoke (utilscli .cli , ["--version" ])
39
49
assert result .exit_code == 0
50
+
51
+
52
+ # Smoke test Flask
53
+ def test_index (app , client ):
54
+ res = client .get ('/' )
55
+ assert res .status_code == 200
56
+ expected = "Predict the Height From Weight of MLB Players"
57
+ assert expected in res .get_data (as_text = True )
Original file line number Diff line number Diff line change 3
3
import mlib
4
4
import requests
5
5
6
+
6
7
@click .group ()
7
8
@click .version_option ("1.0" )
8
9
def cli ():
@@ -30,10 +31,13 @@ def retrain(tsize):
30
31
@click .option ("--host" , default = "http://localhost:8080/predict" , help = "Host to query" )
31
32
def mkrequest (weight , host ):
32
33
"""Sends prediction to ML Endpoint"""
33
-
34
- click .echo (click .style (f"Querying host { host } with weight: { weight } " ,
35
- bg = "green" , fg = "white" ))
36
- payload = {"Weight" :weight }
34
+
35
+ click .echo (
36
+ click .style (
37
+ f"Querying host { host } with weight: { weight } " , bg = "green" , fg = "white"
38
+ )
39
+ )
40
+ payload = {"Weight" : weight }
37
41
result = requests .post (url = host , json = payload )
38
42
click .echo (click .style (f"result: { result .text } " , bg = "red" , fg = "white" ))
39
43
You can’t perform that action at this time.
0 commit comments