示例#1
0
def load(filename=None, **kwargs):
    if filename is None and os.path.isfile(DEFAULT_CONFIG_LOCATION):
        filename = DEFAULT_CONFIG_LOCATION

    if filename is not None:
        try:
            file_config = utils.read_yaml_file(filename)
        except yaml.parser.ParserError as e:
            raise InvalidConfigError("Failed to read configuration file "
                                     "'{}'. Error: {}".format(filename, e))

        if kwargs:
            file_config.update(kwargs)
        return RasaNLUModelConfig(file_config)
    else:
        return RasaNLUModelConfig(kwargs)
示例#2
0
def load(filename=None, **kwargs):
    if filename is None and os.path.isfile(DEFAULT_CONFIG_LOCATION):
        filename = DEFAULT_CONFIG_LOCATION

    if filename is not None:
        try:
            file_config = utils.read_yaml_file(filename)
        except yaml.parser.ParserError as e:
            raise InvalidConfigError("Failed to read configuration file "
                                     "'{}'. Error: {}".format(filename, e))

        if kwargs:
            file_config.update(kwargs)
        return RasaNLUModelConfig(file_config)
    else:
        return RasaNLUModelConfig(kwargs)
import tempfile

import pytest

from rasa_nlu import config, utils
from rasa_nlu.registry import registered_pipeline_templates
from rasa_nlu.components import ComponentBuilder
from tests.conftest import CONFIG_DEFAULTS_PATH
from tests.utilities import write_file_config

defaults = utils.read_yaml_file(CONFIG_DEFAULTS_PATH)


def test_default_config(default_config):
    assert default_config.as_dict() == defaults


def test_blank_config():
    file_config = {}
    f = write_file_config(file_config)
    final_config = config.load(f.name)
    assert final_config.as_dict() == defaults


def test_invalid_config_json():
    file_config = """pipeline: [spacy_sklearn"""  # invalid yaml
    with tempfile.NamedTemporaryFile("w+",
                                     suffix="_tmp_config_file.json") as f:
        f.write(file_config)
        f.flush()
        with pytest.raises(config.InvalidConfigError):
示例#4
0
import tempfile

import pytest

from rasa_nlu import config, utils
from rasa_nlu.registry import registered_pipeline_templates
from rasa_nlu.components import ComponentBuilder
from tests.conftest import CONFIG_DEFAULTS_PATH
from tests.utilities import write_file_config

defaults = utils.read_yaml_file(CONFIG_DEFAULTS_PATH)


def test_default_config(default_config):
    assert default_config.as_dict() == defaults


def test_blank_config():
    file_config = {}
    f = write_file_config(file_config)
    final_config = config.load(f.name)
    assert final_config.as_dict() == defaults


def test_invalid_config_json():
    file_config = """pipeline: [spacy_sklearn"""  # invalid yaml
    with tempfile.NamedTemporaryFile("w+",
                                     suffix="_tmp_config_file.json") as f:
        f.write(file_config)
        f.flush()
        with pytest.raises(config.InvalidConfigError):