Skip to content

Commit

Permalink
Add test to assert against component yaml load
Browse files Browse the repository at this point in the history
  • Loading branch information
kiersten-stokes committed Mar 22, 2022
1 parent 59c980c commit dee8342
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions elyra/tests/pipeline/kfp/test_component_parser_kfp.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

from elyra.metadata.metadata import Metadata
from elyra.pipeline.catalog_connector import CatalogEntry
from elyra.pipeline.catalog_connector import EntryData
from elyra.pipeline.catalog_connector import FilesystemComponentCatalogConnector
from elyra.pipeline.catalog_connector import UrlComponentCatalogConnector
from elyra.pipeline.component_catalog import ComponentCache
Expand Down Expand Up @@ -415,6 +416,56 @@ async def test_parse_components_not_a_file():
assert entry_data is None


async def test_parse_components_invalid_yaml(caplog):
# Get resource path and read definition (by-pass catalog reader functionality)
path = _get_resource_path('kfp_test_invalid_component.yaml')
with open(path, 'r') as f:
definition = f.read()

# Manually construct catalog_entry_data object and catalog instance
catalog_entry_data = {"path": path}
catalog_type = "local-file-catalog"
catalog_instance = ComponentCatalogMetadata(
schema_name=catalog_type,
metadata={
"categories": ['Test'],
"runtime_type": RUNTIME_PROCESSOR.name
}
)

# Build the catalog entry data structures required for parsing
entry_data = EntryData(definition=definition)
catalog_entry = CatalogEntry(entry_data, catalog_entry_data, catalog_instance, ['path'])

# Parse the component entry
parser = KfpComponentParser.create_instance(platform=RUNTIME_PROCESSOR)
component = parser.parse(catalog_entry)

# Failed YAML schema validation returns None
assert component is None

# Assert validation error is captured appropriately in log
assert "Invalid format of YAML definition for component" in caplog.text
assert "Failed validating 'type'" in caplog.text
assert "On instance['inputs'][0]['name']:\n 2" in caplog.text

caplog.clear()

# Modify file to get expected error in YAML safe_load
new_definition = "key with no mapping\n" + definition
catalog_entry.entry_data.definition = new_definition

# Re-parse with new definition content
component = parser.parse(catalog_entry)

# Failed YAML safe_load returns None
assert component is None

# Assert load error is captured appropriately in log
assert "Could not load YAML definition for component" in caplog.text
assert "mapping values are not allowed here" in caplog.text


async def test_parse_components_additional_metatypes():
# Define the appropriate reader for a URL-type component definition
kfp_supported_file_types = [".yaml"]
Expand Down

0 comments on commit dee8342

Please sign in to comment.