Skip to content

Commit

Permalink
Enable passing options from resource init to get_table (#222)
Browse files Browse the repository at this point in the history
Very similar to the way that these options are passed to the Storage.connect method,
we now use these options in the Table consturctor when storage is not used.
  • Loading branch information
akariv authored and roll committed Sep 4, 2018
1 parent 9c2b600 commit 108e2f1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion datapackage/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def __init__(self, descriptor={}, base_path=None, strict=False, storage=None,
self.__strict = strict
self.__table = None
self.__errors = []
self.__table_options = options

# Build resource
self.__build()
Expand Down Expand Up @@ -352,7 +353,7 @@ def __get_table(self):

# General resource
else:
options = {}
options = self.__table_options
descriptor = self.__current_descriptor
options['format'] = descriptor.get('format', 'csv')
if descriptor.get('data'):
Expand Down
17 changes: 17 additions & 0 deletions tests/test_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,23 @@ def test_descriptor_table_tabular_dialect_header_false():
{'id': 2, 'name': '中国人'},
]

# Resource table options
def test_resource_table_options(patch_get):
descriptor = {
'name': 'name',
'profile': 'tabular-data-resource',
'path': ['http://example.com/resource_data.csv'],
'schema': 'resource_schema.json',
}
# Mocks
patch_get('http://example.com/resource_data.csv', body="\n\nid,name\n1,english\n2,中国人")
# Tests
resource = Resource(descriptor, base_path='data', headers=3)
assert resource.table.read(keyed=True) == [
{'id': 1, 'name': 'english'},
{'id': 2, 'name': '中国人'},
]


# Resource.raw_iter/read

Expand Down

0 comments on commit 108e2f1

Please sign in to comment.