Skip to content

Commit 081e438

Browse files
committed
resolve pr
1 parent b5e6c9b commit 081e438

3 files changed

Lines changed: 78 additions & 50 deletions

File tree

meorg_client/tests/conftest.py

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,13 @@
99
os.environ["MEORG_DEV_MODE"] = "1"
1010

1111

12-
class ValueStorage:
13-
def __init__(self):
14-
self.data = dict()
15-
16-
def get(self, key):
17-
return self.data.get(key, None)
18-
19-
def set(self, key, value):
20-
self.data[key] = value
21-
22-
def __repr__(self):
23-
lines = ""
24-
for k, v in self.data.items():
25-
lines += f"{k} = {v}\n"
26-
27-
return lines
28-
29-
30-
# Add some things to the store
31-
store = ValueStorage()
32-
store.set("email", os.environ.get("MEORG_EMAIL"))
33-
store.set("password", os.environ.get("MEORG_PASSWORD"))
34-
store.set("model_output_id", os.environ.get("MEORG_MODEL_OUTPUT_ID"))
35-
store.set("experiment_id", os.environ.get("MEORG_EXPERIMENT_ID"))
36-
store.set("model_profile_id", os.environ.get("MEORG_MODEL_PROFILE_ID"))
37-
store.set("model_output_name", os.environ.get("MEORG_MODEL_OUTPUT_NAME"))
38-
39-
4012
# https://docs.pytest.org/en/latest/example/simple.html#making-test-result-information-available-in-fixtures
4113
@pytest.hookimpl(wrapper=True, tryfirst=True)
4214
def pytest_runtest_makereport(item, call):
15+
"""Have more information on the status for pytests.
16+
17+
The results can be used within fixtures
18+
"""
4319
# execute all other hooks to obtain the report object
4420
rep = yield
4521

meorg_client/tests/test_cli.py

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,33 @@ def test_filepath() -> str:
3434

3535
@pytest.fixture
3636
def model_output_generator(request, runner: CliRunner, model_profile_id: str):
37+
"""A generator function for creating new model outputs before running a test.
38+
39+
After the test has run, automatically deletes all model outputs created within
40+
the test
41+
42+
Parameters
43+
-------
44+
request:
45+
Request object by pytest
46+
47+
click.testing.CliRunner
48+
Runner object.
49+
50+
model_profile_id
51+
Model profile ID.
52+
"""
3753
model_output_ids = []
3854

