Skip to content

Commit b9ce898

Browse files
committed
Move presentation tests to their own module
1 parent 66e919e commit b9ce898

File tree

2 files changed

+56
-126
lines changed

2 files changed

+56
-126
lines changed

tests/penn_chime/test_presentation.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import pytest
2+
3+
from src.penn_chime.presentation import display_header
4+
5+
6+
def header_test_helper(expected_str, model, param, mock_st):
7+
display_header(mock_st, model, param)
8+
assert [
9+
s for s in mock_st.render_store if expected_str in s
10+
], f"Expected the string '{expected_str}' in the display header"
11+
12+
13+
def test_penn_logo_in_header(model, param, mock_st):
14+
penn_css = '<link rel="stylesheet" href="https://www1.pennmedicine.org/styles/shared/penn-medicine-header.css">'
15+
header_test_helper(penn_css, model, param, mock_st)
16+
17+
18+
def test_the_rest_of_header_shows_up(model, param, mock_st):
19+
random_part_of_header = "implying an effective $R_t$ of"
20+
header_test_helper(random_part_of_header, model, param, mock_st)
21+
22+
23+
def test_mitigation_statement(model, param, mock_st):
24+
expected_doubling = "outbreak **reduces the doubling time to 7.8** days"
25+
header_test_helper(expected_doubling, model, param, mock_st)
26+
27+
28+
def test_mitigation_statement_halving(halving_model, halving_param, mock_st):
29+
expected_halving = "outbreak **halves the infections every 51.9** days"
30+
header_test_helper(expected_halving, halving_model, halving_param, mock_st)
31+
32+
33+
def test_growth_rate(model, param, mock_st):
34+
initial_growth = "and daily growth rate of **12.25%**."
35+
header_test_helper(initial_growth, model, param, mock_st)
36+
37+
mitigated_growth = "and daily growth rate of **9.34%**."
38+
header_test_helper(mitigated_growth, model, param, mock_st)
39+
40+
41+
def test_growth_rate_halving(halving_model, halving_param, mock_st):
42+
mitigated_halving = "and daily growth rate of **-1.33%**."
43+
header_test_helper(mitigated_halving, halving_model, halving_param, mock_st)
44+
45+
46+
@pytest.mark.xfail()
47+
def test_header_fail(mock_st, param):
48+
"""
49+
Just proving to myself that these tests work
50+
"""
51+
some_garbage = "ajskhlaeHFPIQONOI8QH34TRNAOP8ESYAW4"
52+
display_header(mock_st, param)
53+
assert len(
54+
list(filter(lambda s: some_garbage in s, mock_st.render_store))
55+
), "This should fail"

tests/test_app.py

Lines changed: 1 addition & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -24,89 +24,13 @@
2424
Disposition,
2525
Regions,
2626
)
27-
from src.penn_chime.presentation import display_header
2827

2928
EPSILON = 1.e-7
3029

3130
# set up
3231

3332
# we just want to verify that st _attempted_ to render the right stuff
3433
# 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)
11034

11135
@pytest.fixture
11236
def admits_df():
@@ -117,56 +41,7 @@ def census_df():
11741
return pd.read_csv('tests/by_doubling_time/2020-03-28_projected_census.csv', parse_dates=['date'])
11842

11943

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):
17045
"""
17146
Test DEFAULTS.repr
17247
"""

0 commit comments

Comments
 (0)