예제 #1
0
def test_check_no_distributions(monkeypatch):
    stream = check.StringIO()

    monkeypatch.setattr(check, "_find_dists", lambda a: [])

    assert not check.check("dist/*", output_stream=stream)
    assert stream.getvalue() == "No files to check.\n"
예제 #2
0
def test_check_failing_distribution(monkeypatch):
    renderer = pretend.stub(
        render=pretend.call_recorder(lambda *a, **kw: None))
    package = pretend.stub(metadata_dictionary=lambda: {"description": "blah"})
    output_stream = check.StringIO()
    warning_stream = "WARNING"

    monkeypatch.setattr(check, "_RENDERERS", {"": renderer})
    monkeypatch.setattr(check, "_find_dists", lambda a: ["dist/dist.tar.gz"])
    monkeypatch.setattr(
        check,
        "PackageFile",
        pretend.stub(from_filename=lambda *a, **kw: package),
    )
    monkeypatch.setattr(check, "_WarningStream", lambda: warning_stream)

    assert check.check("dist/*", output_stream=output_stream)
    assert output_stream.getvalue() == (
        "Checking distribution dist/dist.tar.gz: Failed\n"
        "The project's long_description has invalid markup which will not be "
        "rendered on PyPI. The following syntax errors were detected:\n"
        "WARNING")
    assert renderer.render.calls == [
        pretend.call("blah", stream=warning_stream)
    ]
예제 #3
0
def test_check_failing_distribution(monkeypatch):
    renderer = pretend.stub(
        render=pretend.call_recorder(lambda *a, **kw: None))
    package = pretend.stub(metadata_dictionary=lambda: {
        "description": "blah",
        "description_content_type": 'text/markdown',
    })
    output_stream = check.StringIO()
    warning_stream = "WARNING"

    monkeypatch.setattr(check, "_RENDERERS", {None: renderer})
    monkeypatch.setattr(check, "_find_dists", lambda a: ["dist/dist.tar.gz"])
    monkeypatch.setattr(
        check,
        "PackageFile",
        pretend.stub(from_filename=lambda *a, **kw: package),
    )
    monkeypatch.setattr(check, "_WarningStream", lambda: warning_stream)

    assert check.check("dist/*", output_stream=output_stream)
    assert output_stream.getvalue() == (
        "Checking dist/dist.tar.gz: FAILED\n"
        "  `long_description` has syntax errors in markup and would not be "
        "rendered on PyPI.\n"
        "    WARNING")
    assert renderer.render.calls == [
        pretend.call("blah", stream=warning_stream)
    ]
예제 #4
0
파일: test_check.py 프로젝트: zooba/twine
def test_check_passing_distribution(monkeypatch):
    renderer = pretend.stub(
        render=pretend.call_recorder(lambda *a, **kw: "valid")
    )
    package = pretend.stub(metadata_dictionary=lambda: {
        "description": "blah", 'description_content_type': 'text/markdown',
    })
    output_stream = check.StringIO()
    warning_stream = ""

    monkeypatch.setattr(check, "_RENDERERS", {None: renderer})
    monkeypatch.setattr(check, "_find_dists", lambda a: ["dist/dist.tar.gz"])
    monkeypatch.setattr(
        check,
        "PackageFile",
        pretend.stub(from_filename=lambda *a, **kw: package),
    )
    monkeypatch.setattr(check, "_WarningStream", lambda: warning_stream)

    assert not check.check("dist/*", output_stream=output_stream)
    assert (
        output_stream.getvalue()
        == "Checking distribution dist/dist.tar.gz: Passed\n"
    )
    assert renderer.render.calls == [
        pretend.call("blah", stream=warning_stream)
    ]
예제 #5
0
def test_check_no_description(monkeypatch, capsys):
    package = pretend.stub(metadata_dictionary=lambda: {
        'description': None,
        'description_content_type': None,
    })

    monkeypatch.setattr(check, "_find_dists", lambda a: ["dist/dist.tar.gz"])
    monkeypatch.setattr(
        check,
        "PackageFile",
        pretend.stub(from_filename=lambda *a, **kw: package),
    )

    # used to crash with `AttributeError`
    output_stream = check.StringIO()
    check.check("dist/*", output_stream=output_stream)
    assert output_stream.getvalue() == (
        'Checking dist/dist.tar.gz: PASSED, with warnings\n'
        '  warning: `long_description_content_type` missing.  '
        'defaulting to `text/x-rst`.\n'
        '  warning: `long_description` missing.\n')