3955
def _make_model_output(model_output_name):
56+
"""Create new model output ID.
57+
58+
Parameters
59+
-------
60+
name:
61+
Model output name
62+
"""
63+
# `model_profile_id` from `model_output_generator`
4064
result = runner.invoke(
4165
cli.create_new_model_output,
4266
[model_profile_id, model_output_name],
@@ -49,10 +73,13 @@ def _make_model_output(model_output_name):
4973

5074
yield _make_model_output
5175

52-
# Used if already deleted
76+
# If using tests like model_output_delete, where model output is already deleted,
77+
# we don't want to do the teardown process
5378
if hasattr(request.node, "skip_teardown"):
5479
return
5580

81+
# If test failed, for debugging purposes, we want to keep the model output in
82+
# me.org
5683
report = request.node.stash[phase_report_key]
5784
if report["call"].failed:
5885
print("Call to test failed", request.node.nodeid)
@@ -99,7 +126,7 @@ def test_create_model_output(
99126

100127
assert result.exit_code == 0
101128
model_output_id = result.return_value
102-
assert type(model_output_id) is str # The new model output
129+
assert isinstance(model_output_id, str) # The new model output
103130

104131
def test_model_output_query(self, runner: CliRunner, model_output_id: str):
105132
"""Test Existing Model output."""
@@ -148,27 +175,24 @@ class TestBenchmark:
148175
def model_output_id(
149176
self, runner: CliRunner, model_output_generator, experiment_id: str
150177
):
151-
id1 = model_output_generator("meorg_test_benchmark1")
152-
id2 = model_output_generator("meorg_test_benchmark2")
153-
runner.invoke(
154-
cli.model_output_experiments_extend,
155-
[id1, experiment_id],
156-
)
157-
runner.invoke(
158-
cli.model_output_experiments_extend,
159-
[id2, experiment_id],
160-
)
161-
return id1
178+
latest_id = None
179+
for i in range(2):
180+
latest_id = model_output_generator(f"meorg_test_benchmark{i}")
181+
runner.invoke(
182+
cli.model_output_experiments_extend,
183+
[latest_id, experiment_id],
184+
)
185+
return latest_id
162186

163187
def _check_available_benchmarks(self, result, expected):
164188
available_benchmarks = result.get("benchmarks")
165-
assert type(available_benchmarks) is list
189+
assert isinstance(available_benchmarks, list)
166190
assert len(available_benchmarks) == expected
167191
return available_benchmarks
168192

169193
def _check_current_benchmarks(self, result, expected):
170194
current_benchmarks = result.get("current")
171-
assert type(current_benchmarks) is list
195+
assert isinstance(current_benchmarks, list)
172196
assert len(current_benchmarks) == expected
173197
return current_benchmarks
174198

meorg_client/tests/test_client.py

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,19 +82,47 @@ def test_list_endpoints(client: Client):
8282

8383
@pytest.fixture
8484
def model_output_generator(request, client: Client, model_profile_id: str):
85+
"""A generator function for creating new model outputs before running a test.
86+
87+
After the test has run, automatically deletes all model outputs created within
88+
the test
89+
90+
Parameters
91+
-------
92+
request:
93+
Request object by pytest
94+
95+
client : Client
96+
Client.
97+
98+
model_profile_id
99+
Model profile ID.
100+
"""
85101
model_output_ids = []
86102

87103
def _make_model_output(model_output_name):
104+
"""Create new model output ID.
105+
106+
Parameters
107+
-------
108+
name:
109+
Model output name
110+
"""
111+
# `model_profile_id` from `model_output_generator`
88112
response = client.model_output_create(model_profile_id, model_output_name)
89113
model_output_id = response.get("data").get("modeloutput")
90114
model_output_ids.append(model_output_id)
91115
return model_output_id
92116

93117
yield _make_model_output
94118

119+
# If using tests like model_output_delete, where model output is already deleted,
120+
# we don't want to do the teardown process
95121
if hasattr(request.node, "skip_teardown"):
96122
return
97123

124+
# If test failed, for debugging purposes, we want to keep the model output in
125+
# me.org
98126
report = request.node.stash[phase_report_key]
99127
if report["call"].failed:
100128
print("Call to test failed", request.node.nodeid)
@@ -170,21 +198,21 @@ class TestBenchmark:
170198
def model_output_id(
171199
self, client: Client, model_output_generator, experiment_id: str
172200
):
173-
id1 = model_output_generator("meorg_test_benchmark1")
174-
id2 = model_output_generator("meorg_test_benchmark2")
175-
client.model_output_experiments_extend(id1, [experiment_id])
176-
client.model_output_experiments_extend(id2, [experiment_id])
177-
return id1
201+
latest_id = None
202+
for i in range(2):
203+
latest_id = model_output_generator(f"meorg_test_benchmark{i}")
204+
client.model_output_experiments_extend(latest_id, [experiment_id])
205+
return latest_id
178206

179207
def _check_available_benchmarks(self, response, expected):
180208
available_benchmarks = response.get("data").get("benchmarks")
181-
assert type(available_benchmarks) is list
209+
assert isinstance(available_benchmarks, list)
182210
assert len(available_benchmarks) == expected
183211
return available_benchmarks
184212

185213
def _check_current_benchmarks(self, response, expected):
186214
current_benchmarks = response.get("data").get("current")
187-
assert type(current_benchmarks) is list
215+
assert isinstance(current_benchmarks, list)
188216
assert len(current_benchmarks) == expected
189217
return current_benchmarks
190218

0 commit comments

Comments
 (0)