def test_summarizer(monkeypatch, rand_data, pre_int_period, post_int_period): summarizer_mock = mock.Mock() fit_mock = mock.Mock() process_mock = mock.Mock() summarize_mock = mock.Mock() monkeypatch.setattr('causalimpact.main.CausalImpact._fit_model', fit_mock) monkeypatch.setattr('causalimpact.main.CausalImpact._summarize_inferences', summarize_mock) monkeypatch.setattr( 'causalimpact.main.CausalImpact._process_posterior_inferences', process_mock) monkeypatch.setattr('causalimpact.main.summarizer', summarizer_mock) ci = CausalImpact(rand_data, pre_int_period, post_int_period, model_args={'fit_method': 'vi'}) ci.summary_data = 'summary_data' ci.p_value = 0.5 ci.alpha = 0.05 ci.summary() summarizer_mock.summary.assert_called_with('summary_data', 0.5, 0.05, 'summary', 2) with pytest.raises(ValueError) as excinfo: ci.summary(digits='1') assert str( excinfo.value) == ('Input value for digits must be integer. Received ' '"<class \'str\'>" instead.')
def test_plot_raises_when_not_initialized(rand_data, pre_int_period, post_int_period, monkeypatch): ci = CausalImpact(rand_data, pre_int_period, post_int_period) ci.summary_data = None plotter_mock = mock.Mock() plot_mock = mock.Mock(return_value=plotter_mock) monkeypatch.setattr(plot.Plot, '_get_plotter', plot_mock) with pytest.raises(RuntimeError): ci.plot()