Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

Commit

Permalink
Merge 40727f2 into e355a72
Browse files Browse the repository at this point in the history
  • Loading branch information
roll committed Mar 25, 2020
2 parents e355a72 + 40727f2 commit bceec91
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 5 additions & 1 deletion tabulator/parsers/inline.py
Expand Up @@ -5,6 +5,7 @@
from __future__ import unicode_literals

import six
from collections import OrderedDict
from ..parser import Parser
from .. import exceptions

Expand Down Expand Up @@ -65,7 +66,10 @@ def __iter_extended_rows(self):
elif isinstance(item, dict):
keys = []
values = []
for key in sorted(item.keys()):
iterator = item.keys()
if not isinstance(item, OrderedDict):
iterator = sorted(iterator)
for key in iterator:
keys.append(key)
values.append(item[key])
yield (row_number, list(keys), list(values))
Expand Down
11 changes: 11 additions & 0 deletions tests/formats/test_inline.py
Expand Up @@ -5,6 +5,7 @@
from __future__ import unicode_literals

import pytest
from collections import OrderedDict
from tabulator import Stream, exceptions


Expand Down Expand Up @@ -57,3 +58,13 @@ def test_stream_inline_keyed_with_headers_argument():
with Stream(source, format='inline', headers=['name', 'id']) as stream:
assert stream.headers == ['name', 'id']
assert stream.read() == [['english', '1'], ['中国人', '2']]


def test_stream_inline_ordered_dict():
source = [
OrderedDict([('name', 'english'), ('id', '1')]),
OrderedDict([('name', '中国人'), ('id', '2')]),
]
with Stream(source, headers=1) as stream:
assert stream.headers == ['name', 'id']
assert stream.read() == [['english', '1'], ['中国人', '2']]

0 comments on commit bceec91

Please sign in to comment.