Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Schemas: unit tests FDS-1061 TestDataModelNodes #1310

Conversation

mialy-defelice
Copy link
Contributor

No description provided.

# Test adding a dummy node
node_dict = {'label': 'test_label'}

path_to_data_model = helpers.get_data_path(data_model)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually probably don't need path_to_data_model here.

path_to_data_model = helpers.get_data_path(data_model)

# Get Graph
graph_data_model = generate_graph_data_model(helpers, data_model_name=path_to_data_model)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just pass data_model here.


assert nodes == expected_nodes

# Ensure order is tested.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am a bit confused here. Here it seems like we are ensuring "Patient" does not become the last item in a list?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an additional maybe unnecessary test to ensure that the order and not just the contents is being tested in the previous test. this is sort of a future proof thing...

reordered_nodes.append('Patient')
assert reordered_nodes != expected_nodes

@pytest.mark.parametrize("data_model", list(DATA_MODEL_DICT.keys()), ids=list(DATA_MODEL_DICT.values()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be re-written like:

@pytest.mark.parametrize("data_model", list(DATA_MODEL_DICT.keys()), ids=list(DATA_MODEL_DICT.values())) class TestDataModelNodes:

assert reordered_nodes != expected_nodes

@pytest.mark.parametrize("data_model", list(DATA_MODEL_DICT.keys()), ids=list(DATA_MODEL_DICT.values()))
def test_gather_all_nodes(self, helpers, data_model):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand what you are trying to do here. I am thinking since gather_all_nodes calls gather_nodes function, will it make sense to mock gather_nodes and then test if gather_all_nodes could return the correct output?

data_model_properties = data_model_nodes.get_data_model_properties(attr_rel_dictionary)

# In the current example model, there are no properties, would need to update this section if properties are added.
assert data_model_properties == []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this is a good point. I created a ticket here to track: https://sagebionetworks.jira.com/jira/software/c/projects/FDS/issues/FDS-1226

# In the example data model all attributes should be classes.
for attr in attr_rel_dictionary.keys():
entry_type = data_model_nodes.get_entry_type(attr)
assert entry_type == 'class'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: after adding an example data dictionaries that have properties, we could change this part of the test

@pytest.mark.parametrize("rel_func", list(REL_FUNC_DICT.values()), ids=list(REL_FUNC_DICT.keys()))
@pytest.mark.parametrize("test_dn", list(TEST_DN_DICT.keys()), ids=list(TEST_DN_DICT.keys()))
@pytest.mark.parametrize("test_bool", ['True', 'False', True, False, 'kldjk'], ids=['True_str', 'False_str', 'True_bool', 'False_bool', 'Random_str'])
def test_run_rel_functions(self, helpers, data_model, rel_func, test_dn, test_bool):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have unit tests for get_attribute_display_name_from_label, parse_validation_rules, get_label_from_display_name, convert_bool_to_str? If so, I think here we could simply mock responses from these four functions and test run_rel_functions.. Currently what you are doing here makes sense. But at the same time, I feel like this test becomes difficult to read because it gathers essentially four tests of four different functions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we do have tests for those, but the trick here is actually making sure the parameters are being passed properly through this function.. which has at times felt a bit chaotic, so its nice to call the functions this way.

@linglp
Copy link
Contributor

linglp commented Oct 17, 2023

@mialy-defelice I left some comments for your reference. I think it general it looks good. Feel free to merge

@mialy-defelice mialy-defelice merged commit 9c65a6c into develop-refactor-schemas Oct 18, 2023
@mialy-defelice mialy-defelice deleted the develop-refactor-schemas-unit-tests-FDS-1061 branch March 8, 2024 23:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants