Skip to content

Commit

Permalink
Merge pull request #1305 from Sage-Bionetworks/develop-TestDataModelC…
Browse files Browse the repository at this point in the history
…svParser-FDS-1069

Schema Refactor: Tests for Data Model CSV Parser
  • Loading branch information
mialy-defelice authored Oct 18, 2023
2 parents 9c65a6c + 606d9cc commit 283ff95
Showing 1 changed file with 51 additions and 7 deletions.
58 changes: 51 additions & 7 deletions tests/test_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
ogger = logging.getLogger(__name__)

DATA_MODEL_DICT = {
'example.model.csv': "CSV",
Expand Down Expand Up @@ -92,6 +91,10 @@ def DME(helpers, data_model_name='example.model.csv'):
DME = DataModelGraphExplorer(graph_data_model)
yield DME

@pytest.fixture(name='dmcsvp')
def fixture_dm_csv_parser():
yield DataModelCSVParser()

@pytest.fixture(name='relationships')
def get_relationships(helpers):
DMR = DataModelRelationships()
Expand Down Expand Up @@ -148,12 +151,53 @@ def test_parse_model(self, helpers, data_model):
assert 'Attribute' in model_dict[attribute_key]['Relationships']

class TestDataModelCsvParser:
def test_check_schema_definition(self):
return
def test_gather_csv_attributes_relationships(self):
return
def test_parse_csv_model(self ):
return
@pytest.mark.parametrize("data_model", ['example.model.csv'], ids=["csv"])
def test_check_schema_definition(self, helpers, data_model, dmcsvp:DataModelCSVParser):
"""If the csv schema contains the required headers, then this function should not return anything. Check that this is so.
"""
path_to_data_model = helpers.get_data_path(path=data_model)
model_df = load_df(path_to_data_model, data_model=True)
assert None == (dmcsvp.check_schema_definition(model_df = model_df))

@pytest.mark.parametrize("data_model", ['example.model.csv'], ids=["csv"])
def test_gather_csv_attributes_relationships(self, helpers, data_model, dmcsvp:DataModelCSVParser):
"""The output of the function is a attributes relationship dictionary, check that it is formatted properly.
"""
path_to_data_model = helpers.get_data_path(path=data_model)
model_df = load_df(path_to_data_model, data_model=True)

# Get output of the function:
attr_rel_dict = dmcsvp.gather_csv_attributes_relationships(model_df=model_df)

# Test the attr_rel_dict is formatted as expected:
# Get a key in the model
attribute_key = list(attr_rel_dict.keys())[0]

# Check that the structure of the model dictionary conforms to expectations.
assert True == (type(attr_rel_dict) == dict)
assert True == (attribute_key in attr_rel_dict.keys())
assert True == ('Relationships' in attr_rel_dict[attribute_key])
assert True == ('Attribute' in attr_rel_dict[attribute_key]['Relationships'])

@pytest.mark.parametrize("data_model", ['example.model.csv'], ids=["csv"])
def test_parse_csv_model(self, helpers, data_model, dmcsvp:DataModelCSVParser):
"""The output of the function is a attributes relationship dictionary, check that it is formatted properly.
"""
path_to_data_model = helpers.get_data_path(path=data_model)
model_df = load_df(path_to_data_model, data_model=True)

# Get output of the function:
model_dict = dmcsvp.parse_csv_model(path_to_data_model=path_to_data_model)

# Test the model_dict is formatted as expected:
# Get a key in the model
attribute_key = list(model_dict.keys())[0]

# Check that the structure of the model dictionary conforms to expectations.
assert True == (type(model_dict) == dict)
assert True == (attribute_key in model_dict.keys())
assert True == ('Relationships' in model_dict[attribute_key])
assert True == ('Attribute' in model_dict[attribute_key]['Relationships'])

class TestDataModelJsonLdParser:
@pytest.mark.parametrize("data_model", ['example.model.jsonld'], ids=["jsonld"])
Expand Down

0 comments on commit 283ff95

Please sign in to comment.