def test_dict_containing_lists_different_dimensions():
    input = {
        'Name':
            'Message',
        'Length':
            16,
        'Signal': [{
            'Name': 'Signal1',
            'Length': 8
        }, {
            'Name': 'Signal2',
            'Length': 8
        }],
        'SignalGroup': [{
            'Name': 'SignalGroup1'
        }, {
            'Name': 'SignalGroup2'
        }, {
            'Name': 'SignalGroup3'
        }]
    }

    result = tabularize([input])

    assert result == [['Message', 16, 'Signal1', 8, 'SignalGroup1'],
                      ['Message', 16, 'Signal1', 8, 'SignalGroup2'],
                      ['Message', 16, 'Signal1', 8, 'SignalGroup3'],
                      ['Message', 16, 'Signal2', 8, 'SignalGroup1'],
                      ['Message', 16, 'Signal2', 8, 'SignalGroup2'],
                      ['Message', 16, 'Signal2', 8, 'SignalGroup3']]
Exemple #2
0
    def as_table(self, data: dict) -> str:
        text = []
        headers = self.analyze_headers(data)
        for i, values in enumerate(data.values()):
            if not isinstance(values, list):
                values = [values]
            rows = tabularize(values)
            text.append(tabulate(rows, headers=headers[i], tablefmt="orgtbl"))

        return '\n\n\n'.join(text)
    def write_data_frames(self, sheet, data, start_row):
        if isinstance(data, dict):
            data = [data]

        data_frames = tabularize(data)
        for row_idx, df in enumerate(data_frames, start_row + 1):
            sheet.write_row(row_idx, 0, df)

        row_count = len(data_frames)
        column_count = len(data_frames[0]) - 1
        sheet.autofilter(start_row, 0, row_count, column_count)
def test_flatten_nested_dict():
    input = {
        'Name': 'Message',
        'Length': 8,
        'Cyclic Timing': 0.1,
        'Signal': {
            'Name': 'Signal1',
            'Length': 8
        }
    }

    result = tabularize([input])

    assert result == [['Message', 8, 0.1, 'Signal1', 8]]
def test_dict_containing_list():
    input = {
        'Name': 'Message',
        'Length': 16,
        'Signal': [{
            'Name': 'Signal1',
            'Length': 8
        }, {
            'Name': 'Signal2',
            'Length': 8
        }]
    }

    result = tabularize([input])

    assert result == [['Message', 16, 'Signal1', 8], ['Message', 16, 'Signal2', 8]]
def test_flatten_dict():
    input = {'Name': 'Message', 'Length': 16, 'Cyclic Timing': 0.1}

    result = tabularize([input])

    assert result == [['Message', 16, 0.1]]
def test_multiple_entries():
    input = [{'Name': 'Request', 'Length': 8}, {'Name': 'Response', 'Length': 16}]

    result = tabularize(input)

    assert result == [['Request', 8], ['Response', 16]]