Exemplo n.º 1
0
def test_validate_files_form_slots_not_matching(tmp_path: Path):
    domain_file_name = tmp_path / "domain.yml"
    domain_file_name.write_text("""
        version: "3.0"
        forms:
          name_form:
            required_slots:
            - first_name
            - last_name
        slots:
             first_name:
                type: text
                mappings:
                - type: from_text
             last_nam:
                type: text
                mappings:
                - type: from_text
        """)
    args = {
        "domain": domain_file_name,
        "data": None,
        "max_history": None,
        "config": None,
    }
    with pytest.raises(SystemExit):
        data.validate_files(namedtuple("Args", args.keys())(*args.values()))
Exemplo n.º 2
0
def test_validate_files_invalid_slot_mappings(tmp_path: Path):
    domain = tmp_path / "domain.yml"
    slot_name = "started_booking_form"
    domain.write_text(f"""
            version: "3.0"
            intents:
            - activate_booking
            entities:
            - city
            slots:
              {slot_name}:
                type: bool
                influence_conversation: false
                mappings:
                - type: from_trigger_intent
                  intent: activate_booking
                  value: true
              location:
                type: text
                mappings:
                - type: from_entity
                  entity: city
            forms:
              booking_form:
                required_slots:
                - location
                """)
    args = {
        "domain": str(domain),
        "data": None,
        "max_history": None,
        "config": None,
    }
    with pytest.raises(SystemExit):
        data.validate_files(namedtuple("Args", args.keys())(*args.values()))
Exemplo n.º 3
0
def test_validate_files_with_active_loop_null(
    file_type: Text, data_type: Text, tmp_path: Path
):
    file_name = tmp_path / f"{file_type}.yml"
    file_name.write_text(
        f"""
        version: "{LATEST_TRAINING_DATA_FORMAT_VERSION}"
        {file_type}:
        - {data_type}: test path
          steps:
            - intent: request_restaurant
            - action: restaurant_form
            - active_loop: restaurant_form
            - active_loop: null
            - action: action_search_restaurants
        """
    )
    args = {
        "domain": "data/test_domains/restaurant_form.yml",
        "data": [file_name],
        "max_history": None,
        "config": None,
        "fail_on_warnings": False,
    }
    with pytest.warns(None):
        data.validate_files(namedtuple("Args", args.keys())(*args.values()))
Exemplo n.º 4
0
def test_validate_files_exit_early():
    with pytest.raises(SystemExit) as pytest_e:
        args = {
            "domain": "data/test_domains/duplicate_intents.yml",
            "data": None
        }
        data.validate_files(namedtuple("Args", args.keys())(*args.values()))

    assert pytest_e.type == SystemExit
    assert pytest_e.value.code == 1
Exemplo n.º 5
0
def test_validate_files_invalid_domain():
    args = {
        "domain": "data/test_domains/default_with_mapping.yml",
        "data": None,
        "max_history": None,
        "config": None,
    }

    with pytest.raises(SystemExit):
        data.validate_files(namedtuple("Args", args.keys())(*args.values()))
        with pytest.warns(UserWarning) as w:
            assert "Please migrate to RulePolicy." in str(w[0].message)
Exemplo n.º 6
0
def test_data_validate_stories_with_max_history_zero(monkeypatch: MonkeyPatch):
    parser = argparse.ArgumentParser()
    subparsers = parser.add_subparsers(help="Rasa commands")
    data.add_subparser(subparsers, parents=[])

    args = parser.parse_args(["data", "validate", "stories", "--max-history", 0])

    async def mock_from_importer(importer: TrainingDataImporter) -> Validator:
        return Mock()

    monkeypatch.setattr("rasa.validator.Validator.from_importer", mock_from_importer)

    with pytest.raises(argparse.ArgumentTypeError):
        data.validate_files(args)
Exemplo n.º 7
0
def test_validate_files_action_not_found_invalid_domain(
        file_type: Text, data_type: Text, tmp_path: Path):
    file_name = tmp_path / f"{file_type}.yml"
    file_name.write_text(f"""
        version: "3.0"
        {file_type}:
        - {data_type}: test path
          steps:
          - intent: goodbye
          - action: action_test
        """)
    args = {
        "domain": "data/test_moodbot/domain.yml",
        "data": [file_name],
        "max_history": None,
        "config": None,
    }
    with pytest.raises(SystemExit):
        data.validate_files(namedtuple("Args", args.keys())(*args.values()))
Exemplo n.º 8
0
def test_validate_files_with_active_loop_null(tmp_path: Path):
    file_name = tmp_path / "rules.yml"
    file_name.write_text("""
        version: "3.0"
        rules:
        - rule: test path
          steps:
            - intent: request_restaurant
            - action: restaurant_form
            - active_loop: null
        """)
    args = {
        "domain": "data/test_restaurantbot/domain.yml",
        "data": [file_name],
        "max_history": None,
        "config": None,
        "fail_on_warnings": False,
    }
    with pytest.warns(None):
        data.validate_files(namedtuple("Args", args.keys())(*args.values()))
Exemplo n.º 9
0
def test_validate_files_form_not_found_invalid_domain(
    file_type: Text, data_type: Text, tmp_path: Path
):
    file_name = tmp_path / f"{file_type}.yml"
    file_name.write_text(
        f"""
        version: "{LATEST_TRAINING_DATA_FORMAT_VERSION}"
        {file_type}:
        - {data_type}: test path
          steps:
            - intent: request_restaurant
            - action: restaurant_form
            - active_loop: restaurant_form
        """
    )
    args = {
        "domain": "data/test_restaurantbot/domain.yml",
        "data": [file_name],
        "max_history": None,
        "config": None,
    }
    with pytest.raises(SystemExit):
        data.validate_files(namedtuple("Args", args.keys())(*args.values()))