Files
wehub-resource-sync 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
chore: import upstream snapshot with attribution
2026-07-13 13:24:47 +08:00

175 lines
5.8 KiB
Python

import os
import tempfile
from pathlib import Path
import pytest
import rasa.shared
import rasa.shared.data
from rasa.shared.nlu.training_data.loading import load_data
from rasa.shared.utils.io import write_text_file, json_to_string
from rasa.shared.core.training_data.story_reader.yaml_story_reader import (
YAMLStoryReader,
)
@pytest.mark.parametrize(
"path,is_yaml",
[
("my_file.yaml", True),
("my_file.yml", True),
("/a/b/c/my_file.yml", True),
("/a/b/c/my_file.ml", False),
("my_file.json", False),
],
)
def test_is_yaml_file(path, is_yaml):
assert rasa.shared.data.is_likely_yaml_file(path) == is_yaml
@pytest.mark.parametrize(
"path,is_json",
[
("my_file.json", True),
("/a/b/c/my_file.json", True),
("/a/b/c/my_file.yml", False),
],
)
def test_is_json_file(path, is_json):
assert rasa.shared.data.is_likely_json_file(path) == is_json
def test_get_core_directory(project):
data_dir = os.path.join(project, "data")
core_directory = rasa.shared.data.get_core_directory([data_dir])
core_files = os.listdir(core_directory)
assert len(core_files) == 2
assert any(file.endswith("stories.yml") for file in core_files)
assert any(file.endswith("rules.yml") for file in core_files)
def test_get_nlu_directory(project):
data_dir = os.path.join(project, "data")
nlu_directory = rasa.shared.data.get_nlu_directory([data_dir])
nlu_files = os.listdir(nlu_directory)
assert len(nlu_files) == 1
assert nlu_files[0].endswith("nlu.yml")
def test_get_nlu_file(project):
data_file = os.path.join(project, "data/nlu.yml")
nlu_directory = rasa.shared.data.get_nlu_directory(data_file)
nlu_files = os.listdir(nlu_directory)
original = load_data(data_file)
copied = load_data(nlu_directory)
assert nlu_files[0].endswith("nlu.yml")
assert original.intent_examples == copied.intent_examples
def test_get_core_nlu_files(project):
data_dir = os.path.join(project, "data")
nlu_files = rasa.shared.data.get_data_files(
[data_dir], rasa.shared.data.is_nlu_file
)
core_files = rasa.shared.data.get_data_files(
[data_dir], YAMLStoryReader.is_stories_file
)
assert len(nlu_files) == 1
assert list(nlu_files)[0].endswith("nlu.yml")
assert len(core_files) == 2
assert any(file.endswith("stories.yml") for file in core_files)
assert any(file.endswith("rules.yml") for file in core_files)
@pytest.mark.parametrize(
"test_input,expected",
[
(
"dialogflow",
[
"data/examples/dialogflow/agent.json",
"data/examples/dialogflow/entities/cuisine.json",
"data/examples/dialogflow/entities/cuisine_entries_en.json",
"data/examples/dialogflow/entities/cuisine_entries_es.json",
"data/examples/dialogflow/entities/flightNumber.json",
"data/examples/dialogflow/entities/flightNumber_entries_en.json",
"data/examples/dialogflow/entities/location.json",
"data/examples/dialogflow/entities/location_entries_en.json",
"data/examples/dialogflow/entities/location_entries_es.json",
"data/examples/dialogflow/intents/Default Fallback Intent.json",
"data/examples/dialogflow/intents/affirm.json",
"data/examples/dialogflow/intents/affirm_usersays_en.json",
"data/examples/dialogflow/intents/affirm_usersays_es.json",
"data/examples/dialogflow/intents/goodbye.json",
"data/examples/dialogflow/intents/goodbye_usersays_en.json",
"data/examples/dialogflow/intents/goodbye_usersays_es.json",
"data/examples/dialogflow/intents/hi.json",
"data/examples/dialogflow/intents/hi_usersays_en.json",
"data/examples/dialogflow/intents/hi_usersays_es.json",
"data/examples/dialogflow/intents/inform.json",
"data/examples/dialogflow/intents/inform_usersays_en.json",
"data/examples/dialogflow/intents/inform_usersays_es.json",
"data/examples/dialogflow/package.json",
],
),
("luis", ["data/examples/luis/demo-restaurants_v7.json"]),
(
"rasa",
[
"data/examples/rasa/demo-rasa-multi-intent.yml",
"data/examples/rasa/demo-rasa-responses.yml",
"data/examples/rasa/demo-rasa.json",
"data/examples/rasa/demo-rasa.yml",
],
),
("wit", ["data/examples/wit/demo-flights.json"]),
],
)
def test_find_nlu_files_with_different_formats(test_input, expected):
examples_dir = "data/examples"
data_dir = os.path.join(examples_dir, test_input)
nlu_files = rasa.shared.data.get_data_files(
[data_dir], rasa.shared.data.is_nlu_file
)
assert [Path(f) for f in nlu_files] == [Path(f) for f in expected]
def test_is_nlu_file_with_json():
test = {
"rasa_nlu_data": {
"lookup_tables": [
{"name": "plates", "elements": ["beans", "rice", "tacos", "cheese"]}
]
}
}
directory = tempfile.mkdtemp()
file = os.path.join(directory, "test.json")
write_text_file(json_to_string(test), file)
assert rasa.shared.data.is_nlu_file(file)
def test_is_not_nlu_file_with_json():
directory = tempfile.mkdtemp()
file = os.path.join(directory, "test.json")
write_text_file('{"test": "a"}', file)
assert not rasa.shared.data.is_nlu_file(file)
def test_get_story_file_with_yaml():
examples_dir = "data/test_yaml_stories"
core_files = rasa.shared.data.get_data_files(
[examples_dir], YAMLStoryReader.is_stories_file
)
assert core_files