-
Notifications
You must be signed in to change notification settings - Fork 235
/
test_cli.py
60 lines (42 loc) · 1.69 KB
/
test_cli.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
58
59
60
import pytest
import pickle
import platform
import subprocess
from sklearn import linear_model
from tests import utils
def execute_test(exec_args):
result = subprocess.Popen(
" ".join(exec_args), stdout=subprocess.PIPE, shell=True)
generated_code = result.stdout.read().decode("utf-8")
utils.verify_python_model_is_expected(
generated_code,
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13],
expected_output=-47.62913662138064)
def _prepare_pickled_model(tmp_path):
p = tmp_path / "model.pickle"
estimator = linear_model.LinearRegression()
utils.train_model_regression(estimator)
p.write_bytes(pickle.dumps(estimator))
return p
def test_positional_arg(tmp_path):
pickled_model_path = _prepare_pickled_model(tmp_path)
exec_args = ["m2cgen", "--language", "python", str(pickled_model_path)]
execute_test(exec_args)
def test_override_input(tmp_path):
pickled_model_path = _prepare_pickled_model(tmp_path)
exec_args = [
"m2cgen", "--language", "python", "<", str(pickled_model_path)]
execute_test(exec_args)
def test_piped(tmp_path):
pickled_model_path = _prepare_pickled_model(tmp_path)
exec_args = [
"type" if platform.system() in ('Windows', 'Microsoft') else "cat",
str(pickled_model_path), " | ", "m2cgen", "--language", "python"]
execute_test(exec_args)
@pytest.mark.skip(reason="utils.verify_python_model_is_expected "
"doesn't support modules")
def test_dash_m(tmp_path):
pickled_model_path = _prepare_pickled_model(tmp_path)
exec_args = ["python", "-m", "m2cgen", "--language", "python",
str(pickled_model_path)]
execute_test(exec_args)