def test_run__exception__create_temp_dir(): cfg_mock = Mock(temp_root=_DUMMY_TEMP_ROOT) node_mock = Node() node_mock._create_temp_dir = Mock() node_mock._create_temp_dir.side_effect = OSError() with pytest.raises(NodeUnhandledException): node_mock.run(cfg_mock) assert node_mock._create_temp_dir.mock_calls == [call(cfg_mock)]
def test_run__exception__remove_temp_dir(): cfg_mock = Mock(temp_root=_DUMMY_TEMP_ROOT) mock = Mock() node_mock = Node() node_mock._create_temp_dir = mock._create_temp_dir node_mock._create_temp_dir.return_value = _DUMMY_TEMP node_mock._remove_temp_dir = mock._remove_temp_dir node_mock._remove_temp_dir.side_effect = OSError() with pytest.raises(NodeUnhandledException): node_mock.run(cfg_mock) assert mock.mock_calls == [ call._create_temp_dir(cfg_mock), call._remove_temp_dir(_DUMMY_TEMP), ]
def test_run__exceptions(key, exception, expectation): mock = Mock() node = Node() node._create_temp_dir = mock._create_temp_dir node._create_temp_dir.return_value = _DUMMY_TEMP setattr(node, key, getattr(mock, key)) getattr(node, key).side_effect = exception cfg_mock = Mock(temp_root=_DUMMY_TEMP_ROOT) with pytest.raises(expectation): node.run(cfg_mock) assert mock.mock_calls == [ call._create_temp_dir(cfg_mock), getattr(call, key)(cfg_mock, _DUMMY_TEMP), ]
def test_run__error_log__node_error(tmp_path, exception): temp = tmp_path / "xTMPx" mock = Mock() cfg_mock = Mock(temp_root=tmp_path) node_mock = Node() node_mock._create_temp_dir = mock._create_temp_dir node_mock._create_temp_dir.return_value = temp node_mock._run = mock._run node_mock._run.side_effect = exception("ARGH!") os.mkdir(temp) with pytest.raises(NodeError): node_mock.run(cfg_mock) log_file = tmp_path / "xTMPx" / "pipe.errors" assert log_file.exists() assert "Errors =" in log_file.read_text() assert mock.mock_calls == [ call._create_temp_dir(cfg_mock), call._run(cfg_mock, temp), ]
def test_run__order(): cfg_mock = Mock(temp_root=_DUMMY_TEMP_ROOT) node_mock = Mock() node = Node() node._create_temp_dir = node_mock._create_temp_dir node._create_temp_dir.return_value = _DUMMY_TEMP node._setup = node_mock._setup node._run = node_mock._run node._teardown = node_mock._teardown node._remove_temp_dir = node_mock._remove_temp_dir node.run(cfg_mock) node_mock.mock_calls == [ call._create_temp_dir(cfg_mock), call._setup(cfg_mock, _DUMMY_TEMP), call._run(cfg_mock, _DUMMY_TEMP), call._teardown(cfg_mock, _DUMMY_TEMP), call._remove_temp_dir(_DUMMY_TEMP), ]