Skip to content

Commit d3f391c

Browse files
committed
Enable remaining parameter tests
1 parent 6ea5382 commit d3f391c

File tree

3 files changed

+188
-105
lines changed

3 files changed

+188
-105
lines changed

ixmp4/data/db/optimization/parameter/repository.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def add_data(self, parameter_id: int, data: dict[str, Any] | pd.DataFrame) -> No
154154
missing_columns = set(["values", "units"]) - set(data.columns)
155155
assert (
156156
not missing_columns
157-
), f"Parameter.data must include the column(s): {' ,'.join(missing_columns)}!"
157+
), f"Parameter.data must include the column(s): {', '.join(missing_columns)}!"
158158

159159
# Can use a set for now, need full column if we care about order
160160
for unit_name in set(data["units"]):

tests/data/test_docs.py

+96-25
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
import pytest
22

3+
from ixmp4 import Platform
34
from ixmp4.data.abstract import Docs
45

5-
from ..utils import all_platforms
6+
from ..utils import all_platforms, database_platforms
67

78

89
@all_platforms
910
class TestDataDocs:
1011
def test_get_and_set_modeldocs(self, test_mp, request):
11-
test_mp = request.getfixturevalue(test_mp)
12+
test_mp: Platform = request.getfixturevalue(test_mp) # type: ignore
1213
model = test_mp.backend.models.create("Model")
1314

1415
docs_model = test_mp.backend.models.docs.set(model.id, "Description of Model")
1516
docs_model1 = test_mp.backend.models.docs.get(model.id)
1617
assert docs_model == docs_model1
1718

1819
def test_change_empty_modeldocs(self, test_mp, request):
19-
test_mp = request.getfixturevalue(test_mp)
20+
test_mp: Platform = request.getfixturevalue(test_mp) # type: ignore
2021
model = test_mp.backend.models.create("Model")
2122

2223
with pytest.raises(Docs.NotFound):
@@ -35,7 +36,7 @@ def test_change_empty_modeldocs(self, test_mp, request):
3536
assert test_mp.backend.models.docs.get(model.id) == docs_model2
3637

