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
136 lines
4.1 KiB
Python
136 lines
4.1 KiB
Python
import pytest
|
|
from _pytest.tmpdir import TempPathFactory
|
|
from prompt_toolkit.document import Document
|
|
from prompt_toolkit.validation import ValidationError
|
|
|
|
import rasa.shared.utils.io
|
|
import rasa.utils.io as io_utils
|
|
|
|
|
|
@pytest.mark.parametrize("actual_path", ["", "file.json", "file"])
|
|
def test_file_path_validator_with_invalid_paths(actual_path):
|
|
test_error_message = actual_path
|
|
|
|
validator = io_utils.file_type_validator([".yml"], test_error_message)
|
|
|
|
document = Document(actual_path)
|
|
with pytest.raises(ValidationError) as e:
|
|
validator.validate(document)
|
|
|
|
assert e.value.message == test_error_message
|
|
|
|
|
|
@pytest.mark.parametrize("actual_path", ["domain.yml", "lala.yaml"])
|
|
def test_file_path_validator_with_valid_paths(actual_path):
|
|
validator = io_utils.file_type_validator([".yml", ".yaml"], "error message")
|
|
|
|
document = Document(actual_path)
|
|
# If the path is valid there shouldn't be an exception
|
|
assert validator.validate(document) is None
|
|
|
|
|
|
@pytest.mark.parametrize("user_input", ["", " ", "\t", "\n"])
|
|
def test_non_empty_text_validator_with_empty_input(user_input):
|
|
test_error_message = "enter something"
|
|
|
|
validator = io_utils.not_empty_validator(test_error_message)
|
|
|
|
document = Document(user_input)
|
|
with pytest.raises(ValidationError) as e:
|
|
validator.validate(document)
|
|
|
|
assert e.value.message == test_error_message
|
|
|
|
|
|
@pytest.mark.parametrize("user_input", ["utter_greet", "greet", "Hi there!"])
|
|
def test_non_empty_text_validator_with_valid_input(user_input):
|
|
validator = io_utils.not_empty_validator("error message")
|
|
|
|
document = Document(user_input)
|
|
# If there is input there shouldn't be an exception
|
|
assert validator.validate(document) is None
|
|
|
|
|
|
def test_create_validator_from_callable():
|
|
def is_valid(user_input) -> None:
|
|
return user_input == "this passes"
|
|
|
|
error_message = "try again"
|
|
|
|
validator = io_utils.create_validator(is_valid, error_message)
|
|
|
|
document = Document("this passes")
|
|
assert validator.validate(document) is None
|
|
|
|
document = Document("this doesn't")
|
|
with pytest.raises(ValidationError) as e:
|
|
validator.validate(document)
|
|
|
|
assert e.value.message == error_message
|
|
|
|
|
|
def test_empty_directories_are_equal(tmp_path_factory: TempPathFactory):
|
|
dir1 = tmp_path_factory.mktemp("dir1")
|
|
dir2 = tmp_path_factory.mktemp("dir2")
|
|
|
|
assert rasa.utils.io.are_directories_equal(dir1, dir2)
|
|
|
|
|
|
def test_directories_are_equal(tmp_path_factory: TempPathFactory):
|
|
dir1 = tmp_path_factory.mktemp("dir1")
|
|
(dir1 / "file.txt").write_text("Hello!")
|
|
|
|
dir2 = tmp_path_factory.mktemp("dir2")
|
|
(dir2 / "file.txt").write_text("Hello!")
|
|
|
|
assert rasa.utils.io.are_directories_equal(dir1, dir2)
|
|
|
|
|
|
def test_directories_are_equal_sub_dir(tmp_path_factory: TempPathFactory):
|
|
dir1 = tmp_path_factory.mktemp("dir1")
|
|
(dir1 / "dir").mkdir()
|
|
(dir1 / "dir" / "file.txt").write_text("Hello!")
|
|
|
|
dir2 = tmp_path_factory.mktemp("dir2")
|
|
(dir2 / "dir").mkdir()
|
|
(dir2 / "dir" / "file.txt").write_text("Hello!")
|
|
|
|
assert rasa.utils.io.are_directories_equal(dir1, dir2)
|
|
|
|
|
|
def test_directories_are_equal_different_file_content(
|
|
tmp_path_factory: TempPathFactory,
|
|
):
|
|
dir1 = tmp_path_factory.mktemp("dir1")
|
|
(dir1 / "file.txt").write_text("Hello!")
|
|
|
|
dir2 = tmp_path_factory.mktemp("dir2")
|
|
(dir2 / "file.txt").write_text("Bye!")
|
|
|
|
assert not rasa.utils.io.are_directories_equal(dir1, dir2)
|
|
|
|
|
|
def test_directories_are_equal_extra_file(tmp_path_factory: TempPathFactory):
|
|
dir1 = tmp_path_factory.mktemp("dir1")
|
|
(dir1 / "file.txt").write_text("Hello!")
|
|
|
|
dir2 = tmp_path_factory.mktemp("dir2")
|
|
(dir2 / "file.txt").write_text("Hello!")
|
|
(dir2 / "file2.txt").touch()
|
|
|
|
assert not rasa.utils.io.are_directories_equal(dir1, dir2)
|
|
|
|
|
|
def test_directories_are_equal_different_file_content_sub_dir(
|
|
tmp_path_factory: TempPathFactory,
|
|
):
|
|
dir1 = tmp_path_factory.mktemp("dir1")
|
|
(dir1 / "dir").mkdir()
|
|
(dir1 / "dir" / "file.txt").write_text("Hello!")
|
|
|
|
dir2 = tmp_path_factory.mktemp("dir2")
|
|
(dir2 / "dir").mkdir()
|
|
(dir2 / "dir" / "file.txt").write_text("Bye!")
|
|
|
|
assert not rasa.utils.io.are_directories_equal(dir1, dir2)
|