Skip to content

Commit

Permalink
Merge 353b15e into 9db673f
Browse files Browse the repository at this point in the history
  • Loading branch information
wochinge committed Aug 14, 2019
2 parents 9db673f + 353b15e commit bed9b42
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Expand Up @@ -27,6 +27,7 @@ Changed
into the ``supervised_embeddings`` NLU pipeline template
- bot messages contain the `timestamp` of the `BotUttered` event, which can be used in channels
- NLU evaluations now also stores its output in the output directory like the core evaluation
- show warning in case a default path is used instead of a provided, invalid path

Removed
-------
Expand Down
7 changes: 6 additions & 1 deletion rasa/cli/utils.py
Expand Up @@ -28,12 +28,17 @@ def get_validated_path(
The current value if it was valid, else the default value of the
argument if it is valid, else `None`.
"""

if current is None or current is not None and not os.path.exists(current):
if default is not None and os.path.exists(default):
reason_str = "'{}' not found.".format(current)
if current is None:
reason_str = "Parameter '{}' not set.".format(parameter)
else:
logger.warning(
"'{}' does not exist. Using default value '{}' instead.".format(
current, default
)
)

logger.debug(
"{} Using default location '{}' instead.".format(reason_str, default)
Expand Down
20 changes: 18 additions & 2 deletions tests/cli/test_utils.py
@@ -1,8 +1,11 @@
import logging
import sys
import tempfile

import pytest
from _pytest.logging import LogCaptureFixture

import rasa.cli.utils
from rasa.cli.utils import (
parse_last_positional_argument_as_model_path,
get_validated_path,
Expand Down Expand Up @@ -59,7 +62,20 @@ def test_validate_if_none_is_valid():
assert get_validated_path(None, "out", "default", True) is None


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

assert get_validated_path(None, "out", tempdir) == tempdir
with caplog.at_level(logging.WARNING, rasa.cli.utils.logger.name):
assert get_validated_path(None, "out", tempdir) == tempdir

assert caplog.records == []


def test_validate_with_invalid_directory_if_default_is_valid(caplog: LogCaptureFixture):
tempdir = tempfile.mkdtemp()
invalid_directory = "gcfhvjkb"

with caplog.at_level(logging.WARNING, rasa.cli.utils.logger.name):
assert get_validated_path(invalid_directory, "out", tempdir) == tempdir

assert "'{}' does not exist".format(invalid_directory) in caplog.text

0 comments on commit bed9b42

Please sign in to comment.