3738
def test_delete_modeldocs(self, test_mp, request):
38-
test_mp = request.getfixturevalue(test_mp)
39+
test_mp: Platform = request.getfixturevalue(test_mp) # type: ignore
3940
model = test_mp.backend.models.create("Model")
4041
docs_model = test_mp.backend.models.docs.set(
4142
model.id, "Description of test Model"
@@ -49,7 +50,7 @@ def test_delete_modeldocs(self, test_mp, request):
4950
test_mp.backend.models.docs.get(model.id)
5051

5152
def test_get_and_set_regiondocs(self, test_mp, request):
52-
test_mp = request.getfixturevalue(test_mp)
53+
test_mp: Platform = request.getfixturevalue(test_mp) # type: ignore
5354
region = test_mp.backend.regions.create("Region", "Hierarchy")
5455
docs_region = test_mp.backend.regions.docs.set(
5556
region.id, "Description of test Region"
@@ -59,7 +60,7 @@ def test_get_and_set_regiondocs(self, test_mp, request):
5960
assert docs_region == docs_region1
6061

6162
def test_change_empty_regiondocs(self, test_mp, request):
62-
test_mp = request.getfixturevalue(test_mp)
63+
test_mp: Platform = request.getfixturevalue(test_mp) # type: ignore
6364
region = test_mp.backend.regions.create("Region", "Hierarchy")
6465

6566
with pytest.raises(Docs.NotFound):
@@ -78,7 +79,7 @@ def test_change_empty_regiondocs(self, test_mp, request):
7879
assert test_mp.backend.regions.docs.get(region.id) == docs_region2
7980

8081
def test_delete_regiondocs(self, test_mp, request):
81-
test_mp = request.getfixturevalue(test_mp)
82+
test_mp: Platform = request.getfixturevalue(test_mp) # type: ignore
8283
region = test_mp.backend.regions.create("Region", "Hierarchy")
8384
docs_region = test_mp.backend.regions.docs.set(
8485
region.id, "Description of test region"
@@ -92,7 +93,7 @@ def test_delete_regiondocs(self, test_mp, request):
9293
test_mp.backend.regions.docs.get(region.id)
9394

9495
def test_get_and_set_scenariodocs(self, test_mp, request):
95-
test_mp = request.getfixturevalue(test_mp)
96+
test_mp: Platform = request.getfixturevalue(test_mp) # type: ignore
9697
scenario = test_mp.backend.scenarios.create("Scenario")
9798
docs_scenario = test_mp.backend.scenarios.docs.set(
9899
scenario.id, "Description of Scenario"
@@ -101,7 +102,7 @@ def test_get_and_set_scenariodocs(self, test_mp, request):
101102
assert docs_scenario == docs_scenario1
102103

103104
def test_change_empty_scenariodocs(self, test_mp, request):
104-
test_mp = request.getfixturevalue(test_mp)
105+
test_mp: Platform = request.getfixturevalue(test_mp) # type: ignore
105106
scenario = test_mp.backend.scenarios.create("Scenario")
106107

107108
with pytest.raises(Docs.NotFound):
@@ -120,7 +121,7 @@ def test_change_empty_scenariodocs(self, test_mp, request):
120121
assert test_mp.backend.scenarios.docs.get(scenario.id) == docs_scenario2
121122

122123
def test_delete_scenariodocs(self, test_mp, request):
123-
test_mp = request.getfixturevalue(test_mp)
124+
test_mp: Platform = request.getfixturevalue(test_mp) # type: ignore
124125
scenario = test_mp.backend.scenarios.create("Scenario")
125126
docs_scenario = test_mp.backend.scenarios.docs.set(
126127
scenario.id, "Description of test Scenario"
@@ -134,15 +135,15 @@ def test_delete_scenariodocs(self, test_mp, request):
134135
test_mp.backend.scenarios.docs.get(scenario.id)
135136

136137
def test_get_and_set_unitdocs(self, test_mp, request):
137-
test_mp = request.getfixturevalue(test_mp)
138+
test_mp: Platform = request.getfixturevalue(test_mp) # type: ignore
138139
unit = test_mp.backend.units.create("Unit")
139140
docs_unit = test_mp.backend.units.docs.set(unit.id, "Description of test Unit")
140141
docs_unit1 = test_mp.backend.units.docs.get(unit.id)
141142

142143
assert docs_unit == docs_unit1
143144

144145
def test_change_empty_unitdocs(self, test_mp, request):
145-
test_mp = request.getfixturevalue(test_mp)
146+
test_mp: Platform = request.getfixturevalue(test_mp) # type: ignore
146147
unit = test_mp.backend.units.create("Unit")
147148

148149
with pytest.raises(Docs.NotFound):
@@ -159,7 +160,7 @@ def test_change_empty_unitdocs(self, test_mp, request):
159160
assert test_mp.backend.units.docs.get(unit.id) == docs_unit2
160161

161162
def test_delete_unitdocs(self, test_mp, request):
162-
test_mp = request.getfixturevalue(test_mp)
163+
test_mp: Platform = request.getfixturevalue(test_mp) # type: ignore
163164
unit = test_mp.backend.units.create("Unit")
164165
docs_unit = test_mp.backend.units.docs.set(unit.id, "Description of test Unit")
165166

@@ -171,7 +172,7 @@ def test_delete_unitdocs(self, test_mp, request):
171172
test_mp.backend.units.docs.get(unit.id)
172173

173174
def test_get_and_set_variabledocs(self, test_mp, request):
174-
test_mp = request.getfixturevalue(test_mp)
175+
test_mp: Platform = request.getfixturevalue(test_mp) # type: ignore
175176
variable = test_mp.backend.iamc.variables.create("Variable")
176177
docs_variable = test_mp.backend.iamc.variables.docs.set(
177178
variable.id, "Description of test Variable"
@@ -181,7 +182,7 @@ def test_get_and_set_variabledocs(self, test_mp, request):
181182
assert docs_variable == docs_variables1
182183

183184
def test_change_empty_variabledocs(self, test_mp, request):
184-
test_mp = request.getfixturevalue(test_mp)
185+
test_mp: Platform = request.getfixturevalue(test_mp) # type: ignore
185186
variable = test_mp.backend.iamc.variables.create("Variable")
186187

187188
with pytest.raises(Docs.NotFound):
@@ -200,7 +201,7 @@ def test_change_empty_variabledocs(self, test_mp, request):
200201
assert test_mp.backend.iamc.variables.docs.get(variable.id) == docs_variable2
201202

202203
def test_delete_variabledocs(self, test_mp, request):
203-
test_mp = request.getfixturevalue(test_mp)
204+
test_mp: Platform = request.getfixturevalue(test_mp) # type: ignore
204205
variable = test_mp.backend.iamc.variables.create("Variable")
205206
docs_variable = test_mp.backend.iamc.variables.docs.set(
206207
variable.id, "Description of test Variable"
@@ -214,7 +215,7 @@ def test_delete_variabledocs(self, test_mp, request):
214215
test_mp.backend.iamc.variables.docs.get(variable.id)
215216

216217
def test_get_and_set_indexsetdocs(self, test_mp, request):
217-
test_mp = request.getfixturevalue(test_mp)
218+
test_mp: Platform = request.getfixturevalue(test_mp) # type: ignore
218219
run = test_mp.backend.runs.create("Model", "Scenario")
219220
indexset = test_mp.backend.optimization.indexsets.create(
220221
run_id=run.id, name="IndexSet"
@@ -227,7 +228,7 @@ def test_get_and_set_indexsetdocs(self, test_mp, request):
227228
assert docs_indexset == docs_indexset1
228229

229230
def test_change_empty_indexsetdocs(self, test_mp, request):
230-
test_mp = request.getfixturevalue(test_mp)
231+
test_mp: Platform = request.getfixturevalue(test_mp) # type: ignore
231232
run = test_mp.backend.runs.create("Model", "Scenario")
232233
indexset = test_mp.backend.optimization.indexsets.create(
233234
run_id=run.id, name="IndexSet"
@@ -255,7 +256,7 @@ def test_change_empty_indexsetdocs(self, test_mp, request):
255256
)
256257

257258
def test_delete_indexsetdocs(self, test_mp, request):
258-
test_mp = request.getfixturevalue(test_mp)
259+
test_mp: Platform = request.getfixturevalue(test_mp) # type: ignore
259260
run = test_mp.backend.runs.create("Model", "Scenario")
260261
indexset = test_mp.backend.optimization.indexsets.create(
261262
run_id=run.id, name="IndexSet"
@@ -275,7 +276,7 @@ def test_delete_indexsetdocs(self, test_mp, request):
275276
test_mp.backend.optimization.indexsets.docs.get(indexset.id)
276277

277278
def test_get_and_set_scalardocs(self, test_mp, request):
278-
test_mp = request.getfixturevalue(test_mp)
279+
test_mp: Platform = request.getfixturevalue(test_mp) # type: ignore
279280
run = test_mp.backend.runs.create("Model", "Scenario")
280281
unit = test_mp.backend.units.create("Unit")
281282
scalar = test_mp.backend.optimization.scalars.create(
@@ -289,7 +290,7 @@ def test_get_and_set_scalardocs(self, test_mp, request):
289290
assert docs_scalar == docs_scalar1
290291

291292
def test_change_empty_scalardocs(self, test_mp, request):
292-
test_mp = request.getfixturevalue(test_mp)
293+
test_mp: Platform = request.getfixturevalue(test_mp) # type: ignore
293294
run = test_mp.backend.runs.create("Model", "Scenario")
294295
unit = test_mp.backend.units.create("Unit")
295296
scalar = test_mp.backend.optimization.scalars.create(
@@ -312,7 +313,7 @@ def test_change_empty_scalardocs(self, test_mp, request):
312313
assert test_mp.backend.optimization.scalars.docs.get(scalar.id) == docs_scalar2
313314

314315
def test_delete_scalardocs(self, test_mp, request):
315-
test_mp = request.getfixturevalue(test_mp)
316+
test_mp: Platform = request.getfixturevalue(test_mp) # type: ignore
316317
run = test_mp.backend.runs.create("Model", "Scenario")
317318
unit = test_mp.backend.units.create("Unit")
318319
scalar = test_mp.backend.optimization.scalars.create(
@@ -330,7 +331,7 @@ def test_delete_scalardocs(self, test_mp, request):
330331
test_mp.backend.optimization.scalars.docs.get(scalar.id)
331332

332333
def test_get_and_set_tabledocs(self, test_mp, request):
333-
test_mp = request.getfixturevalue(test_mp)
334+
test_mp: Platform = request.getfixturevalue(test_mp) # type: ignore
334335
run = test_mp.backend.runs.create("Model", "Scenario")
335336
_ = test_mp.backend.optimization.indexsets.create(
336337
run_id=run.id, name="Indexset"
@@ -346,7 +347,7 @@ def test_get_and_set_tabledocs(self, test_mp, request):
346347
assert docs_table == docs_table1
347348

348349
def test_change_empty_tabledocs(self, test_mp, request):
349-
test_mp = request.getfixturevalue(test_mp)
350+
test_mp: Platform = request.getfixturevalue(test_mp) # type: ignore
350351
run = test_mp.backend.runs.create("Model", "Scenario")
351352
_ = test_mp.backend.optimization.indexsets.create(
352353
run_id=run.id, name="Indexset"
@@ -371,7 +372,7 @@ def test_change_empty_tabledocs(self, test_mp, request):
371372
assert test_mp.backend.optimization.tables.docs.get(table.id) == docs_table2
372373

373374
def test_delete_tabledocs(self, test_mp, request):
374-
test_mp = request.getfixturevalue(test_mp)
375+
test_mp: Platform = request.getfixturevalue(test_mp) # type: ignore
375376
run = test_mp.backend.runs.create("Model", "Scenario")
376377
_ = test_mp.backend.optimization.indexsets.create(
377378
run_id=run.id, name="Indexset"
@@ -389,3 +390,73 @@ def test_delete_tabledocs(self, test_mp, request):
389390

390391
with pytest.raises(Docs.NotFound):
391392
test_mp.backend.optimization.tables.docs.get(table.id)
393+
394+
395+
# TODO Integrate with above once API layer is implemented
396+
@database_platforms
397+
def test_get_and_set_parameterdocs(test_mp, request):
398+
test_mp: Platform = request.getfixturevalue(test_mp) # type: ignore
399+
run = test_mp.backend.runs.create("Model", "Scenario")
400+
_ = test_mp.backend.optimization.indexsets.create(run_id=run.id, name="Indexset")
401+
parameter = test_mp.backend.optimization.parameters.create(
402+
run_id=run.id, name="Parameter", constrained_to_indexsets=["Indexset"]
403+
)
404+
docs_parameter = test_mp.backend.optimization.parameters.docs.set(
405+
parameter.id, "Description of test Parameter"
406+
)
407+
docs_parameter1 = test_mp.backend.optimization.parameters.docs.get(parameter.id)
408+
409+
assert docs_parameter == docs_parameter1
410+
411+
412+
@database_platforms
413+
def test_change_empty_parameterdocs(test_mp, request):
414+
test_mp: Platform = request.getfixturevalue(test_mp) # type: ignore
415+
run = test_mp.backend.runs.create("Model", "Scenario")
416+
_ = test_mp.backend.optimization.indexsets.create(run_id=run.id, name="Indexset")
417+
parameter = test_mp.backend.optimization.parameters.create(
418+
run_id=run.id, name="Parameter", constrained_to_indexsets=["Indexset"]
419+
)
420+
421+
with pytest.raises(Docs.NotFound):
422+
test_mp.backend.optimization.parameters.docs.get(parameter.id)
423+
424+
docs_parameter1 = test_mp.backend.optimization.parameters.docs.set(
425+
parameter.id, "Description of test Parameter"
426+
)
427+
428+
assert (
429+
test_mp.backend.optimization.parameters.docs.get(parameter.id)
430+
== docs_parameter1
431+
)
432+
433+
docs_parameter2 = test_mp.backend.optimization.parameters.docs.set(
434+
parameter.id, "Different description of test Parameter"
435+
)
436+
437+
assert (
438+
test_mp.backend.optimization.parameters.docs.get(parameter.id)
439+
== docs_parameter2
440+
)
441+
442+
443+
@database_platforms
444+
def test_delete_parameterdocs(test_mp, request):
445+
test_mp: Platform = request.getfixturevalue(test_mp) # type: ignore
446+
run = test_mp.backend.runs.create("Model", "Scenario")
447+
_ = test_mp.backend.optimization.indexsets.create(run_id=run.id, name="Indexset")
448+
parameter = test_mp.backend.optimization.parameters.create(
449+
run_id=run.id, name="Parameter", constrained_to_indexsets=["Indexset"]
450+
)
451+
docs_parameter = test_mp.backend.optimization.parameters.docs.set(
452+
parameter.id, "Description of test Parameter"
453+
)
454+
455+
assert (
456+
test_mp.backend.optimization.parameters.docs.get(parameter.id) == docs_parameter
457+
)
458+
459+
test_mp.backend.optimization.parameters.docs.delete(parameter.id)
460+
461+
with pytest.raises(Docs.NotFound):
462+
test_mp.backend.optimization.parameters.docs.get(parameter.id)

0 commit comments

Comments
 (0)