-
Notifications
You must be signed in to change notification settings - Fork 309
/
Copy pathtest_mlib.py
57 lines (40 loc) · 1.27 KB
/
test_mlib.py
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
from mlib import format_input, scale_input, height_human
import numpy as np
import pytest
from click.testing import CliRunner
from cli import predictcli
import utilscli
from app import app as flask_app
@pytest.fixture
def test_array():
val = np.array(1)
feature = val.reshape(-1, 1)
return feature
@pytest.fixture
def app():
yield flask_app
@pytest.fixture
def client(app):
return app.test_client()
def test_format_input(test_array):
assert test_array.shape == format_input(2).shape
def test_scale_input(test_array):
assert int(scale_input(test_array)) == int(np.array([[-9.56513601]]))
def test_height_human():
assert "6 foot, 1 inches" == height_human(73.4)
assert "5 foot, 11 inches" == height_human(71.1)
def test_clisearch():
runner = CliRunner()
result = runner.invoke(predictcli, ["--weight", "180"])
assert result.exit_code == 0
assert "6 foot, 0 inches" in result.output
def test_retrain():
runner = CliRunner()
result = runner.invoke(utilscli.cli, ["--version"])
assert result.exit_code == 0
# Smoke test Flask
def test_index(app, client):
res = client.get('/')
assert res.status_code == 200
expected = "Predict the Height From Weight of MLB Players"
assert expected in res.get_data(as_text=True)