forked from OSeMOSYS/OSeMOSYS_linopy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_validate.py
62 lines (46 loc) · 1.56 KB
/
test_validate.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
61
62
import pytest
from variables import add_demand_variables, add_activity_variables
import xarray as xr
import numpy as np
from linopy import Model, Variable
from validate import validate_user_data
@pytest.fixture()
def specified_demand_profile():
data = np.empty((1, 1, 2, 1))
data.fill(0.5)
coords = {
'REGION': ['SIMPLICITY'],
'FUEL': ['ELC'],
'TIMESLICE': ['1', '2'],
'YEAR': [2010]
}
dims = ['REGION', 'FUEL', 'TIMESLICE', 'YEAR']
return xr.DataArray(data, coords, dims, 'SpecifiedDemandProfile')
@pytest.fixture()
def coords():
return {
'_REGION': ['SIMPLICITY'],
'REGION': ['SIMPLICITY'],
'TECHNOLOGY': ['HEATER'],
'TIMESLICE': ['1', '2'],
'MODE_OF_OPERATION': [1],
'FUEL': ['ELC'],
'YEAR': [2010]
}
@pytest.fixture()
def dataset(coords, specified_demand_profile):
data_vars = {
'SpecifiedDemandProfile': specified_demand_profile,
}
# Dataset containing all the parameters read in from an OSeMOSYS file
ds = xr.Dataset(data_vars=data_vars, coords=coords)
return ds
def test_validate_demand_profile(dataset):
assert validate_user_data(dataset)
def test_validate_demand_profile_raises(dataset):
dataset['SpecifiedDemandProfile'].data = np.array([[[[0.25], [0.3]]]])
with pytest.raises(ValueError):
assert validate_user_data(dataset)
def test_validate_demand_profile_approx(dataset):
dataset['SpecifiedDemandProfile'].data = np.array([[[[0.99999998], [0.00000001]]]])
assert validate_user_data(dataset)