예제 #1
0
def test__cli__formatters__violations():
    # check not just the formatting, but the ordering
    v = {
        'foo': [
            RuleViolation(
                PositionedChunk('blah', 1, 25, 'context'),
                RuleGhost('A', 'DESC'), []),
            RuleViolation(
                PositionedChunk('blah', 2, 21, 'context'),
                RuleGhost('B', 'DESC'), [])],
        'bar': [
            RuleViolation(
                PositionedChunk('blah', 10, 2, 'context'),
                RuleGhost('C', 'DESC'), [])]
    }
    f = format_violations(v)
    k = sorted(['foo', 'bar'])
    chk = {
        'foo': ["L:  21 | P:   3 | B | DESC", "L:  25 | P:   2 | A | DESC"],
        'bar': ["L:   2 | P:  11 | C | DESC"]
    }
    chk2 = []
    for elem in k:
        chk2 = chk2 + [format_filename(elem)] + chk[elem]
    chk2 = '\n'.join(chk2)
    assert escape_ansi(f) == escape_ansi(chk2)
예제 #2
0
def test__cli__formatters__violations():
    """Test formatting and ordering of violations."""
    v = {
        'foo': [
            SQLLintError(segment=RawSegment('blah',
                                            FilePositionMarker(0, 25, 2, 26)),
                         rule=RuleGhost('A', 'DESCR')),
            # Here we check the optional description override
            SQLLintError(segment=RawSegment('blah',
                                            FilePositionMarker(0, 21, 3, 22)),
                         rule=RuleGhost('B', 'DESCR'),
                         description='foo')
        ],
        'bar': [
            SQLLintError(segment=RawSegment('blah',
                                            FilePositionMarker(0, 2, 11, 3)),
                         rule=RuleGhost('C', 'DESCR'))
        ]
    }
    f = format_path_violations(v)
    k = sorted(['foo', 'bar'])
    chk = {
        'foo':
        ["L:  21 | P:   3 |    B | foo", "L:  25 | P:   2 |    A | DESCR"],
        'bar': ["L:   2 | P:  11 |    C | DESCR"]
    }
    chk2 = []
    for elem in k:
        chk2 = chk2 + [format_filename(elem)] + chk[elem]
    chk2 = '\n'.join(chk2)
    assert escape_ansi(f) == escape_ansi(chk2)
예제 #3
0
def test__cli__formatters__filename_col():
    """ Explicity test color codes """
    res = format_filename('blah', success=False, verbose=0)
    assert res == u"== [\u001b[30;1mblah\u001b[0m] \u001b[31mFAIL\u001b[0m"
예제 #4
0
def test__cli__formatters__filename_nocol():
    res = format_filename('blahblah', success=True, verbose=0)
    assert escape_ansi(res) == "== [blahblah] PASS"
예제 #5
0
def test__cli__formatters__filename_nocol():
    """Test formatting filenames."""
    res = format_filename("blahblah", success=True)
    assert escape_ansi(res) == "== [blahblah] PASS"