Esempio n. 1
0
def test_notice():
    """Test notice-related functions of the error bundler."""

    # Use the StringIO as an output buffer.
    bundle = ErrorBundle()

    bundle.notice((), "")

    # Load the JSON output as an object.
    output = json.loads(bundle.render_json())

    # Run some basic tests
    assert len(output["messages"]) == 1

    print output

    has_ = False

    for message in output["messages"]:
        print message

        if message["type"] == "notice":
            has_ = True

    assert has_
    assert not bundle.failed()
    assert not bundle.failed(True)
Esempio n. 2
0
def test_notice_friendly():
    """
    Test notice-related human-friendly text output functions of the error
    bundler.
    """

    # Use the StringIO as an output buffer.
    bundle = ErrorBundle()

    bundle.notice((), "foobar")

    # Load the JSON output as an object.
    output = bundle.print_summary(verbose=True, no_color=True)
    print output

    assert output.count("foobar")
Esempio n. 3
0
def test_json():
    """Test the JSON output capability of the error bundler."""

    # Use the StringIO as an output buffer.
    bundle = ErrorBundle() # No color since no output
    bundle.set_tier(4)
    bundle.set_tier(3)

    bundle.error((), "error", "description")
    bundle.warning((), "warning", "description")
    bundle.notice((), "notice", "description")

    results = json.loads(bundle.render_json())

    eq_(len(results["messages"]), 3)
    assert not results["success"]
    eq_(results["ending_tier"], 4)
Esempio n. 4
0
def test_json_constructs():
    """This tests some of the internal JSON stuff so we don't break zamboni."""

    e = ErrorBundle()
    e.error(("a", "b", "c"), "Test")
    e.error(("a", "b", "foo"), "Test")
    e.error(("a", "foo", "c"), "Test")
    e.error(("a", "foo", "c"), "Test")
    e.error(("b", "foo", "bar"), "Test")
    e.warning((), "Context test",
              context=ContextGenerator("x\ny\nz\n"),
              line=2, column=0)
    e.notice((), "none")
    e.notice((), "line", line=1)
    e.notice((), "column", column=0)
    e.notice((), "line column", line=1, column=1)

    results = e.render_json()
    print results
    j = json.loads(results)

    assert "messages" in j
    for m in j["messages"]:
        if m["type"] == "warning":
            assert m["context"] == ["x", "y", "z"]

    for m in (m for m in j["messages"] if m["type"] == "notice"):
        if "line" in m["message"]:
            assert m["line"] is not None
            assert isinstance(m["line"], int)
            assert m["line"] > 0
        else:
            assert m["line"] is None

        if "column" in m["message"]:
            assert m["column"] is not None
            assert isinstance(m["column"], int)
            assert m["column"] > -1
        else:
            assert m["column"] is None