24
24
Disposition ,
25
25
Regions ,
26
26
)
27
- from src .penn_chime .presentation import display_header
28
27
29
28
EPSILON = 1.e-7
30
29
31
30
# set up
32
31
33
32
# we just want to verify that st _attempted_ to render the right stuff
34
33
# so we store the input, and make sure that it matches what we expect
35
- class MockStreamlit :
36
- def __init__ (self ):
37
- self .render_store = []
38
- self .markdown = self .just_store_instead_of_rendering
39
- self .latex = self .just_store_instead_of_rendering
40
- self .subheader = self .just_store_instead_of_rendering
41
-
42
- def just_store_instead_of_rendering (self , inp , * args , ** kwargs ):
43
- self .render_store .append (inp )
44
- return None
45
-
46
- @pytest .fixture
47
- def mock_st ():
48
- return MockStreamlit ()
49
-
50
- # The defaults in settings will change and break the tests
51
- @pytest .fixture
52
- def DEFAULTS ():
53
- return Parameters (
54
- region = Regions (
55
- delaware = 564696 ,
56
- chester = 519293 ,
57
- montgomery = 826075 ,
58
- bucks = 628341 ,
59
- philly = 1581000 ,
60
- ),
61
- current_date = datetime (year = 2020 , month = 3 , day = 28 ),
62
- current_hospitalized = 14 ,
63
- date_first_hospitalized = datetime (year = 2020 , month = 3 , day = 7 ),
64
- doubling_time = 4.0 ,
65
- n_days = 60 ,
66
- market_share = 0.15 ,
67
- relative_contact_rate = 0.3 ,
68
- hospitalized = Disposition (0.025 , 7 ),
69
- icu = Disposition (0.0075 , 9 ),
70
- ventilated = Disposition (0.005 , 10 ),
71
- )
72
-
73
- @pytest .fixture
74
- def param ():
75
- return Parameters (
76
- current_date = datetime (year = 2020 , month = 3 , day = 28 ),
77
- current_hospitalized = 100 ,
78
- doubling_time = 6.0 ,
79
- market_share = 0.05 ,
80
- relative_contact_rate = 0.15 ,
81
- population = 500000 ,
82
- hospitalized = Disposition (0.05 , 7 ),
83
- icu = Disposition (0.02 , 9 ),
84
- ventilated = Disposition (0.01 , 10 ),
85
- n_days = 60 ,
86
- )
87
-
88
- @pytest .fixture
89
- def halving_param ():
90
- return Parameters (
91
- current_date = datetime (year = 2020 , month = 3 , day = 28 ),
92
- current_hospitalized = 100 ,
93
- doubling_time = 6.0 ,
94
- market_share = 0.05 ,
95
- relative_contact_rate = 0.7 ,
96
- population = 500000 ,
97
- hospitalized = Disposition (0.05 , 7 ),
98
- icu = Disposition (0.02 , 9 ),
99
- ventilated = Disposition (0.01 , 10 ),
100
- n_days = 60 ,
101
- )
102
-
103
- @pytest .fixture
104
- def model (param ):
105
- return Model (param )
106
-
107
- @pytest .fixture
108
- def halving_model (halving_param ):
109
- return Model (halving_param )
110
34
111
35
@pytest .fixture
112
36
def admits_df ():
@@ -117,56 +41,7 @@ def census_df():
117
41
return pd .read_csv ('tests/by_doubling_time/2020-03-28_projected_census.csv' , parse_dates = ['date' ])
118
42
119
43
120
- # test presentation
121
- def header_test_helper (expected_str , model , param , mock_st ):
122
- display_header (mock_st , model , param )
123
- assert [s for s in mock_st .render_store if expected_str in s ],\
124
- f"Expected the string '{ expected_str } ' in the display header"
125
-
126
- def test_penn_logo_in_header (model , param , mock_st ):
127
- penn_css = '<link rel="stylesheet" href="https://www1.pennmedicine.org/styles/shared/penn-medicine-header.css">'
128
- header_test_helper (penn_css , model , param , mock_st )
129
-
130
-
131
- def test_the_rest_of_header_shows_up (model , param , mock_st ):
132
- random_part_of_header = "implying an effective $R_t$ of"
133
- header_test_helper (random_part_of_header , model , param , mock_st )
134
-
135
-
136
- def test_mitigation_statement (model , param , mock_st ):
137
- expected_doubling = "outbreak **reduces the doubling time to 7.8** days"
138
- header_test_helper (expected_doubling , model , param , mock_st )
139
-
140
- def test_mitigation_statement_halving (halving_model , halving_param , mock_st ):
141
- expected_halving = "outbreak **halves the infections every 51.9** days"
142
- header_test_helper (expected_halving , halving_model , halving_param , mock_st )
143
-
144
-
145
- def test_growth_rate (model , param , mock_st ):
146
- initial_growth = "and daily growth rate of **12.25%**."
147
- header_test_helper (initial_growth , model , param , mock_st )
148
-
149
- mitigated_growth = "and daily growth rate of **9.34%**."
150
- header_test_helper (mitigated_growth , model , param , mock_st )
151
-
152
- def test_growth_rate_halving (halving_model , halving_param , mock_st ):
153
- mitigated_halving = "and daily growth rate of **-1.33%**."
154
- header_test_helper (mitigated_halving , halving_model , halving_param , mock_st )
155
-
156
-
157
- @pytest .mark .xfail ()
158
- def test_header_fail (mock_st ):
159
- """
160
- Just proving to myself that these tests work
161
- """
162
- some_garbage = "ajskhlaeHFPIQONOI8QH34TRNAOP8ESYAW4"
163
- display_header (mock_st , param )
164
- assert len (
165
- list (filter (lambda s : some_garbage in s , mock_st .render_store ))
166
- ), "This should fail"
167
-
168
-
169
- def test_defaults_repr ():
44
+ def test_defaults_repr (DEFAULTS ):
170
45
"""
171
46
Test DEFAULTS.repr
172
47
"""
0 commit comments