Ejemplo n.º 1
0
def test_DictHeadersWhenNotDict():
    '''Test if DictHeaders only works for dicts.'''
    import tableful_utils
    testNonDict = ['First', 'Second', 'Third']
    expected = None
    headers = tableful_utils._GetDictHeaders(testNonDict)
    assert headers is expected, \
        "Headers were {} but should be None".format(headers)
Ejemplo n.º 2
0
def test_DictHeaders():
    '''Test that dictionaries are correctly turned into headers.'''
    import tableful_utils

    testDict = OrderedDict.fromkeys(['First', 'Second', 'Third'])
    expected = ('First', 'Second', 'Third')
    headers = tableful_utils._GetDictHeaders(testDict)
    assert expected == headers, \
        "Headers were {}, but should be {}".format(expected, headers)
Ejemplo n.º 3
0
def TablefulOfDict(dictionary, *, file=None):
    '''
    Prints a dict in a tableful way!

    keyword args:
    file - any object that can be written to
    '''
    headers = tableful_utils._GetDictHeaders(dictionary)
    rows = tableful_utils._GetDictRows(dictionary)
    Tableful(rows, headers=headers, file=file)
Ejemplo n.º 4
0
def TablefulOfDict(dictionary, *, file=None, delim="default"):
    '''
    Prints a dict in a tableful way!

    keyword args:
    file - any object that can be written to
    delim - set to html for an html table
            see docs of Tableful for custom delim settings which are passed through here
    '''
    headers = tableful_utils._GetDictHeaders(dictionary)
    rows = tableful_utils._GetDictRows(dictionary)
    Tableful(rows, headers=headers, file=file, delim=delim)