Skip to content

Commit

Permalink
Merge pull request #54 from DLHub-Argonne/fix_paths
Browse files Browse the repository at this point in the history
Bug Fix: Calling `to_dict` changes self in MetadataModel
  • Loading branch information
WardLT committed Mar 14, 2019
2 parents 46c2758 + 342ceac commit 0729dbe
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 3 additions & 2 deletions dlhub_sdk/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from datetime import datetime
from six import string_types
from zipfile import ZipFile
from copy import deepcopy
from glob import glob
import json
import sys
Expand Down Expand Up @@ -431,7 +432,7 @@ def to_dict(self, simplify_paths=False, save_class_data=False):
raise ValueError('Name must be specified. Use `set_name`')

# Make a copy of the output
out = dict(self._output)
out = deepcopy(self._output)

# Add the name of the class to the output, if desired
if save_class_data:
Expand Down Expand Up @@ -465,7 +466,7 @@ def from_dict(cls, data):

# Create the object, overwrite data
output = cls()
output._output = dict(data)
output._output = deepcopy(data)

# Make sure the class information is removed
if '@class' in output._output:
Expand Down
3 changes: 3 additions & 0 deletions dlhub_sdk/models/tests/test_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ def test_tabular_dataset(self):
metadata = m.to_dict(simplify_paths=True)
self.assertEqual({'data': 'test.csv'}, metadata['dlhub']['files'])

# Make sure the paths saved in the object have not changed
self.assertEqual({'data': data_path}, m['dlhub']['files'])

def test_zip(self):
"""Test generating a zip file with the requested files"""

Expand Down

0 comments on commit 0729dbe

Please sign in to comment.