import rasa_nlu

import pytest

from rasa_nlu import registry, training_data
from rasa_nlu.model import Interpreter
from tests import utilities


@utilities.slowtest
@pytest.mark.parametrize("pipeline_template",
                         list(registry.registered_pipeline_templates.keys()))
def test_interpreter(pipeline_template, component_builder, tmpdir):
    test_data = "data/examples/rasa/demo-rasa.json"
    _conf = utilities.base_test_conf(pipeline_template)
    _conf["data"] = test_data
    td = training_data.load_data(test_data)
    interpreter = utilities.interpreter_for(component_builder,
                                            "data/examples/rasa/demo-rasa.json",
                                            tmpdir.strpath,
                                            _conf)

    texts = ["good bye", "i am looking for an indian spot"]

    for text in texts:
        result = interpreter.parse(text, time=None)
        assert result['text'] == text
        assert (not result['intent']['name'] or
                result['intent']['name'] in td.intents)
        assert result['intent']['confidence'] >= 0
        # Ensure the model doesn't detect entity types that are not present
        # Models on our test data set are not stable enough to
        # require the exact entities to be found
        for entity in result['entities']:
            assert entity['entity'] in td.entities


@pytest.mark.parametrize("metadata",
                         [{"rasa_nlu_version": "0.11.0"},
                          {"rasa_nlu_version": "0.10.2"},
                          {"rasa_nlu_version": "0.12.0a1"},
                          {"rasa_nlu_version": "0.12.2"},
                          {"rasa_nlu_version": "0.12.3"}])
def test_model_not_compatible(metadata):
    with pytest.raises(rasa_nlu.model.UnsupportedModelError):
        Interpreter.ensure_model_compatibility(metadata)


@pytest.mark.parametrize("metadata",
                         [{"rasa_nlu_version": "0.13.0a2"},
                          {"rasa_nlu_version": "0.13.0"}])
def test_model_is_compatible(metadata):
    # should not raise an exception
    assert Interpreter.ensure_model_compatibility(metadata) is None

@@ -1728,19 +1728,604 @@
 0.12.3%22%7D
+,%0A                          %7B%22rasa_nlu_version%22: %220.13.3%22%7D,%0A                          %7B%22rasa_nlu_version%22: %220.13.4%22%7D,%0A                          %7B%22rasa_nlu_version%22: %220.13.5%22%7D,%0A                          %7B%22rasa_nlu_version%22: %220.14.0a1%22%7D,%0A                          %7B%22rasa_nlu_version%22: %220.14.0%22%7D,%0A                          %7B%22rasa_nlu_version%22: %220.14.1%22%7D,%0A                          %7B%22rasa_nlu_version%22: %220.14.2%22%7D,%0A                          %7B%22rasa_nlu_version%22: %220.14.3%22%7D,%0A                          %7B%22rasa_nlu_version%22: %220.14.4%22%7D,%0A                          %7B%22rasa_nlu_version%22: %220.15.0a1%22%7D,
 %5D)%0A
-
 def test
@@ -2566,17 +2566,17 @@
 n%22: %220.1
-3
+5
 .0a2%22%7D,%0A
@@ -2626,17 +2626,17 @@
 n%22: %220.1
-3
+5
 .0%22%7D%5D)%0Ad

fix compatibility tests