Skip to content

Commit

Permalink
Add outline for tests for tinydb reader
Browse files Browse the repository at this point in the history
  • Loading branch information
MrKriss committed Nov 25, 2016
1 parent b290e32 commit a734838
Show file tree
Hide file tree
Showing 2 changed files with 413 additions and 10 deletions.
19 changes: 9 additions & 10 deletions sacred/observers/tinydb_hashfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,16 @@ def create(path='./runs_db', overwrite=None):
db = TinyDB(os.path.join(root_dir, 'metadata.json'),
storage=serialization_store)

return TinyDbObserver(db, fs, overwrite=overwrite)
return TinyDbObserver(db, fs, overwrite=overwrite, root=root_dir)

def __init__(self, db, fs, overwrite=None):
def __init__(self, db, fs, overwrite=None, root=None):
self.db = db
self.runs = db.table('runs')
self.fs = fs
self.overwrite = overwrite
self.run_entry = {}
self.db_run_id = None
self.root = root

def save(self):
"""Insert or update the current run entry."""
Expand All @@ -176,7 +177,7 @@ def save_sources(self, ex_info):

file = self.fs.get(md5)
if file:
id_ = file.id
id_ = file.id
else:
address = self.fs.put(abs_path)
id_ = address.id
Expand Down Expand Up @@ -341,18 +342,18 @@ def fetch_files(self, exp_name=None, query=None, indices=None):
"""

entries = self.fetch_metadata(exp_name, query, indices)
entries = self.fetch_metadata(exp_name, query, indices)

all_matched_entries = []
for ent in entries:
rec = dict(exp_name=ent['experiment']['name'],

rec = dict(exp_name=ent['experiment']['name'],
exp_id=ent['_id'],
date=ent['start_time'])

source_files = {x[0]: x[2] for x in ent['experiment']['sources']}
resource_files = {x[0]: x[2] for x in ent['resources']}
artifact_files = {x[0]: x[3] for x in ent['artifacts']}
artifact_files = {x[0]: x[3] for x in ent['artifacts']}

if source_files:
rec['sources'] = source_files
Expand Down Expand Up @@ -397,7 +398,7 @@ def fetch_report(self, exp_name=None, query=None, indices=None):

all_matched_entries = []
for ent in entries:

date = ent['start_time']
WEEKDAYS = 'Mon Tue Wed Thu Fri Sat Sun'.split()
w = WEEKDAYS[date.weekday()]
Expand Down Expand Up @@ -481,5 +482,3 @@ def _dict_to_indented_list(self, d):
output_str = textwrap.indent(output_str.strip(), prefix=' ')

return output_str


0 comments on commit a734838

Please sign in to comment.