Skip to content

Commit

Permalink
Fix inferring of resource & path names from name argument in 'load' (#85
Browse files Browse the repository at this point in the history
)

Fixes #85
  • Loading branch information
akariv committed May 27, 2019
1 parent 5e3d5a6 commit 6f55946
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion dataflows/processors/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def process_datapackage(self, dp: Package):
else:
path = os.path.basename(self.load_source)
path = os.path.splitext(path)[0]
descriptor = dict(path=path,
descriptor = dict(path=self.name or path,
profile='tabular-data-resource')
self.resource_descriptors.append(descriptor)
descriptor['name'] = self.name or path
Expand Down
19 changes: 19 additions & 0 deletions tests/test_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,25 @@ def test_load_strategies():
}


def test_load_name_path():
from dataflows import load

dp, *_ = Flow(
load('data/beatles_age.json', name='foo'),
load('data/beatles_age.csv')
).process()

print(dp.descriptor['resources'])

res0 = dp.resources[0]
res1 = dp.resources[1]

assert res0.name == 'foo'
assert res0.descriptor['path'] == 'foo.json'
assert res1.name == 'beatles_age'
assert res1.descriptor['path'] == 'beatles_age.csv'


def test_load_from_package_resources():
from dataflows import load

Expand Down

0 comments on commit 6f55946

Please sign in to comment.