from .tabulate import find_columns, pad, MISSING, concat, symbol, columnize


def test_pad():
    assert pad("HW2", 12345) == "HW2  ", "should pad to the left to the width of the number"
    assert pad("HW2", 1) == "HW2", "should not trim the string if the number is shorter"
    assert pad(MISSING, 12345) == (MISSING * 5), "should use MISSING if given"


def test_find_columns():
    assert find_columns(10) == "1 2 3 4 5 6 7 8 9 10", "should return incremental numbers between 1 and the argument"


def test_symbol():
    assert symbol({'number': 5, 'status': 'success'}) == '5', "return the number for sucessful assignments"
    assert symbol({'number': 5, 'status': 'missing'}) == MISSING, "returns MISSING for missing assignments"
    assert symbol({'number': 5, 'status': 'partial'}) == '5', "returns the raw number ift stdout can't handle fanciness"


def test_concat():
    assert concat([
        {'number': 1, 'status': 'success'},
        {'number': 2, 'status': 'success'},
    ], 2) == "1 2", "should turn an assignment list into a string"

    assert concat([
        {'number': 1, 'status': 'success'},
        {'number': 2, 'status': 'success'},
    ], 6) == "1 2 - - - -", "should output hyphens when no assignments are given"

    assert concat([
        {'number': 1, 'status': 'success'},
        {'number': 6, 'status': 'success'},
    ], 6) == "1 - - - - 6", "should handle missing assignments in between others"

    assert concat([
        {'number': 10, 'status': 'success'},
        {'number': 11, 'status': 'success'},
    ], 12) == "- - - - - - - - - 10 11 --", "should output two hyphens for two-digit numbers"


def test_columnize():
    student = {
        'username': 'rives',
        'unmerged_branches': False,
        'homeworks': [
            {'number': 1, 'status': 'success'},
            {'number': 2, 'status': 'success'},
        ],
        'labs': [
            {'number': 1, 'status': 'success'},
        ]
    }

    assert columnize(student, 'rives', 2, 1) == "rives  | 1 2 | 1"
    assert columnize(student, 'long_username', 2, 1) == "rives          | 1 2 | 1"
    assert columnize(student, 'rives', 5, 1) == "rives  | 1 2 - - - | 1"
    assert columnize(student, 'rives', 2, 5) == "rives  | 1 2 | 1 - - - -"

    student2 = {
        'username': 'rives',
        'unmerged_branches': True,
        'homeworks': [
            {'number': 1, 'status': 'success'},
            {'number': 2, 'status': 'success'},
        ],
        'labs': [
            {'number': 1, 'status': 'success'},
        ]
    }

    assert columnize(student2, 'rives', 2, 1) == "\033[1mrives\033[0m  | 1 2 | 1"

@@ -2615,20 +2615,249 @@
 %5C033%5B0m  %7C 1 2 %7C 1%22%0A
+%0A    student3 = %7B%0A        'username': 'rives',%0A        'error': 'an error occurred',%0A        'homeworks': %5B%5D,%0A        'labs': %5B%5D,%0A    %7D%0A%0A    assert columnize(student3, 'rives', 2, 1) == %22%7Busername%7D  %7C %7Berror%7D%22.format(**student3)%0A

add test for "error": true