def test_create_default(predictor_evaluation_workflow_dict: dict, workflow: PredictorEvaluationWorkflow): session = FakeSession() session.set_response(predictor_evaluation_workflow_dict) collection = PredictorEvaluationWorkflowCollection(project_id=uuid.uuid4(), session=session) default_workflow = collection.create_default(uuid.uuid4()) assert default_workflow.dump() == workflow.dump()
def test_create_default(valid_product_design_space_data, valid_product_design_space): # The instance field isn't renamed to config in objects returned from this route # This renames the config key to instance to match the data we get from the API data_with_instance = deepcopy(valid_product_design_space_data) data_with_instance['instance'] = data_with_instance.pop('config') session = FakeSession() session.set_response(data_with_instance) collection = DesignSpaceCollection(project_id=uuid.uuid4(), session=session) default_design_space = collection.create_default(uuid.uuid4()) assert default_design_space.dump() == valid_product_design_space.dump()
def test_check_update_none(): """Test that check-for-updates makes the expected calls, parses output for no update.""" # Given session = FakeSession() session.set_response({"updatable": False}) pc = PredictorCollection(uuid.uuid4(), session) predictor_id = uuid.uuid4() # when update_check = pc.check_for_update(predictor_id) # then assert update_check is None expected_call = FakeCall(method='GET', path='/projects/{}/predictors/{}/check-for-update'.format(pc.project_id, predictor_id)) assert session.calls[0] == expected_call
def test_from_predictor_responses(): session = FakeSession() col = 'smiles' response_json = { 'responses': [ # shortened sample response { 'category': 'Real', 'descriptor_key': 'khs.sNH3 KierHallSmarts for {}'.format(col), 'units': '', 'lower_bound': 0, 'upper_bound': 1000000000 }, { 'category': 'Real', 'descriptor_key': 'khs.dsN KierHallSmarts for {}'.format(col), 'units': '', 'lower_bound': 0, 'upper_bound': 1000000000 }, ] } session.set_response(response_json) descriptors = DescriptorMethods(uuid4(), session) featurizer = MolecularStructureFeaturizer( name="Molecule featurizer", description="description", descriptor=MolecularStructureDescriptor(col), features=["all"], excludes=["standard"]) results = descriptors.from_predictor_responses( featurizer, [MolecularStructureDescriptor(col)]) assert results == [ RealDescriptor( key=r['descriptor_key'], lower_bound=r['lower_bound'], upper_bound=r['upper_bound'], ) for r in response_json['responses'] ] assert session.last_call.path == '/projects/{}/material-descriptors/predictor-responses'\ .format(descriptors.project_id) assert session.last_call.method == 'POST'
def test_returned_predictor(valid_graph_predictor_data): """Check that auto_configure works on the happy path.""" # Given session = FakeSession() # Setup a response that includes instance instead of config response = deepcopy(valid_graph_predictor_data) response["instance"] = response["config"] del response["config"] session.set_response(response) pc = PredictorCollection(uuid.uuid4(), session) # When result = pc.auto_configure(GemTableDataSource(uuid.uuid4(), 0), "PLAIN") # Then the response is parsed in a predictor assert result.name == valid_graph_predictor_data["display_name"] assert isinstance(result, GraphPredictor) # including nested predictors assert len(result.predictors) == 2 assert isinstance(result.predictors[0], uuid.UUID) assert isinstance(result.predictors[1], DeprecatedExpressionPredictor)
def test_descriptors_from_data_source(): session = FakeSession() col = 'smiles' response_json = { 'descriptors': [ # shortened sample response { 'category': 'Real', 'descriptor_key': 'khs.sNH3 KierHallSmarts for {}'.format(col), 'units': '', 'lower_bound': 0, 'upper_bound': 1000000000 }, { 'category': 'Real', 'descriptor_key': 'khs.dsN KierHallSmarts for {}'.format(col), 'units': '', 'lower_bound': 0, 'upper_bound': 1000000000 }, ] } session.set_response(response_json) descriptors = DescriptorMethods(uuid4(), session) data_source = GemTableDataSource('43357a66-3644-4959-8115-77b2630aca45', 123) results = descriptors.descriptors_from_data_source(data_source) assert results == [ RealDescriptor(key=r['descriptor_key'], lower_bound=r['lower_bound'], upper_bound=r['upper_bound'], units=r['units']) for r in response_json['descriptors'] ] assert session.last_call.path == '/projects/{}/material-descriptors/from-data-source'\ .format(descriptors.project_id) assert session.last_call.method == 'POST'
def test_check_update_some(): """Test the update check correctly builds a module.""" # given session = FakeSession() desc = RealDescriptor("spam", 0, 1, "kg") response = { "type": "AnalyticExpression", "name": "foo", "description": "bar", "expression": "2 * x", "output": RealDescriptor("spam", 0, 1, "kg").dump(), "aliases": {} } session.set_response({"updatable": True, "update": response}) pc = PredictorCollection(uuid.uuid4(), session) predictor_id = uuid.uuid4() # when update_check = pc.check_for_update(predictor_id) # then expected = ExpressionPredictor("foo", "bar", "2 * x", desc, {}) assert update_check.dump() == expected.dump() assert update_check.uid == predictor_id