コード例 #1
0
def test_save_badge_no_cairo(monkeypatch):
    """PNG can't be generated without extra dependencies installed."""
    monkeypatch.setattr("interrogate.badge_gen.cairosvg", None)
    badge_contents = "<svg>foo</svg>"

    with pytest.raises(ImportError, match="The required `cairosvg` "):
        badge_gen.save_badge(badge_contents,
                             "fixtures/my_badge.png",
                             output_format="png")
コード例 #2
0
def test_save_badge_windows(mocker):
    """Badge is saved in the expected location."""
    mock_open = mocker.mock_open()
    m = mocker.patch("interrogate.badge_gen.open", mock_open)
    output = "C:\\foo\\bar\\my_badge.svg"
    badge_contents = "<svg>foo</svg>"

    actual = badge_gen.save_badge(badge_contents, output)
    assert output == actual
    m.assert_called_once_with(output, "w")
コード例 #3
0
def test_save_badge(output, is_dir, expected, mocker, monkeypatch):
    """Badge is saved in the expected location."""
    monkeypatch.setattr(badge_gen.os.path, "isdir", lambda x: is_dir)

    mock_open = mocker.mock_open()
    m = mocker.patch("interrogate.badge_gen.open", mock_open)

    badge_contents = "<svg>foo</svg>"

    actual = badge_gen.save_badge(badge_contents, output)
    assert expected == actual
    m.assert_called_once_with(expected, "w")
コード例 #4
0
def test_save_badge(out_format, out_file, exp_called_with, mocker,
                    monkeypatch):
    """Badge is saved in the expected location."""
    mock_cairosvg = mocker.Mock()
    monkeypatch.setattr(badge_gen, "cairosvg", mock_cairosvg)

    mock_open = mocker.mock_open()
    m = mocker.patch("interrogate.badge_gen.open", mock_open)
    mock_rm = mocker.patch("interrogate.badge_gen.os.remove", mocker.Mock())

    badge_contents = "<svg>foo</svg>"

    actual = badge_gen.save_badge(badge_contents, out_file, out_format)
    assert out_file == actual
    m.assert_called_once_with(exp_called_with, "w")
    if out_format == "png":
        mock_cairosvg.svg2png.assert_called_once_with(url=exp_called_with,
                                                      write_to=out_file,
                                                      scale=2)
        mock_rm.assert_called_once_with(exp_called_with)