Skip to content

Commit 9fa3c79

Browse files
committed
mocking out RPC to covidcast.metadata
1 parent 363a93a commit 9fa3c79

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

_delphi_utils_python/tests/test_signal.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
"""Tests for delphi_utils.signal."""
2+
import pandas as pd
3+
from unittest.mock import patch
24

35
from delphi_utils.signal import add_prefix, public_signal
46

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})
610

711
class TestSignal:
812
"""Tests for signal.py."""
9-
def test_handle_wip_signal(self):
13+
14+
@patch("covidcast.metadata")
15+
def test_handle_wip_signal(self, metadata):
1016
"""Tests that `add_prefix()` derives work-in-progress signals."""
17+
metadata.return_value = SIGNALS_FRAME
18+
1119
# Test wip_signal = True
1220
signal_names = SIGNALS
1321
signal_names = add_prefix(SIGNALS, True, prefix="wip_")
@@ -21,7 +29,10 @@ def test_handle_wip_signal(self):
2129
assert signal_names[0].startswith("wip_")
2230
assert all(not s.startswith("wip_") for s in signal_names[1:])
2331

24-
def test_public_signal(self):
32+
@patch("covidcast.metadata")
33+
def test_public_signal(self, metadata):
2534
"""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

Comments
 (0)