Skip to content

Commit

Permalink
Merge pull request #76 from UM-Bridge/testing-multi-input
Browse files Browse the repository at this point in the history
Modified CI to allow vector input
  • Loading branch information
annereinarz authored May 23, 2024
2 parents 1392a93 + b16916a commit fec642b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
8 changes: 6 additions & 2 deletions testing/protocol_conformity_1.0/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

def pytest_addoption(parser):
parser.addoption("--model_url", action="store", help="what model URL to connect to")
parser.addoption("--input_value", action="store", default=0.0, help="value of constant input vector to be passed to the model, since some models may not handle the default well")
parser.addoption("--input_value", action="store", default=0.0, help="input vector or constant value to fill the vector to be passed to the model, since some models may not handle the default well. No spaces allowed when inputting vector!")

def pytest_generate_tests(metafunc):
option_value = metafunc.config.option.model_url
Expand All @@ -11,4 +11,8 @@ def pytest_generate_tests(metafunc):

option_value = metafunc.config.option.input_value
if 'input_value' in metafunc.fixturenames and option_value is not None:
metafunc.parametrize("input_value", [float(option_value)])
if isinstance(option_value, str):
option_value = eval(option_value)
metafunc.parametrize("input_value", [option_value])
else:
metafunc.parametrize("input_value", [float(option_value)])
21 changes: 14 additions & 7 deletions testing/protocol_conformity_1.0/test_model_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,21 @@ def test_evaluate(model_url, input_value):
inputSizesJSON = requests.post(f'{model_url}/InputSizes', json=input_model_name).json()

inputParams = {"input": [], "name": model_name, "config": {}}
input_value_len = getattr(input_value, '__len__', lambda:1)()
for i in range(0,len(inputSizesJSON["inputSizes"])):
assert input_value_len == 1 or input_value_len == inputSizesJSON["inputSizes"][i]
if input_value_len == 1:
inputParams["input"].append([input_value] * inputSizesJSON["inputSizes"][i])
else:
for i in range(0, len(inputSizesJSON["inputSizes"])):
inputSizesJSON_i = inputSizesJSON["inputSizes"][i]
inputSizesJSON_len = len(inputSizesJSON["inputSizes"])
# Handles the case for one input vector
if hasattr(input_value, '__len__') and inputSizesJSON_len == 1:
assert len(input_value) == inputSizesJSON_i
inputParams["input"].append(input_value)
# The case where there are multiple input vector
elif hasattr(input_value, '__len__') and inputSizesJSON_len != 1:
assert len(input_value[i]) == inputSizesJSON_i
inputParams["input"].append(input_value[i])

# Single number entered, will be expanded if sizes unmatched
else:
inputParams["input"].append([input_value] * inputSizesJSON_i)
assert len(inputParams["input"][i]) == inputSizesJSON_i

resp = requests.post(f'{model_url}/Evaluate', headers={}, data=json.dumps(inputParams,indent=4))

Expand Down

0 comments on commit fec642b

Please sign in to comment.