1
1
"""Tests for delphi_utils.signal."""
2
+ import pandas as pd
3
+ from unittest .mock import patch
2
4
3
5
from delphi_utils .signal import add_prefix , public_signal
4
6
5
- SIGNALS = ["median_home_dwell_time" , "completely_home_prop" , "full_time_work_prop" ]
7
+ # Constants for mocking out the call to `covidcast.metadata` within `public_signal()`.
8
+ SIGNALS = ["sig1" , "sig2" , "sig3" ]
9
+ SIGNALS_FRAME = pd .DataFrame (data = {"signal" : SIGNALS })
6
10
7
11
class TestSignal :
8
12
"""Tests for signal.py."""
9
- def test_handle_wip_signal (self ):
13
+
14
+ @patch ("covidcast.metadata" )
15
+ def test_handle_wip_signal (self , metadata ):
10
16
"""Tests that `add_prefix()` derives work-in-progress signals."""
17
+ metadata .return_value = SIGNALS_FRAME
18
+
11
19
# Test wip_signal = True
12
20
signal_names = SIGNALS
13
21
signal_names = add_prefix (SIGNALS , True , prefix = "wip_" )
@@ -21,7 +29,10 @@ def test_handle_wip_signal(self):
21
29
assert signal_names [0 ].startswith ("wip_" )
22
30
assert all (not s .startswith ("wip_" ) for s in signal_names [1 :])
23
31
24
- def test_public_signal (self ):
32
+ @patch ("covidcast.metadata" )
33
+ def test_public_signal (self , metadata ):
25
34
"""Tests that `public_signal()` identifies public vs. private signals."""
26
- assert not public_signal ("junk" )
27
- assert public_signal ("covid_ag_smoothed_pct_positive" )
35
+ metadata .return_value = SIGNALS_FRAME
36
+
37
+ assert not public_signal ("sig0" )
38
+ assert public_signal ("sig2" )
0 commit comments