Skip to content

Commit

Permalink
supporting patching simulator specs
Browse files Browse the repository at this point in the history
  • Loading branch information
jonrkarr committed Dec 23, 2020
1 parent 1e954a4 commit b9adba2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion biosimulators_utils/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.1.17'
__version__ = '0.1.18'
8 changes: 7 additions & 1 deletion biosimulators_utils/simulator/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
import simplejson.errors


def read_simulator_specs(path_or_url):
def read_simulator_specs(path_or_url, patch=None):
""" Read the specifications of a simulator
Args:
path_or_url (:obj:`str`): file path or URL for the specifications of a simulator
patch (:obj:`dict`, optional): values of properties to supersede those in :obj:`path_or_url`
Returns:
:obj:`dict`: specifications of a simulator
Expand Down Expand Up @@ -55,6 +56,11 @@ def read_simulator_specs(path_or_url):
'Specifications must be encoded into JSON.\n\n {}'.format(str(error).replace('\n', '\n ')),
]))

# apply patch
if patch:
for key, val in patch.items():
specs[key] = val

# validate specifications
api_endpoint = get_config().BIOSIMULATORS_API_ENDPOINT
response = requests.post('{}simulators/validate'.format(api_endpoint), json=specs)
Expand Down
3 changes: 2 additions & 1 deletion tests/simulator/test_simulator_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ def test_file (self):

def test_url(self):
url = 'https://raw.githubusercontent.com/biosimulators/Biosimulators_tellurium/dev/biosimulators.json'
specs = read_simulator_specs(url)
specs = read_simulator_specs(url, patch={'version': '0.0.0'})
self.assertEqual(specs['version'], '0.0.0')

with self.assertRaises(requests.RequestException):
url = 'https://raw.githubusercontent.com/biosimulators/Biosimulators_tellurium/dev/__undefined__'
Expand Down

0 comments on commit b9adba2

Please sign in to comment.