dc6079821b
CI Github Actions / Run Tests (push) Waiting to run
Automatic PR Merger / mergepal (push) Waiting to run
Semgrep / Semgrep Workflow Security Scan (push) Waiting to run
Docs Tests / Check for file changes (push) Has been cancelled
Docs Tests / Test Documentation (push) Has been cancelled
Docs Tests / Documentation Linting Checks (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.10, test-performance) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.10, test-policies) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.8, test-cli) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.8, test-core-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.8, test-full-model-training) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.8, test-nlu-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.8, test-nlu-predictors) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.8, test-other-unit-tests) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.8, test-performance) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.8, test-policies) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.9, test-cli) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.9, test-core-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.9, test-full-model-training) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.9, test-nlu-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.9, test-nlu-predictors) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.9, test-other-unit-tests) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.9, test-performance) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.9, test-policies) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.10, test-cli) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.10, test-core-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.10, test-full-model-training) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.10, test-nlu-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.10, test-nlu-predictors) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.10, test-other-unit-tests) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.10, test-performance) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.10, test-policies) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.8, test-cli) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.8, test-core-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.8, test-full-model-training) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.8, test-nlu-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.8, test-nlu-predictors) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.8, test-other-unit-tests) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.8, test-performance) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.8, test-policies) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.9, test-cli) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.9, test-core-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.9, test-full-model-training) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.9, test-nlu-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.9, test-nlu-predictors) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.9, test-other-unit-tests) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.9, test-performance) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.9, test-policies) (push) Has been cancelled
Continuous Integration / Run Flaky Tests (ubuntu-24.04, 3.10) (push) Has been cancelled
Continuous Integration / Run Flaky Tests (ubuntu-24.04, 3.8) (push) Has been cancelled
Continuous Integration / Run Flaky Tests (ubuntu-24.04, 3.9) (push) Has been cancelled
Continuous Integration / Run Flaky Tests (windows-2022, 3.10) (push) Has been cancelled
Continuous Integration / Run Flaky Tests (windows-2022, 3.8) (push) Has been cancelled
Continuous Integration / Run Flaky Tests (windows-2022, 3.9) (push) Has been cancelled
Continuous Integration / Check for file changes (push) Has been cancelled
Continuous Integration / Wait for docs tests (push) Has been cancelled
Continuous Integration / Code Quality (push) Has been cancelled
Continuous Integration / Check for changelog (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.10, test-cli) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.10, test-core-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.10, test-full-model-training) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.10, test-nlu-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.10, test-nlu-predictors) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.10, test-other-unit-tests) (push) Has been cancelled
Continuous Integration / Upload coverage reports to codeclimate (push) Has been cancelled
Continuous Integration / Run Non-Sequential Integration Tests (push) Has been cancelled
Continuous Integration / Run Broker Integration Tests (push) Has been cancelled
Continuous Integration / Run Sequential Integration Tests (push) Has been cancelled
Continuous Integration / Build Docker base images and setup environment (push) Has been cancelled
Continuous Integration / Build Docker (default) (push) Has been cancelled
Continuous Integration / Build Docker (full) (push) Has been cancelled
Continuous Integration / Build Docker (mitie-en) (push) Has been cancelled
Continuous Integration / Build Docker (spacy-de) (push) Has been cancelled
Continuous Integration / Build Docker (spacy-en) (push) Has been cancelled
Continuous Integration / Build Docker (spacy-it) (push) Has been cancelled
Continuous Integration / Deploy to PyPI (push) Has been cancelled
Continuous Integration / Notify Slack & Publish Release Notes (push) Has been cancelled
Publish Documentation / Evaluate release tag (push) Has been cancelled
Publish Documentation / Prebuild Docs (push) Has been cancelled
Publish Documentation / Preview Docs (push) Has been cancelled
Publish Documentation / Check for file changes (push) Has been cancelled
Publish Documentation / Publish Docs (push) Has been cancelled
117 lines
3.7 KiB
Python
117 lines
3.7 KiB
Python
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
from typing import Dict, Text
|
|
|
|
import pytest
|
|
|
|
from rasa.engine.storage.resource import Resource
|
|
import rasa.shared.utils.io
|
|
from rasa.engine.exceptions import GraphSchemaException
|
|
from rasa.engine.graph import SchemaNode, GraphSchema
|
|
from tests.engine.graph_components_test_classes import PersistableTestComponent
|
|
|
|
|
|
def test_serialize_graph_schema(tmp_path: Path):
|
|
graph_schema = GraphSchema(
|
|
{
|
|
"train": SchemaNode(
|
|
needs={},
|
|
uses=PersistableTestComponent,
|
|
fn="train",
|
|
constructor_name="create",
|
|
config={"some_config": 123455, "some more config": [{"nested": "hi"}]},
|
|
),
|
|
"load": SchemaNode(
|
|
needs={"resource": "train"},
|
|
uses=PersistableTestComponent,
|
|
fn="run_inference",
|
|
constructor_name="load",
|
|
config={},
|
|
is_target=True,
|
|
resource=Resource("test resource"),
|
|
),
|
|
}
|
|
)
|
|
|
|
serialized = graph_schema.as_dict()
|
|
|
|
# Dump it to make sure it's actually serializable
|
|
file_path = tmp_path / "my_graph.yml"
|
|
rasa.shared.utils.io.write_yaml(serialized, file_path)
|
|
|
|
serialized_graph_schema_from_file = rasa.shared.utils.io.read_yaml_file(file_path)
|
|
graph_schema_from_file = GraphSchema.from_dict(serialized_graph_schema_from_file)
|
|
|
|
assert graph_schema_from_file == graph_schema
|
|
|
|
|
|
def test_invalid_module_error_when_deserializing_schemas(tmp_path: Path):
|
|
graph_schema = GraphSchema(
|
|
{
|
|
"train": SchemaNode(
|
|
needs={},
|
|
uses=PersistableTestComponent,
|
|
fn="train",
|
|
constructor_name="create",
|
|
config={"some_config": 123455, "some more config": [{"nested": "hi"}]},
|
|
)
|
|
}
|
|
)
|
|
|
|
serialized = graph_schema.as_dict()
|
|
|
|
# Pretend module is for some reason invalid
|
|
serialized["nodes"]["train"]["uses"] = "invalid.class"
|
|
|
|
# Dump it to make sure it's actually serializable
|
|
file_path = tmp_path / "my_graph.yml"
|
|
rasa.shared.utils.io.write_yaml(serialized, file_path)
|
|
|
|
serialized_graph_schema_from_file = rasa.shared.utils.io.read_yaml_file(file_path)
|
|
|
|
with pytest.raises(GraphSchemaException):
|
|
_ = GraphSchema.from_dict(serialized_graph_schema_from_file)
|
|
|
|
|
|
def test_minimal_graph_schema():
|
|
def test_schema_node(needs: Dict[Text, Text], target: bool = False) -> SchemaNode:
|
|
return SchemaNode(
|
|
needs=needs,
|
|
uses=None,
|
|
fn="",
|
|
constructor_name="",
|
|
config={},
|
|
is_target=target,
|
|
)
|
|
|
|
test_schema = GraphSchema(
|
|
{
|
|
"1": test_schema_node({"i": "3"}, True),
|
|
"2": test_schema_node({"i": "3"}),
|
|
"3": test_schema_node({"i": "4"}),
|
|
"4": test_schema_node({}),
|
|
"5": test_schema_node({"i": "6"}),
|
|
"6": test_schema_node({}),
|
|
"7": test_schema_node({}),
|
|
"8": test_schema_node({"i": "9"}, True),
|
|
"9": test_schema_node({"i": "__input__"}),
|
|
}
|
|
)
|
|
assert test_schema.minimal_graph_schema() == GraphSchema(
|
|
{
|
|
"1": test_schema_node({"i": "3"}, True),
|
|
"3": test_schema_node({"i": "4"}),
|
|
"4": test_schema_node({}),
|
|
"8": test_schema_node({"i": "9"}, True),
|
|
"9": test_schema_node({"i": "__input__"}),
|
|
}
|
|
)
|
|
|
|
assert test_schema.minimal_graph_schema(targets=["8"]) == GraphSchema(
|
|
{
|
|
"8": test_schema_node({"i": "9"}, True),
|
|
"9": test_schema_node({"i": "__input__"}),
|
|
}
|
|
)
|