Skip to content

Commit

Permalink
Merge pull request #30 from materials-data-facility/toolbox-dev
Browse files Browse the repository at this point in the history
Toolbox dev
  • Loading branch information
jgaff authored Nov 20, 2018
2 parents 78ec18b + f3e53e1 commit d00c061
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 17 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ python:
- '3.4'
- '3.5'
- '3.6'
# - '3.7' # Unsupported on Travis
install:
- pip install --upgrade pip
- pip install -e .
Expand Down
18 changes: 7 additions & 11 deletions mdf_toolbox/toolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@
import globus_sdk
from globus_sdk.base import BaseClient
from globus_sdk.response import GlobusHTTPResponse
try:
from mdf_connect_client import MDFConnectClient
except ImportError:
print("Proceeding without mdf_connect_client")
MDFConnectClient = None


KNOWN_SCOPES = {
Expand Down Expand Up @@ -45,7 +40,6 @@
"search": globus_sdk.SearchClient,
"search_ingest": globus_sdk.SearchClient,
# "publish": DataPublicationClient, # Defined in this module, added to dict later
"mdf_connect": MDFConnectClient,
"groups": NexusClient
}
SEARCH_INDEX_UUIDS = {
Expand Down Expand Up @@ -950,7 +944,8 @@ def get_local_ep(transfer_client):
def dict_merge(base, addition):
"""Merge one dictionary with another, recursively.
Fields present in addition will be added to base.
No data in base is deleted or overwritten.
No data from base is deleted or overwritten.
This function does not modify either dictionary.
Arguments:
base (dict): The dictionary being added to.
Expand All @@ -962,15 +957,16 @@ def dict_merge(base, addition):
if not isinstance(base, dict) or not isinstance(addition, dict):
raise TypeError("dict_merge only works with dicts.")

new_base = deepcopy(base)
for key, value in addition.items():
# If the value is a dict, need to merge those
if isinstance(value, dict):
base[key] = dict_merge(base.get(key, {}), value)
new_base[key] = dict_merge(new_base.get(key, {}), value)
# Otherwise, if the key is not in base, add it
elif key not in base.keys():
base[key] = value
elif key not in new_base.keys():
new_base[key] = value

return base
return new_base


def insensitive_comparison(item1, item2, type_insensitive=False, string_insensitive=False):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='mdf_toolbox',
version='0.3.4',
version='0.3.5',
packages=['mdf_toolbox'],
description='Materials Data Facility Python utilities',
long_description=("Toolbox is the Materials Data Facility Python package"
Expand Down
11 changes: 6 additions & 5 deletions tests/test_toolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ def test_login(capsys, monkeypatch):
assert isinstance(res2.get("publish"), mdf_toolbox.DataPublicationClient)
assert isinstance(res2.get("groups"), NexusClient)

creds3 = deepcopy(credentials)
creds3["services"] = "mdf_connect"
res3 = mdf_toolbox.login(creds3)
assert isinstance(res3.get("mdf_connect"), mdf_toolbox.MDFConnectClient)

# Test fetching previous tokens
creds = deepcopy(credentials)
assert mdf_toolbox.login(creds).get("petrel_https_server")
Expand Down Expand Up @@ -410,7 +405,13 @@ def test_dict_merge():
}
}
# Proper use
old_base = deepcopy(base)
old_add = deepcopy(add)
assert mdf_toolbox.dict_merge(base, add) == merged
# Originals should be unchanged
assert base == old_base
assert add == old_add

assert mdf_toolbox.dict_merge({}, {}) == {}

# Check errors
Expand Down

0 comments on commit d00c061

Please sign in to comment.