def test_run(self, mock_change_dir, fx_deployments, monkeypatch, runway_context, tmp_path): """Test run.""" mock_type = MagicMock() mock_inst = MagicMock() mock_inst.deploy = MagicMock() mock_type.module_class.return_value = mock_inst monkeypatch.setattr(Module, "should_skip", True) monkeypatch.setattr(Module, "path", MagicMock(module_root=str(tmp_path))) monkeypatch.setattr(Module, "type", mock_type) mod = Module( context=runway_context, definition=fx_deployments.load("min_required").modules[0], ) assert not mod.run("deploy") mock_change_dir.assert_not_called() monkeypatch.setattr(Module, "should_skip", False) assert not mod.run("deploy") mock_change_dir.assert_called_once_with(str(tmp_path)) mock_type.module_class.assert_called_once_with(context=mod.ctx, path=str(tmp_path), options=mod.payload) mock_inst["deploy"].assert_called_once_with() del mock_inst.deploy with pytest.raises(SystemExit) as excinfo: assert mod.run("deploy") assert excinfo.value.code == 1
def test_run( self, empty_opts_from_file: None, fx_deployments: YamlLoaderDeployment, mocker: MockerFixture, runway_context: MockRunwayContext, tmp_path: Path, ) -> None: """Test run.""" mock_change_dir = mocker.patch(f"{MODULE}.change_dir") mock_type = MagicMock() mock_inst = MagicMock() mock_inst.deploy = MagicMock() mock_type.module_class.return_value = mock_inst mocker.patch.object(Module, "should_skip", True) mocker.patch.object(Module, "path", MagicMock(module_root=tmp_path)) mocker.patch.object(Module, "type", mock_type) mod = Module( context=runway_context, definition=fx_deployments.load("min_required").modules[0], ) assert not mod.run("deploy") mock_change_dir.assert_not_called() mocker.patch.object(Module, "should_skip", False) assert not mod.run("deploy") mock_change_dir.assert_called_once_with(tmp_path) mock_type.module_class.assert_called_once_with(mod.ctx, module_root=tmp_path, **mod.payload) mock_inst["deploy"].assert_called_once_with() del mock_inst.deploy with pytest.raises(SystemExit) as excinfo: assert mod.run("deploy") assert excinfo.value.code == 1