コード例 #1
0
def test_find_format_width_filters_keys_not_present_in_header():
    report = [
        {"key1": "test 1", "key2": "value xyz test", "key3": "test test test test"},
        {"key1": "1", "key2": "value xyz", "key3": "test test test test"},
    ]
    header_with_subset_keys = {"key1": "Column 1", "key3": "Column 100"}
    result, _ = find_format_width(report, header_with_subset_keys)
    for item in result:
        assert "key2" not in item.keys()
コード例 #2
0
def to_table(output, header, include_header=True):
    """Output is a list of records"""
    if not output:
        return

    rows, column_size = find_format_width(output,
                                          header,
                                          include_header=include_header)
    return format_to_table(rows, column_size)
コード例 #3
0
def test_find_format_width_when_records_sets_width_to_greater_of_data_or_header_length():
    report = [
        {"key1": "test 1", "key2": "value xyz test", "key3": "test test test test"},
        {"key1": "1", "key2": "value xyz", "key3": "test test test test"},
    ]
    _, column_width = find_format_width(report, TEST_HEADER)
    assert column_width["key1"] == len(TEST_HEADER["key1"])
    assert column_width["key2"] == len(report[0]["key2"])
    assert column_width["key3"] == len(report[1]["key3"])
コード例 #4
0
def test_find_format_width_when_zero_records_sets_width_to_header_length():
    _, column_width = find_format_width([], TEST_HEADER)
    assert column_width["key1"] == len(TEST_HEADER["key1"])
    assert column_width["key2"] == len(TEST_HEADER["key2"])
    assert column_width["key3"] == len(TEST_HEADER["key3"])