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)
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)
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)
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)