Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions DataProcessingTools/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ class DPObject():

def __init__(self, *args, **kwargs):
fname = kwargs.get("loadFrom", None)
if isinstance(fname, list):
# go through the list of filenames and check if one matches for this object
bn, ext = os.path.splitext(self.filename)
found = False
for fn in fname:
if fn.find(bn) > -1:
fname = fn
found = True
break
if not found:
fname = None
_dirs = kwargs.get("dirs")
if fname is not None:
self.load(fname=fname)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from distutils.core import setup

setup(name="DataProcessingTools",
version="0.20.0",
version="0.21.0",
description="""Tools for processing data with hierarchical organization""",
url="https://github.com/grero/DataProcessingTools.git",
author="Roger Herikstad",
Expand Down
9 changes: 9 additions & 0 deletions tests/test_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ def test_append():
obj1 = MyObj([0.1, 0.2, 0.3])
h = obj1.hash()
assert h == "c872"
# test that we can ignore files
obj2 = MyObj([0.1, 0.2, 0.3], loadFrom=["fake_file.hkl"])
h2 = obj2.hash()
assert h2 == h

for d in dirs[1:]:
with DPT.misc.CWD(d):
Expand Down Expand Up @@ -122,6 +126,11 @@ def test_append():
assert obj7.args["bins"] == obj.args["bins"]
assert obj7.dirs == obj.dirs

obj8 = MyObj(loadFrom=["myobj_c872.hkl",
"something_else.hkl"])

assert obj8.dirs == obj.dirs

os.remove(obj.get_filename())

def test_object():
Expand Down