forked from InstituteforDiseaseModeling/covasim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_parameters.py
71 lines (49 loc) · 1.33 KB
/
test_parameters.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
63
64
65
66
67
68
69
70
71
'''
Test that the parameters and data files are being created correctly.
'''
#%% Imports
import os
import pytest
import sciris as sc
import covasim as cv
#%% Define the tests
def test_parameters():
sc.heading('Model parameters')
pars = cv.make_pars()
sc.pp(pars)
return pars
def test_data():
sc.heading('Data loading')
data = cv.load_data(os.path.join(sc.thisdir(__file__), 'example_data.csv'))
sc.pp(data)
# Check that it is looking for the right file
with pytest.raises(FileNotFoundError):
data = cv.load_data(datafile='file_not_found.csv')
return data
def test_location():
sc.heading('Population settings')
pars = dict(
pop_size = 1000,
pop_type = 'hybrid',
location = 'nigeria',
)
sim = cv.Sim(pars)
sim.initialize()
return sim
def test_age_structure():
sc.heading('Age structures')
available = 'Lithuania'
not_available = 'Ruritania'
age_data = cv.data.loaders.get_age_distribution(available)
with pytest.raises(ValueError):
cv.data.loaders.get_age_distribution(not_available)
return age_data
#%% Run as a script
if __name__ == '__main__':
T = sc.tic()
pars = test_parameters()
data = test_data()
sim = test_location()
age = test_age_structure()
sc.toc(T)
print('Done.')