1
1
import pytest
2
2
3
+ from ixmp4 import Platform
3
4
from ixmp4 .data .abstract import Docs
4
5
5
- from ..utils import all_platforms
6
+ from ..utils import all_platforms , database_platforms
6
7
7
8
8
9
@all_platforms
9
10
class TestDataDocs :
10
11
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
12
13
model = test_mp .backend .models .create ("Model" )
13
14
14
15
docs_model = test_mp .backend .models .docs .set (model .id , "Description of Model" )
15
16
docs_model1 = test_mp .backend .models .docs .get (model .id )
16
17
assert docs_model == docs_model1
17
18
18
19
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
20
21
model = test_mp .backend .models .create ("Model" )
21
22
22
23
with pytest .raises (Docs .NotFound ):
@@ -35,7 +36,7 @@ def test_change_empty_modeldocs(self, test_mp, request):
35
36
assert test_mp .backend .models .docs .get (model .id ) == docs_model2
36
37
37
38
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
39
40
model = test_mp .backend .models .create ("Model" )
40
41
docs_model = test_mp .backend .models .docs .set (
41
42
model .id , "Description of test Model"
@@ -49,7 +50,7 @@ def test_delete_modeldocs(self, test_mp, request):
49
50
test_mp .backend .models .docs .get (model .id )
50
51
51
52
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
53
54
region = test_mp .backend .regions .create ("Region" , "Hierarchy" )
54
55
docs_region = test_mp .backend .regions .docs .set (
55
56
region .id , "Description of test Region"
@@ -59,7 +60,7 @@ def test_get_and_set_regiondocs(self, test_mp, request):
59
60
assert docs_region == docs_region1
60
61
61
62
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
63
64
region = test_mp .backend .regions .create ("Region" , "Hierarchy" )
64
65
65
66
with pytest .raises (Docs .NotFound ):
@@ -78,7 +79,7 @@ def test_change_empty_regiondocs(self, test_mp, request):
78
79
assert test_mp .backend .regions .docs .get (region .id ) == docs_region2
79
80
80
81
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
82
83
region = test_mp .backend .regions .create ("Region" , "Hierarchy" )
83
84
docs_region = test_mp .backend .regions .docs .set (
84
85
region .id , "Description of test region"
@@ -92,7 +93,7 @@ def test_delete_regiondocs(self, test_mp, request):
92
93
test_mp .backend .regions .docs .get (region .id )
93
94
94
95
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
96
97
scenario = test_mp .backend .scenarios .create ("Scenario" )
97
98
docs_scenario = test_mp .backend .scenarios .docs .set (
98
99
scenario .id , "Description of Scenario"
@@ -101,7 +102,7 @@ def test_get_and_set_scenariodocs(self, test_mp, request):
101
102
assert docs_scenario == docs_scenario1
102
103
103
104
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
105
106
scenario = test_mp .backend .scenarios .create ("Scenario" )
106
107
107
108
with pytest .raises (Docs .NotFound ):
@@ -120,7 +121,7 @@ def test_change_empty_scenariodocs(self, test_mp, request):
120
121
assert test_mp .backend .scenarios .docs .get (scenario .id ) == docs_scenario2
121
122
122
123
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
124
125
scenario = test_mp .backend .scenarios .create ("Scenario" )
125
126
docs_scenario = test_mp .backend .scenarios .docs .set (
126
127
scenario .id , "Description of test Scenario"
@@ -134,15 +135,15 @@ def test_delete_scenariodocs(self, test_mp, request):
134
135
test_mp .backend .scenarios .docs .get (scenario .id )
135
136
136
137
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
138
139
unit = test_mp .backend .units .create ("Unit" )
139
140
docs_unit = test_mp .backend .units .docs .set (unit .id , "Description of test Unit" )
140
141
docs_unit1 = test_mp .backend .units .docs .get (unit .id )
141
142
142
143
assert docs_unit == docs_unit1
143
144
144
145
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
146
147
unit = test_mp .backend .units .create ("Unit" )
147
148
148
149
with pytest .raises (Docs .NotFound ):
@@ -159,7 +160,7 @@ def test_change_empty_unitdocs(self, test_mp, request):
159
160
assert test_mp .backend .units .docs .get (unit .id ) == docs_unit2
160
161
161
162
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
163
164
unit = test_mp .backend .units .create ("Unit" )
164
165
docs_unit = test_mp .backend .units .docs .set (unit .id , "Description of test Unit" )
165
166
@@ -171,7 +172,7 @@ def test_delete_unitdocs(self, test_mp, request):
171
172
test_mp .backend .units .docs .get (unit .id )
172
173
173
174
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
175
176
variable = test_mp .backend .iamc .variables .create ("Variable" )
176
177
docs_variable = test_mp .backend .iamc .variables .docs .set (
177
178
variable .id , "Description of test Variable"
@@ -181,7 +182,7 @@ def test_get_and_set_variabledocs(self, test_mp, request):
181
182
assert docs_variable == docs_variables1
182
183
183
184
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
185
186
variable = test_mp .backend .iamc .variables .create ("Variable" )
186
187
187
188
with pytest .raises (Docs .NotFound ):
@@ -200,7 +201,7 @@ def test_change_empty_variabledocs(self, test_mp, request):
200
201
assert test_mp .backend .iamc .variables .docs .get (variable .id ) == docs_variable2
201
202
202
203
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
204
205
variable = test_mp .backend .iamc .variables .create ("Variable" )
205
206
docs_variable = test_mp .backend .iamc .variables .docs .set (
206
207
variable .id , "Description of test Variable"
@@ -214,7 +215,7 @@ def test_delete_variabledocs(self, test_mp, request):
214
215
test_mp .backend .iamc .variables .docs .get (variable .id )
215
216
216
217
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
218
219
run = test_mp .backend .runs .create ("Model" , "Scenario" )
219
220
indexset = test_mp .backend .optimization .indexsets .create (
220
221
run_id = run .id , name = "IndexSet"
@@ -227,7 +228,7 @@ def test_get_and_set_indexsetdocs(self, test_mp, request):
227
228
assert docs_indexset == docs_indexset1
228
229
229
230
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
231
232
run = test_mp .backend .runs .create ("Model" , "Scenario" )
232
233
indexset = test_mp .backend .optimization .indexsets .create (
233
234
run_id = run .id , name = "IndexSet"
@@ -255,7 +256,7 @@ def test_change_empty_indexsetdocs(self, test_mp, request):
255
256
)
256
257
257
258
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
259
260
run = test_mp .backend .runs .create ("Model" , "Scenario" )
260
261
indexset = test_mp .backend .optimization .indexsets .create (
261
262
run_id = run .id , name = "IndexSet"
@@ -275,7 +276,7 @@ def test_delete_indexsetdocs(self, test_mp, request):
275
276
test_mp .backend .optimization .indexsets .docs .get (indexset .id )
276
277
277
278
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
279
280
run = test_mp .backend .runs .create ("Model" , "Scenario" )
280
281
unit = test_mp .backend .units .create ("Unit" )
281
282
scalar = test_mp .backend .optimization .scalars .create (
@@ -289,7 +290,7 @@ def test_get_and_set_scalardocs(self, test_mp, request):
289
290
assert docs_scalar == docs_scalar1
290
291
291
292
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
293
294
run = test_mp .backend .runs .create ("Model" , "Scenario" )
294
295
unit = test_mp .backend .units .create ("Unit" )
295
296
scalar = test_mp .backend .optimization .scalars .create (
@@ -312,7 +313,7 @@ def test_change_empty_scalardocs(self, test_mp, request):
312
313
assert test_mp .backend .optimization .scalars .docs .get (scalar .id ) == docs_scalar2
313
314
314
315
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
316
317
run = test_mp .backend .runs .create ("Model" , "Scenario" )
317
318
unit = test_mp .backend .units .create ("Unit" )
318
319
scalar = test_mp .backend .optimization .scalars .create (
@@ -330,7 +331,7 @@ def test_delete_scalardocs(self, test_mp, request):
330
331
test_mp .backend .optimization .scalars .docs .get (scalar .id )
331
332
332
333
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
334
335
run = test_mp .backend .runs .create ("Model" , "Scenario" )
335
336
_ = test_mp .backend .optimization .indexsets .create (
336
337
run_id = run .id , name = "Indexset"
@@ -346,7 +347,7 @@ def test_get_and_set_tabledocs(self, test_mp, request):
346
347
assert docs_table == docs_table1
347
348
348
349
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
350
351
run = test_mp .backend .runs .create ("Model" , "Scenario" )
351
352
_ = test_mp .backend .optimization .indexsets .create (
352
353
run_id = run .id , name = "Indexset"
@@ -371,7 +372,7 @@ def test_change_empty_tabledocs(self, test_mp, request):
371
372
assert test_mp .backend .optimization .tables .docs .get (table .id ) == docs_table2
372
373
373
374
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
375
376
run = test_mp .backend .runs .create ("Model" , "Scenario" )
376
377
_ = test_mp .backend .optimization .indexsets .create (
377
378
run_id = run .id , name = "Indexset"
@@ -389,3 +390,73 @@ def test_delete_tabledocs(self, test_mp, request):
389
390
390
391
with pytest .raises (Docs .NotFound ):
391
392
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