Skip to content

Commit 12e118c

Browse files
committed
add test
1 parent d622b53 commit 12e118c

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

tests/unit/synapseclient/extensions/unit_test_create_json_schema.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,48 @@ def test_invalid_regex_columntype_traversalnode(
456456
)
457457

458458

459+
def test_invalid_regex_traversalnode(
460+
helpers,
461+
) -> None:
462+
"""
463+
Tests for TraversalNode class initialization.
464+
465+
Verifies that when TransversalNode objects are initialized with a patter specified and an incompatible column type, a ValueError is raised.
466+
"""
467+
node = "Check Regex Single"
468+
469+
path_to_data_model = helpers.get_schema_file_path("data_models/example.model.csv")
470+
471+
fullpath = helpers.get_schema_file_path(path_to_data_model)
472+
473+
# Instantiate DataModelParser
474+
data_model_parser = DataModelParser(path_to_data_model=fullpath, logger=Mock())
475+
476+
# Parse Model
477+
parsed_data_model = data_model_parser.parse_model()
478+
479+
# Change column type to imcompatible type
480+
parsed_data_model[node]["Relationships"]["Pattern"] = "\\u"
481+
482+
# Instantiate DataModelGraph
483+
data_model_grapher = DataModelGraph(
484+
parsed_data_model, data_model_labels="class_label", logger=Mock()
485+
)
486+
487+
# Generate graph
488+
graph_data_model = data_model_grapher.graph
489+
490+
# Instantiate DataModelGraphExplorer
491+
dmge = DataModelGraphExplorer(graph_data_model, logger=Mock())
492+
493+
# A value error should be raised when using pattern specification with non-string column type
494+
error_message = "Column type must be set to 'string' to use column pattern specification for regex validation."
495+
with pytest.raises(SyntaxError, match="The regex pattern.*is invalid"):
496+
node = TraversalNode(
497+
node.replace(" ", ""), "JSONSchemaComponent", dmge, logger=Mock()
498+
)
499+
500+
459501
@pytest.mark.parametrize(
460502
"node_name, expected_node_type, expected_max, expected_min",
461503
[

0 commit comments

Comments
 (0)