示例#1
0
def test_environment_variable_dict_with_prefix_and_with_postfix():
    os.environ['variable'] = 'test'
    content = "model: \n  test: dir/${variable}/dir"

    result = utils.read_yaml(content)

    assert result['model']['test'] == 'dir/test/dir'
示例#2
0
def test_environment_variable_in_list():
    os.environ['variable'] = 'test'
    content = "model: \n  - value\n  - ${variable}"

    result = utils.read_yaml(content)

    assert result['model'][1] == 'test'
示例#3
0
def test_read_emojis_from_json():
    import json
    from rasa.nlu.utils import read_yaml
    d = {"text": "hey 😁💯 👩🏿‍💻👨🏿‍💻🧜‍♂️(?u)\\b\\w+\\b} f\u00fcr"}
    json_string = json.dumps(d, indent=2)

    s = read_yaml(json_string)

    expected = "hey 😁💯 👩🏿‍💻👨🏿‍💻🧜‍♂️(?u)\\b\\w+\\b} für"
    assert s.get('text') == expected
示例#4
0
def test_emojis_in_yaml():
    test_data = """
    data:
        - one 😁💯 👩🏿‍💻👨🏿‍💻
        - two £ (?u)\\b\\w+\\b f\u00fcr
    """
    actual = utils.read_yaml(test_data)

    assert actual["data"][0] == "one 😁💯 👩🏿‍💻👨🏿‍💻"
    assert actual["data"][1] == "two £ (?u)\\b\\w+\\b für"
示例#5
0
def test_bool_str():
    test_data = """
    one: "yes"
    two: "true"
    three: "True"
    """

    actual = utils.read_yaml(test_data)

    assert actual["one"] == "yes"
    assert actual["two"] == "true"
    assert actual["three"] == "True"
示例#6
0
def test_emojis_in_tmp_file():
    test_data = """
        data:
            - one 😁💯 👩🏿‍💻👨🏿‍💻
            - two £ (?u)\\b\\w+\\b f\u00fcr
        """
    test_file = utils.create_temporary_file(test_data)
    with io.open(test_file, mode='r', encoding="utf-8") as f:
        content = f.read()
    actual = utils.read_yaml(content)

    assert actual["data"][0] == "one 😁💯 👩🏿‍💻👨🏿‍💻"
    assert actual["data"][1] == "two £ (?u)\\b\\w+\\b für"
示例#7
0
    def extract_data_and_config(self, request):

        request_content = request.content.read().decode('utf-8', 'strict')
        content_type = self.get_request_content_type(request)

        if 'yml' in content_type:
            # assumes the user submitted a model configuration with a data
            # parameter attached to it

            model_config = utils.read_yaml(request_content)
            data = model_config.get("data")

        elif 'json' in content_type:

            model_config, data = self.extract_json(request_content)

        else:

            raise Exception("Content-Type must be 'application/x-yml' "
                            "or 'application/json'")

        return model_config, data
示例#8
0
def test_environment_variable_not_existing():
    content = "model: \n  test: ${variable}"
    with pytest.raises(KeyError):
        utils.read_yaml(content)