Skip to content

Commit

Permalink
Merge pull request #125 from datmo/default-config-stats
Browse files Browse the repository at this point in the history
adding default config and stats
  • Loading branch information
asampat3090 committed May 12, 2018
2 parents 27f3e52 + cc28dd4 commit 1d69c96
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 14 deletions.
17 changes: 10 additions & 7 deletions datmo/core/controller/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,8 @@ def _config_setup(self, incoming_dictionary, create_dict):
""" Fills in snapshot config by having one of the following:
1. config = JSON object
2. config_filepath = some location where a json file exists
3. config_filename = just the file nam
3. config_filename = just the file name
Parameters
----------
incoming_dictionary : dict
Expand All @@ -416,12 +417,13 @@ def _config_setup(self, incoming_dictionary, create_dict):
incoming_dictionary['config_filepath'])
create_dict['config'] = config_json_driver.to_dict()
elif "config_filename" in incoming_dictionary:
config_filename = incoming_dictionary['config_filename'] \
if "config_filename" in incoming_dictionary else "config.json"
config_filename = incoming_dictionary['config_filename']
create_dict['config'] = self._find_in_filecollection(
config_filename, create_dict['file_collection_id'])
else:
create_dict['config'] = {}
config_filename = "config.json"
create_dict['config'] = self._find_in_filecollection(
config_filename, create_dict['file_collection_id'])

def _stats_setup(self, incoming_dictionary, create_dict):
"""Fills in snapshot stats by having one of the following:
Expand Down Expand Up @@ -452,12 +454,13 @@ def _stats_setup(self, incoming_dictionary, create_dict):
incoming_dictionary['stats_filepath'])
create_dict['stats'] = stats_json_driver.to_dict()
elif "stats_filename" in incoming_dictionary:
stats_filename = incoming_dictionary['stats_filename'] \
if "stats_filename" in incoming_dictionary else "stats.json"
stats_filename = incoming_dictionary['stats_filename']
create_dict['stats'] = self._find_in_filecollection(
stats_filename, create_dict['file_collection_id'])
else:
create_dict['stats'] = {}
stats_filename = "stats.json"
create_dict['stats'] = self._find_in_filecollection(
stats_filename, create_dict['file_collection_id'])

def _find_in_filecollection(self, file_to_find, file_collection_id):
""" Attempts to find a file within the file collection
Expand Down
32 changes: 25 additions & 7 deletions datmo/core/controller/tests/test_snapshot_private.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,20 @@ def test_config_setup_with_filename(self):
self.snapshot._config_setup(incoming_data, final_data)
assert final_data['config']["foo"] == 1

def test_config_setup_with_empty(self):
def test_config_setup_with_empty_and_file(self):
incoming_data = {}
final_data = {}
self.snapshot._file_setup(incoming_data, final_data)
self.snapshot._config_setup(incoming_data, final_data)
assert final_data["config"]["foo"] == 1

def test_config_setup_with_empty_no_file(self):
os.remove(os.path.join(self.snapshot.home, "config.json"))
incoming_data = {}
final_data = {}
self.snapshot._file_setup(incoming_data, final_data)
self.snapshot._config_setup(incoming_data, final_data)
assert final_data['config'] == {}
assert final_data["config"] == {}

def test_stats_setup_with_json(self):
incoming_data = {"stats": {"bar": 1}}
Expand All @@ -120,15 +129,24 @@ def test_stats_setup_with_filepath(self):
self.snapshot._stats_setup(incoming_data, final_data)
assert final_data['stats']["bar"] == 1

def test_stats_setup_with_empty(self):
incoming_data = {}
def test_stats_setup_with_filename(self):
incoming_data = {"stats_filename": "stats.json"}
final_data = {}
self.snapshot._file_setup(incoming_data, final_data)
self.snapshot._stats_setup(incoming_data, final_data)
assert final_data['stats'] == {}
assert final_data['stats']["bar"] == 1

def test_stats_setup_with_filename(self):
incoming_data = {"stats_filename": "stats.json"}
def test_stats_setup_with_empty_with_file(self):
incoming_data = {}
final_data = {}
self.snapshot._file_setup(incoming_data, final_data)
self.snapshot._stats_setup(incoming_data, final_data)
assert final_data['stats']["bar"] == 1

def test_stats_setup_with_empty_no_file(self):
os.remove(os.path.join(self.snapshot.home, "stats.json"))
incoming_data = {}
final_data = {}
self.snapshot._file_setup(incoming_data, final_data)
self.snapshot._stats_setup(incoming_data, final_data)
assert final_data["stats"] == {}

0 comments on commit 1d69c96

Please sign in to comment.