Skip to content

Commit

Permalink
Conversation tests using yaml (#6457)
Browse files Browse the repository at this point in the history
* Create conversation_tests.yml

* implement conversation tests using the new yml format

* fixed linter issues

* renamed test_conversatiosn to stories

* fixed story reader detection

* fixed remaining tests

* fixed type error

* fixed some smaller style issues

* added documentation

* style improvements

* Update rasa/core/training/story_reader/markdown_story_reader.py

Co-authored-by: Ella Rohm-Ensing <[email protected]>

* adressed review comments (and linter error)

* added changelog item

* fixed failing tests

* added tests

* fixed linting

* fixed classification test

* fixed some more style errors deepsource found

* fixed some more deepsource issues

* fixed some more deepsource issues...

* Autofix issues in 1 files

Resolved issues in the following files via DeepSource Autofix:
1. rasa/cli/utils.py

* added comments for public funcionts

* trying to fix tests

* fixed server tests

* Apply suggestions from code review

Co-authored-by: Alexander Khizov <[email protected]>

* adressed review comments

* renamed files to stay in test stories naming convention

* removed trailing whitespace

* fixed shitty tests

* added default argument

* Update test_multi_project.py

* fixed windows errors

* trying to fix escaping issues

* fixed linter

Co-authored-by: Ella Rohm-Ensing <[email protected]>
Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
Co-authored-by: Alexander Khizov <[email protected]>
  • Loading branch information
4 people authored Aug 27, 2020
1 parent e186b07 commit c78aca8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
10 changes: 9 additions & 1 deletion test_rasa_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import pytest
from _pytest.monkeypatch import MonkeyPatch
from _pytest.pytester import RunResult
from ruamel.yaml.scalarstring import SingleQuotedScalarString

import rasa.core.utils as rasa_core_utils
from rasa.cli import export
Expand Down Expand Up @@ -65,7 +66,14 @@ def test_validate_timestamp_options_with_invalid_timestamps():
def test_get_event_broker_and_tracker_store_from_endpoint_config(tmp_path: Path):
# write valid config to file
endpoints_path = write_endpoint_config_to_yaml(
tmp_path, {"event_broker": {"type": "sql"}, "tracker_store": {"type": "sql"}}
tmp_path,
{
"event_broker": {
"type": "sql",
"db": str(tmp_path / "rasa.db").replace("\\", "\\\\"),
},
"tracker_store": {"type": "sql"},
},
)

available_endpoints = rasa_core_utils.read_endpoints_from_path(endpoints_path)
Expand Down
15 changes: 11 additions & 4 deletions test_rasa_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ def test_test_core_no_plot(run_in_simple_project: Callable[..., RunResult]):


def test_test(run_in_simple_project_with_model: Callable[..., RunResult]):
write_yaml(
{
"pipeline": "KeywordIntentClassifier",
"policies": [{"name": "MemoizationPolicy"}],
},
"config2.yml",
)

run_in_simple_project_with_model("test")

assert os.path.exists("results")
Expand Down Expand Up @@ -61,14 +69,15 @@ def test_test_nlu_cross_validation(run_in_simple_project: Callable[..., RunResul


def test_test_nlu_comparison(run_in_simple_project: Callable[..., RunResult]):
copyfile("config.yml", "config-1.yml")
write_yaml({"pipeline": "KeywordIntentClassifier"}, "config.yml")
write_yaml({"pipeline": "KeywordIntentClassifier"}, "config2.yml")

run_in_simple_project(
"test",
"nlu",
"--config",
"config.yml",
"config-1.yml",
"config2.yml",
"--run",
"2",
"--percentages",
Expand Down Expand Up @@ -123,8 +132,6 @@ def test_test_core_comparison_after_train(
"--percentages",
"25",
"75",
"--augmentation",
"5",
"--out",
"comparison_models",
)
Expand Down
21 changes: 10 additions & 11 deletions test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,30 +72,29 @@ def test_validate_invalid_path():
get_validated_path("test test test", "out", "default")


def test_validate_valid_path():
tempdir = tempfile.mkdtemp()

assert get_validated_path(tempdir, "out", "default") == tempdir
def test_validate_valid_path(tmp_path: pathlib.Path):
assert get_validated_path(str(tmp_path), "out", "default") == str(tmp_path)


def test_validate_if_none_is_valid():
assert get_validated_path(None, "out", "default", True) is None


def test_validate_with_none_if_default_is_valid(caplog: LogCaptureFixture):
tempdir = tempfile.mkdtemp()

def test_validate_with_none_if_default_is_valid(
caplog: LogCaptureFixture, tmp_path: pathlib.Path
):
with caplog.at_level(logging.WARNING, rasa.cli.utils.logger.name):
assert get_validated_path(None, "out", tempdir) == tempdir
assert get_validated_path(None, "out", str(tmp_path)) == str(tmp_path)

assert caplog.records == []


def test_validate_with_invalid_directory_if_default_is_valid():
tempdir = tempfile.mkdtemp()
def test_validate_with_invalid_directory_if_default_is_valid(tmp_path: pathlib.Path):
invalid_directory = "gcfhvjkb"
with pytest.warns(UserWarning) as record:
assert get_validated_path(invalid_directory, "out", tempdir) == tempdir
assert get_validated_path(invalid_directory, "out", str(tmp_path)) == str(
tmp_path
)
assert len(record) == 1
assert "does not seem to exist" in record[0].message.args[0]

Expand Down

0 comments on commit c78aca8

Please sign in to comment.