def test_pull_image(monkeypatch): storage = Docker(base_image="python:3.6") pull = MagicMock(return_value=[{"progress": "test"}]) monkeypatch.setattr("docker.APIClient", MagicMock(pull=MagicMock(return_value=pull))) storage.pull_image() assert storage
def test_pull_image(capsys, monkeypatch): storage = Docker(base_image="python:3.6") client = MagicMock() client.pull.return_value = [{"progress": "test", "status": "100"}] monkeypatch.setattr("docker.APIClient", MagicMock(return_value=client)) storage.pull_image() captured = capsys.readouterr() printed_lines = [line for line in captured.out.split("\n") if line != ""] assert any(["100 test\r" in line for line in printed_lines])
def test_pull_image_raises_if_error_encountered(monkeypatch): storage = Docker(base_image="python:3.6") client = MagicMock() client.pull.return_value = [ {"progress": "test"}, {"error": "you know nothing jon snow"}, ] monkeypatch.setattr("docker.APIClient", MagicMock(return_value=client)) with pytest.raises(InterruptedError, match="you know nothing jon snow"): storage.pull_image()