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

Raise a helpful error when a datatype cannot be found in a schema #1286

Merged
merged 10 commits into from
Sep 21, 2023
13 changes: 12 additions & 1 deletion schematic/manifest/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,19 @@ def __init__(

# Determine whether current data type is file-based
is_file_based = False
if self.root:

if self.root:
GiaJordan marked this conversation as resolved.
Show resolved Hide resolved
# Check if the class is in the schema
root_in_schema = self.sg.se.is_class_in_schema(self.root)

# If the class could not be found, give a notification
if not root_in_schema:
exception_message = f"The DataType entered ({self.root}) could not be found in the data model schema. " + \
"Please confirm that the datatype is in the data model and that the spelling matches the class label in the .jsonld file."
raise LookupError(exception_message)

is_file_based = "Filename" in self.sg.get_node_dependencies(self.root)

self.is_file_based = is_file_based

def _attribute_to_letter(self, attribute, manifest_fields):
Expand Down
22 changes: 19 additions & 3 deletions tests/test_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,24 @@ def test_init(self, helpers):
assert generator.root is None
assert type(generator.sg) is SchemaGenerator

def test_missing_root_error(self, helpers):
"""
The ManifestGenerator should raise a LookupError during initialization if a data_type is passed in that can't be found in the schema.
"""
# Choose a data type that is not in the schema
data_type = "MissingComponent"

# A LookupError should be raised and include message when the component cannot be found
with pytest.raises(LookupError) as e:
generator = ManifestGenerator(
path_to_json_ld=helpers.get_data_path("example.model.jsonld"),
root=data_type,
use_annotations=False,
)

# Check message contents
assert f"({data_type}) could not be found in the data model schema" in str(e)

@pytest.mark.google_credentials_needed
def test_get_manifest_first_time(self, manifest):

Expand Down Expand Up @@ -145,7 +163,7 @@ def test_get_manifest_first_time(self, manifest):
# An annotation merged with an attribute from the data model
if use_annotations:
assert output["File Format"].tolist() == ["txt", "csv", "fastq"]

@pytest.mark.parametrize("output_format", [None, "dataframe", "excel", "google_sheet"])
@pytest.mark.parametrize("sheet_url", [None, True, False])
@pytest.mark.parametrize("dataset_id", [None, "syn27600056"])
Expand Down Expand Up @@ -381,5 +399,3 @@ def test_populate_existing_excel_spreadsheet(self, simple_manifest_generator, si
# remove file
os.remove(dummy_output_path)



Loading