🌐 AI搜索 & 代理 主页
Skip to content

Commit c2de3d8

Browse files
author
Montana Low
committed
make test that "works"
1 parent a1ef909 commit c2de3d8

File tree

4 files changed

+87
-11
lines changed

4 files changed

+87
-11
lines changed

pgml/pgml/model.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def find(cls, id: int):
4141
FROM pgml.projects
4242
WHERE id = {q(id)}
4343
""", 1)
44-
if (result.nrows == 0):
44+
if (len(result) == 0):
4545
return None
4646

4747
project = Project()
@@ -71,7 +71,7 @@ def find_by_name(cls, name: str):
7171
FROM pgml.projects
7272
WHERE name = {q(name)}
7373
""", 1)
74-
if (result.nrows == 0):
74+
if (len(result)== 0):
7575
return None
7676

7777
project = Project()
@@ -159,7 +159,7 @@ def create(cls, relation_name: str, y_column_name: str, test_size: float or int,
159159
SET status = 'created'
160160
WHERE id = {q(snapshot.id)}
161161
RETURNING *
162-
""")[0])
162+
""", 1)[0])
163163
return snapshot
164164

165165
def data(self):
@@ -172,8 +172,9 @@ def data(self):
172172
FROM pgml."snapshot_{self.id}"
173173
""")
174174

175+
print(data)
175176
# Sanity check the data
176-
if data.nrows == 0:
177+
if len(data) == 0:
177178
PgMLException(
178179
f"Relation `{self.relation_name}` contains no rows. Did you pass the correct `relation_name`?"
179180
)
@@ -272,7 +273,7 @@ def find_deployed(cls, project_id: int):
272273
ORDER by deployments.created_at DESC
273274
LIMIT 1
274275
""")
275-
if (result.nrows == 0):
276+
if (len(result) == 0):
276277
return None
277278

278279
model = Model()

pgml/tests/plpy.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from collections import deque
2+
3+
execute_results = deque()
4+
5+
def quote_literal(literal):
6+
return "'" + literal + "'"
7+
8+
def execute(sql, lines = 0):
9+
if len(execute_results) > 0:
10+
result = execute_results.popleft()
11+
return result
12+
else:
13+
return []
14+
15+
def add_mock_result(result):
16+
execute_results.append(result)

pgml/tests/test_model.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# stub out plpy
2+
from . import plpy
3+
import sys
4+
sys.modules['plpy'] = plpy
5+
6+
import time
7+
import unittest
8+
from pgml import model
9+
10+
class TestModel(unittest.TestCase):
11+
def test_the_world(self):
12+
plpy.add_mock_result(
13+
[{"id": 1, "name": "Test", "objective": "regression", "created_at": time.time(), "updated_at": time.time()}]
14+
)
15+
plpy.add_mock_result(
16+
[{"id": 1, "relation_name": "test", "y_column_name": "test_y", "test_size": 0.1, "test_sampling": "random", "status": "new", "created_at": time.time(), "updated_at": time.time()}]
17+
)
18+
plpy.add_mock_result(
19+
"OK"
20+
)
21+
plpy.add_mock_result(
22+
[{"id": 1, "relation_name": "test", "y_column_name": "test_y", "test_size": 0.1, "test_sampling": "random", "status": "created", "created_at": time.time(), "updated_at": time.time()}]
23+
)
24+
plpy.add_mock_result(
25+
[{"id": 1, "project_id": 1, "snapshot_id": 1, "algorithm_name": "linear", "status": "new", "r2_score": None, "mean_squared_error": None, "pickle": None, "created_at": time.time(), "updated_at": time.time()}]
26+
)
27+
plpy.add_mock_result(
28+
[
29+
{"a": 1, "b": 2, "test_y": 3},
30+
{"a": 2, "b": 3, "test_y": 4},
31+
{"a": 3, "b": 4, "test_y": 5},
32+
]
33+
)
34+
plpy.add_mock_result(
35+
[{"id": 1, "project_id": 1, "snapshot_id": 1, "algorithm_name": "linear", "status": "new", "r2_score": None, "mean_squared_error": None, "pickle": None, "created_at": time.time(), "updated_at": time.time()}]
36+
)
37+
38+
plpy.add_mock_result(
39+
[{"id": 1, "project_id": 1, "snapshot_id": 1, "algorithm_name": "linear", "status": "new", "r2_score": None, "mean_squared_error": None, "pickle": None, "created_at": time.time(), "updated_at": time.time()}]
40+
)
41+
plpy.add_mock_result(
42+
[
43+
{"a": 1, "b": 2, "test_y": 3},
44+
{"a": 2, "b": 3, "test_y": 4},
45+
{"a": 3, "b": 4, "test_y": 5},
46+
]
47+
)
48+
plpy.add_mock_result(
49+
[{"id": 1, "project_id": 1, "snapshot_id": 1, "algorithm_name": "linear", "status": "new", "r2_score": None, "mean_squared_error": None, "pickle": None, "created_at": time.time(), "updated_at": time.time()}]
50+
)
51+
52+
plpy.add_mock_result(
53+
[{"id": 1, "project_id": 1, "snapshot_id": 1, "algorithm_name": "linear", "status": "new", "r2_score": None, "mean_squared_error": None, "pickle": None, "created_at": time.time(), "updated_at": time.time()}]
54+
)
55+
plpy.add_mock_result(
56+
[
57+
{"a": 1, "b": 2, "test_y": 3},
58+
{"a": 2, "b": 3, "test_y": 4},
59+
{"a": 3, "b": 4, "test_y": 5},
60+
]
61+
)
62+
plpy.add_mock_result(
63+
[{"id": 1, "project_id": 1, "snapshot_id": 1, "algorithm_name": "linear", "status": "new", "r2_score": None, "mean_squared_error": None, "pickle": None, "created_at": time.time(), "updated_at": time.time()}]
64+
)
65+
model.train("Test", "regression", "test", "test_y")

pgml/tests/test_train.py

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)