1
- """Tests."""
2
-
3
- from math import ceil # type: ignore
4
- from datetime import date , datetime # type: ignore
5
- import pytest # type: ignore
1
+ from datetime import date
6
2
import pandas as pd # type: ignore
7
3
import numpy as np # type: ignore
8
- import altair as alt # type: ignore
9
-
10
- from src .penn_chime .charts import (
11
- build_admits_chart ,
12
- build_census_chart ,
13
- build_descriptions ,
14
- )
15
-
16
- from src .penn_chime .parameters import (
17
- Parameters ,
18
- Disposition ,
19
- Regions ,
20
- )
21
4
22
5
EPSILON = 1.e-7
23
6
26
9
# we just want to verify that st _attempted_ to render the right stuff
27
10
# so we store the input, and make sure that it matches what we expect
28
11
29
- @pytest .fixture
30
- def admits_df ():
31
- return pd .read_csv ('tests/by_doubling_time/2020-03-28_projected_admits.csv' , parse_dates = ['date' ])
32
-
33
- @pytest .fixture
34
- def census_df ():
35
- return pd .read_csv ('tests/by_doubling_time/2020-03-28_projected_census.csv' , parse_dates = ['date' ])
36
-
37
12
38
13
def test_defaults_repr (DEFAULTS ):
39
14
"""
@@ -43,28 +18,6 @@ def test_defaults_repr(DEFAULTS):
43
18
# TODO: Add assertions here
44
19
45
20
46
- # Test the math
47
-
48
- def test_admits_chart (admits_df ):
49
- chart = build_admits_chart (alt = alt , admits_df = admits_df )
50
- assert isinstance (chart , (alt .Chart , alt .LayerChart ))
51
- assert round (chart .data .iloc [40 ].icu , 0 ) == 39
52
-
53
- # test fx call with no params
54
- with pytest .raises (TypeError ):
55
- build_admits_chart ()
56
-
57
- def test_census_chart (census_df ):
58
- chart = build_census_chart (alt = alt , census_df = census_df )
59
- assert isinstance (chart , (alt .Chart , alt .LayerChart ))
60
- assert chart .data .iloc [1 ].hospitalized == 3
61
- assert chart .data .iloc [49 ].ventilated == 365
62
-
63
- # test fx call with no params
64
- with pytest .raises (TypeError ):
65
- build_census_chart ()
66
-
67
-
68
21
def test_model (model , param ):
69
22
# test the Model
70
23
@@ -147,31 +100,3 @@ def test_model_cumulative_census(param, model):
147
100
0.05 * 0.05 * (raw_df .infected [1 :- 1 ] + raw_df .recovered [1 :- 1 ]) - 1.0
148
101
)
149
102
assert (diff .abs () < 0.1 ).all ()
150
-
151
-
152
- def test_build_descriptions (admits_df , param ):
153
- chart = build_admits_chart (alt = alt , admits_df = admits_df )
154
- description = build_descriptions (chart = chart , labels = param .labels )
155
-
156
- hosp , icu , vent = description .split ("\n \n " ) # break out the description into lines
157
-
158
- max_hosp = chart .data ['hospitalized' ].max ()
159
- assert str (ceil (max_hosp )) in hosp
160
-
161
- # TODO add test for asterisk
162
-
163
- def test_no_asterisk (admits_df , param ):
164
- param .n_days = 600
165
-
166
- chart = build_admits_chart (alt = alt , admits_df = admits_df )
167
- description = build_descriptions (chart = chart , labels = param .labels )
168
- assert "*" not in description
169
-
170
-
171
- def test_census (census_df , param ):
172
- chart = build_census_chart (alt = alt , census_df = census_df )
173
- description = build_descriptions (chart = chart , labels = param .labels )
174
-
175
- assert str (ceil (chart .data ['ventilated' ].max ())) in description
176
- assert str (chart .data ['icu' ].idxmax ()) not in description
177
- assert datetime .strftime (chart .data .iloc [chart .data ['icu' ].idxmax ()].date , '%b %d' ) in description
0 commit comments