From 7e1e1b7dec5ee8a91c910b4c4863858bd8d48a95 Mon Sep 17 00:00:00 2001 From: Tom Bocklisch Date: Thu, 13 Feb 2020 09:41:34 +0100 Subject: [PATCH] improved build speed by reusing trained models --- .github/workflows/continous-integration.yml | 5 +- .github/workflows/documentation.yml | 2 +- docs/conf.py | 3 +- scripts/publish_gh_release_notes.py | 2 +- tests/cli/conftest.py | 27 ++++- tests/conftest.py | 56 +++++++--- tests/core/conftest.py | 111 ++------------------ tests/core/test_agent.py | 51 +++++---- tests/core/test_model.py | 38 +++---- tests/core/test_nlg.py | 4 +- tests/core/test_trackers.py | 6 +- tests/nlu/base/test_evaluation.py | 5 +- tests/test_server.py | 2 +- 13 files changed, 134 insertions(+), 178 deletions(-) diff --git a/.github/workflows/continous-integration.yml b/.github/workflows/continous-integration.yml index 0a9821f56eae..2e82433ec16c 100644 --- a/.github/workflows/continous-integration.yml +++ b/.github/workflows/continous-integration.yml @@ -1,4 +1,4 @@ -name: Continous Integration +name: Continuous Integration on: [push] @@ -18,7 +18,7 @@ env: jobs: api: - name: API specification + name: Test API specification runs-on: ubuntu-latest steps: @@ -177,6 +177,7 @@ jobs: GITHUB_TAG: ${{ github.ref }} GITHUB_REPO_SLUG: ${{ github.repository }} run: | + sudo apt-get update sudo apt-get -y install pandoc pip install -U github3.py pypandoc python3 scripts/publish_gh_release_notes.py diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml index 3692d1f90cd7..1291731934d7 100644 --- a/.github/workflows/documentation.yml +++ b/.github/workflows/documentation.yml @@ -43,7 +43,7 @@ jobs: curl -sSL -o $RASABASTER "https://storage.googleapis.com/docs-theme/${RASABASTER}?q=$(date +%s%N)" pip install $RASABASTER pip install -r requirements.txt - pip install --no-cache-dir -r requirements-docs.txt + pip install -r requirements-docs.txt pip install git+https://${GITHUB_TOKEN}:x-oauth-basic@github.com/RasaHQ/sphinxcontrib-versioning.git@version_list pip install -e . pip list diff --git a/docs/conf.py b/docs/conf.py index 110fdbd56a6b..8b08d499c0ae 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -336,7 +336,8 @@ scv_whitelist_tags = ( re.compile(r"^[2-9]+\.\d+\.\d+$"), re.compile(r"^1\.[1-9][0-9]+\.\d+$"), - re.compile(r"^1\.[6789]\.\d+$"), + re.compile(r"^1\.[789]\.\d+$"), + re.compile(r"^1\.6\.2$"), re.compile(r"^1\.5\.3$"), re.compile(r"^1\.4\.6$"), re.compile(r"^1\.3\.10$"), diff --git a/scripts/publish_gh_release_notes.py b/scripts/publish_gh_release_notes.py index 4394354d1ba6..7dc4c4ab4e4c 100644 --- a/scripts/publish_gh_release_notes.py +++ b/scripts/publish_gh_release_notes.py @@ -1,6 +1,6 @@ """ Script used to publish GitHub release notes extracted from CHANGELOG.rst. -This script is executed by Github after a new release was successfully built. +This script is executed by GitHub after a new release was successfully built. Uses the following environment variables: * GITHUB_TAG: the name of the tag of the current commit. diff --git a/tests/cli/conftest.py b/tests/cli/conftest.py index b7294eaeadff..99c3acd4631b 100644 --- a/tests/cli/conftest.py +++ b/tests/cli/conftest.py @@ -1,3 +1,8 @@ +import shutil + +from subprocess import check_call + +from _pytest.tmpdir import TempdirFactory from typing import Callable import pytest import os @@ -22,10 +27,28 @@ def do_run(*args, stdin): return do_run +@pytest.fixture(scope="session") +def init_default_project(tmpdir_factory: TempdirFactory) -> str: + path = tmpdir_factory.mktemp("agent").strpath + os.environ["LOG_LEVEL"] = "ERROR" + + check_call(["rasa", "init", "--no-prompt"], cwd=path) + return path + + @pytest.fixture -def run_in_default_project(testdir: Testdir) -> Callable[..., RunResult]: +def run_in_default_project( + testdir: Testdir, init_default_project: str +) -> Callable[..., RunResult]: os.environ["LOG_LEVEL"] = "ERROR" - testdir.run("rasa", "init", "--no-prompt") + + # makes sure we do not always retrain an initial model for every "new" project + for file_name in os.listdir(init_default_project): + full_file_name = os.path.join(init_default_project, file_name) + if os.path.isfile(full_file_name): + shutil.copy(full_file_name, str(testdir.tmpdir)) + else: + shutil.copytree(full_file_name, str(testdir.tmpdir / file_name)) def do_run(*args): args = ["rasa"] + list(args) diff --git a/tests/conftest.py b/tests/conftest.py index 99b96601b0fc..4957360c217b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,9 +1,10 @@ -import logging -from contextlib import contextmanager -from typing import Text, List +import asyncio +from sanic.request import Request +from sanic.testing import SanicTestClient + +from typing import Text, List, Tuple, Iterator import pytest -from _pytest.logging import LogCaptureFixture from _pytest.tmpdir import TempdirFactory from sanic import Sanic @@ -12,9 +13,11 @@ from rasa.core.agent import Agent, load_agent from rasa.core.channels import channel from rasa.core.channels.channel import RestInput +from rasa.core.domain import SessionConfig from rasa.core.policies import Policy from rasa.core.policies.memoization import AugmentedMemoizationPolicy from rasa.core.run import _create_app_without_api +from rasa.core.tracker_store import InMemoryTrackerStore from rasa.model import get_model from rasa.train import train_async from rasa.utils.common import TempDirectoryPath @@ -33,13 +36,22 @@ # from a separatedly installable pytest-cli plugin. pytest_plugins = ["pytester"] +# https://github.com/pytest-dev/pytest-asyncio/issues/68 +# this event_loop is used by pytest-asyncio, and redefining it +# is currently the only way of changing the scope of this fixture +@pytest.yield_fixture(scope="session") +def event_loop(request: Request) -> Iterator[asyncio.AbstractEventLoop]: + loop = asyncio.get_event_loop_policy().new_event_loop() + yield loop + loop.close() -@pytest.fixture -async def default_agent(tmpdir_factory: TempdirFactory) -> Agent: + +@pytest.fixture(scope="session") +async def _trained_default_agent(tmpdir_factory: TempdirFactory) -> Tuple[Agent, str]: model_path = tmpdir_factory.mktemp("model").strpath agent = Agent( - "data/test_domains/default.yml", + "data/test_domains/default_with_slots.yml", policies=[AugmentedMemoizationPolicy(max_history=3)], ) @@ -49,6 +61,18 @@ async def default_agent(tmpdir_factory: TempdirFactory) -> Agent: return agent +def reset_conversation_state(agent: Agent) -> Agent: + # Clean tracker store after each test so tests don't affect each other + agent.tracker_store = InMemoryTrackerStore(agent.domain) + agent.domain.session_config = SessionConfig.default() + return agent + + +@pytest.fixture +async def default_agent(_trained_default_agent: Agent) -> Agent: + return reset_conversation_state(_trained_default_agent) + + @pytest.fixture(scope="session") async def trained_moodbot_path() -> Text: return await train_async( @@ -66,17 +90,17 @@ async def unpacked_trained_moodbot_path( return get_model(trained_moodbot_path) -@pytest.fixture +@pytest.fixture(scope="session") async def stack_agent(trained_rasa_model: Text) -> Agent: return await load_agent(model_path=trained_rasa_model) -@pytest.fixture +@pytest.fixture(scope="session") async def core_agent(trained_core_model: Text) -> Agent: return await load_agent(model_path=trained_core_model) -@pytest.fixture +@pytest.fixture(scope="session") async def nlu_agent(trained_nlu_model: Text) -> Agent: return await load_agent(model_path=trained_nlu_model) @@ -122,16 +146,15 @@ async def _train(*args, output_path=None, **kwargs): return _train -@pytest.fixture() +@pytest.fixture(scope="session") async def trained_rasa_model( trained_async, default_domain_path: Text, - default_config: List[Policy], default_nlu_data: Text, default_stories_file: Text, ) -> Text: trained_stack_model_path = await trained_async( - domain="data/test_domains/default.yml", + domain=default_domain_path, config=DEFAULT_STACK_CONFIG, training_files=[default_nlu_data, default_stories_file], ) @@ -139,11 +162,10 @@ async def trained_rasa_model( return trained_stack_model_path -@pytest.fixture() +@pytest.fixture(scope="session") async def trained_core_model( trained_async, default_domain_path: Text, - default_config: List[Policy], default_nlu_data: Text, default_stories_file: Text, ) -> Text: @@ -156,7 +178,7 @@ async def trained_core_model( return trained_core_model_path -@pytest.fixture() +@pytest.fixture(scope="session") async def trained_nlu_model( trained_async, default_domain_path: Text, @@ -208,7 +230,7 @@ async def rasa_server_without_api() -> Sanic: return app -def get_test_client(server): +def get_test_client(server: Sanic) -> SanicTestClient: test_client = server.test_client test_client.port = None return test_client diff --git a/tests/core/conftest.py b/tests/core/conftest.py index a58f80f92706..2613fcc98d7c 100644 --- a/tests/core/conftest.py +++ b/tests/core/conftest.py @@ -1,9 +1,11 @@ import asyncio import os + +from sanic.request import Request import uuid from datetime import datetime -from typing import Text +from typing import Text, Iterator import pytest from _pytest.tmpdir import TempdirFactory @@ -96,7 +98,7 @@ def __init__( # this event_loop is used by pytest-asyncio, and redefining it # is currently the only way of changing the scope of this fixture @pytest.yield_fixture(scope="session") -def event_loop(request): +def event_loop(request: Request) -> Iterator[asyncio.AbstractEventLoop]: loop = asyncio.get_event_loop_policy().new_event_loop() yield loop loop.close() @@ -136,56 +138,20 @@ def default_domain(): return Domain.load(DEFAULT_DOMAIN_PATH_WITH_SLOTS) -@pytest.fixture(scope="session") -async def _default_agent(default_domain: Domain) -> Agent: - agent = Agent( - default_domain, - policies=[MemoizationPolicy()], - interpreter=RegexInterpreter(), - tracker_store=InMemoryTrackerStore(default_domain), - ) - training_data = await agent.load_data(DEFAULT_STORIES_FILE) - agent.train(training_data) - return agent - - -@pytest.fixture() -async def default_agent(_default_agent: Agent) -> Agent: - # Clean tracker store after each test so tests don't affect each other - _default_agent.tracker_store = InMemoryTrackerStore(_default_agent.domain) - _default_agent.domain.session_config = SessionConfig.default() - return _default_agent - - -@pytest.fixture(scope="session") -def default_agent_path(_default_agent: Agent, tmpdir_factory: TempdirFactory): - path = tmpdir_factory.mktemp("agent").strpath - _default_agent.persist(path) - return path - - @pytest.fixture def default_channel() -> OutputChannel: return CollectingOutputChannel() @pytest.fixture -async def default_processor(default_domain, default_nlg): - agent = Agent( - default_domain, - SimplePolicyEnsemble([AugmentedMemoizationPolicy()]), - interpreter=RegexInterpreter(), - ) - - training_data = await agent.load_data(DEFAULT_STORIES_FILE) - agent.train(training_data) - tracker_store = InMemoryTrackerStore(default_domain) +async def default_processor(default_agent: Agent) -> MessageProcessor: + tracker_store = InMemoryTrackerStore(default_agent.domain) return MessageProcessor( - agent.interpreter, - agent.policy_ensemble, - default_domain, + default_agent.interpreter, + default_agent.policy_ensemble, + default_agent.domain, tracker_store, - default_nlg, + TemplatedNaturalLanguageGenerator(default_agent.domain.templates), ) @@ -243,39 +209,6 @@ def moodbot_metadata(unpacked_trained_moodbot_path): ) -@pytest.fixture() -async def trained_stack_model( - trained_async, - default_domain_path, - default_stack_config, - default_nlu_data, - default_stories_file, -): - - trained_stack_model_path = await trained_async( - domain=default_domain_path, - config=default_stack_config, - training_files=[default_nlu_data, default_stories_file], - ) - - return trained_stack_model_path - - -@pytest.fixture -async def prepared_agent(tmpdir_factory) -> Agent: - model_path = tmpdir_factory.mktemp("model").strpath - - agent = Agent( - "data/test_domains/default.yml", - policies=[AugmentedMemoizationPolicy(max_history=3)], - ) - - training_data = await agent.load_data(DEFAULT_STORIES_FILE) - agent.train(training_data) - agent.persist(model_path) - return agent - - @pytest.fixture def default_nlg(default_domain): return TemplatedNaturalLanguageGenerator(default_domain.templates) @@ -297,30 +230,6 @@ def project() -> Text: return directory -def train_model(loop, project: Text, filename: Text = "test.tar.gz"): - from rasa.constants import ( - DEFAULT_CONFIG_PATH, - DEFAULT_DATA_PATH, - DEFAULT_DOMAIN_PATH, - DEFAULT_MODELS_PATH, - ) - import rasa.train - - output = os.path.join(project, DEFAULT_MODELS_PATH, filename) - domain = os.path.join(project, DEFAULT_DOMAIN_PATH) - config = os.path.join(project, DEFAULT_CONFIG_PATH) - training_files = os.path.join(project, DEFAULT_DATA_PATH) - - rasa.train(domain, config, training_files, output, loop=loop) - - return output - - -@pytest.fixture(scope="session") -def trained_model(loop, project) -> Text: - return train_model(loop, project) - - @pytest.fixture async def restaurantbot(trained_async) -> Text: restaurant_domain = os.path.join(RESTAURANTBOT_PATH, "domain.yml") diff --git a/tests/core/test_agent.py b/tests/core/test_agent.py index 0fe3a5c3e17d..d181d847cc56 100644 --- a/tests/core/test_agent.py +++ b/tests/core/test_agent.py @@ -5,14 +5,16 @@ from sanic import Sanic, response import rasa.core +from rasa.core.policies.embedding_policy import EmbeddingPolicy +from rasa.core.policies.mapping_policy import MappingPolicy import rasa.utils.io from rasa.core import jobs, utils from rasa.core.agent import Agent, load_agent from rasa.core.channels.channel import UserMessage from rasa.core.domain import Domain, InvalidDomain from rasa.core.interpreter import INTENT_MESSAGE_PREFIX -from rasa.core.policies.ensemble import PolicyEnsemble -from rasa.core.policies.memoization import AugmentedMemoizationPolicy +from rasa.core.policies.ensemble import PolicyEnsemble, SimplePolicyEnsemble +from rasa.core.policies.memoization import AugmentedMemoizationPolicy, MemoizationPolicy from rasa.utils.endpoints import EndpointConfig from tests.core.conftest import DEFAULT_DOMAIN_PATH_WITH_SLOTS @@ -63,30 +65,25 @@ async def test_training_data_is_reproducible(tmpdir, default_domain): assert str(x.as_dialogue()) == str(same_training_data[i].as_dialogue()) -async def test_agent_train(tmpdir, default_domain): - training_data_file = "examples/moodbot/data/stories.md" - agent = Agent( - "examples/moodbot/domain.yml", policies=[AugmentedMemoizationPolicy()] - ) - - training_data = await agent.load_data(training_data_file) - - agent.train(training_data) - agent.persist(tmpdir.strpath) - - loaded = Agent.load(tmpdir.strpath) +async def test_agent_train(trained_moodbot_path: Text): + moodbot_domain = Domain.load("examples/moodbot/domain.yml") + loaded = Agent.load(trained_moodbot_path) # test domain - assert loaded.domain.action_names == agent.domain.action_names - assert loaded.domain.intents == agent.domain.intents - assert loaded.domain.entities == agent.domain.entities - assert loaded.domain.templates == agent.domain.templates - assert [s.name for s in loaded.domain.slots] == [s.name for s in agent.domain.slots] + assert loaded.domain.action_names == moodbot_domain.action_names + assert loaded.domain.intents == moodbot_domain.intents + assert loaded.domain.entities == moodbot_domain.entities + assert loaded.domain.templates == moodbot_domain.templates + assert [s.name for s in loaded.domain.slots] == [ + s.name for s in moodbot_domain.slots + ] # test policies - assert isinstance(loaded.policy_ensemble, type(agent.policy_ensemble)) + assert isinstance(loaded.policy_ensemble, SimplePolicyEnsemble) assert [type(p) for p in loaded.policy_ensemble.policies] == [ - type(p) for p in agent.policy_ensemble.policies + EmbeddingPolicy, + MemoizationPolicy, + MappingPolicy, ] @@ -122,7 +119,7 @@ async def test_agent_parse_message_using_nlu_interpreter( assert result == expected -async def test_agent_handle_text(default_agent): +async def test_agent_handle_text(default_agent: Agent): text = INTENT_MESSAGE_PREFIX + 'greet{"name":"Rasa"}' result = await default_agent.handle_text(text, sender_id="test_agent_handle_text") assert result == [ @@ -130,7 +127,7 @@ async def test_agent_handle_text(default_agent): ] -async def test_agent_handle_message(default_agent): +async def test_agent_handle_message(default_agent: Agent): text = INTENT_MESSAGE_PREFIX + 'greet{"name":"Rasa"}' message = UserMessage(text, sender_id="test_agent_handle_message") result = await default_agent.handle_message(message) @@ -192,8 +189,8 @@ async def test_wait_time_between_pulls_without_interval(model_server, monkeypatc jobs.kill_scheduler() -async def test_load_agent(trained_model): - agent = await load_agent(model_path=trained_model) +async def test_load_agent(trained_rasa_model: str): + agent = await load_agent(model_path=trained_rasa_model) assert agent.tracker_store is not None assert agent.interpreter is not None @@ -247,8 +244,8 @@ def test_two_stage_fallback_without_deny_suggestion(domain, policy_config): assert "The intent 'out_of_scope' must be present" in str(execinfo.value) -async def test_agent_update_model_none_domain(trained_model: Text): - agent = await load_agent(model_path=trained_model) +async def test_agent_update_model_none_domain(trained_rasa_model: Text): + agent = await load_agent(model_path=trained_rasa_model) agent.update_model( None, None, agent.fingerprint, agent.interpreter, agent.model_directory ) diff --git a/tests/core/test_model.py b/tests/core/test_model.py index e837ced5e929..13485fc80974 100644 --- a/tests/core/test_model.py +++ b/tests/core/test_model.py @@ -48,26 +48,26 @@ from rasa.exceptions import ModelNotFound -def test_get_latest_model(trained_model): +def test_get_latest_model(trained_rasa_model: str): import shutil - path_of_latest = os.path.join(os.path.dirname(trained_model), "latest.tar.gz") - shutil.copy(trained_model, path_of_latest) + path_of_latest = os.path.join(os.path.dirname(trained_rasa_model), "latest.tar.gz") + shutil.copy(trained_rasa_model, path_of_latest) model_directory = os.path.dirname(path_of_latest) assert get_latest_model(model_directory) == path_of_latest -def test_get_model_from_directory(trained_model): - unpacked = get_model(trained_model) +def test_get_model_from_directory(trained_rasa_model: str): + unpacked = get_model(trained_rasa_model) assert os.path.exists(os.path.join(unpacked, DEFAULT_CORE_SUBDIRECTORY_NAME)) assert os.path.exists(os.path.join(unpacked, "nlu")) -def test_get_model_context_manager(trained_model): - with get_model(trained_model) as unpacked: +def test_get_model_context_manager(trained_rasa_model: str): + with get_model(trained_rasa_model) as unpacked: assert os.path.exists(unpacked) assert not os.path.exists(unpacked) @@ -80,9 +80,9 @@ def test_get_model_exception(model_path): def test_get_model_from_directory_with_subdirectories( - trained_model, tmpdir_factory: TempdirFactory + trained_rasa_model, tmpdir_factory: TempdirFactory ): - unpacked = get_model(trained_model) + unpacked = get_model(trained_rasa_model) unpacked_core, unpacked_nlu = get_model_subdirectories(unpacked) assert unpacked_core @@ -93,8 +93,8 @@ def test_get_model_from_directory_with_subdirectories( get_model_subdirectories(directory) -def test_get_model_from_directory_nlu_only(trained_model): - unpacked = get_model(trained_model) +def test_get_model_from_directory_nlu_only(trained_rasa_model): + unpacked = get_model(trained_rasa_model) shutil.rmtree(os.path.join(unpacked, DEFAULT_CORE_SUBDIRECTORY_NAME)) unpacked_core, unpacked_nlu = get_model_subdirectories(unpacked) @@ -235,8 +235,8 @@ async def test_create_fingerprint_from_invalid_paths(project, project_files): @pytest.mark.parametrize("use_fingerprint", [True, False]) -async def test_rasa_packaging(trained_model, project, use_fingerprint): - unpacked_model_path = get_model(trained_model) +async def test_rasa_packaging(trained_rasa_model, project, use_fingerprint): + unpacked_model_path = get_model(trained_rasa_model) os.remove(os.path.join(unpacked_model_path, FINGERPRINT_FILE_PATH)) if use_fingerprint: @@ -314,8 +314,8 @@ async def test_rasa_packaging(trained_model, project, use_fingerprint): }, ], ) -def test_should_retrain(trained_model: Text, fingerprint: Fingerprint): - old_model = set_fingerprint(trained_model, fingerprint["old"]) +def test_should_retrain(trained_rasa_model: Text, fingerprint: Fingerprint): + old_model = set_fingerprint(trained_rasa_model, fingerprint["old"]) retrain = should_retrain(fingerprint["new"], old_model, tempfile.mkdtemp()) @@ -324,8 +324,8 @@ def test_should_retrain(trained_model: Text, fingerprint: Fingerprint): assert retrain.should_retrain_nlu() == fingerprint["retrain_nlu"] -def set_fingerprint(trained_model: Text, fingerprint: Fingerprint) -> Text: - unpacked_model_path = get_model(trained_model) +def set_fingerprint(trained_rasa_model: Text, fingerprint: Fingerprint) -> Text: + unpacked_model_path = get_model(trained_rasa_model) os.remove(os.path.join(unpacked_model_path, FINGERPRINT_FILE_PATH)) @@ -377,8 +377,8 @@ def test_fingerprint_comparison_result( assert comparison_result.should_retrain_nlu() == retrain_nlu -async def test_update_with_new_domain(trained_model: Text, tmpdir: Path): - _ = model.unpack_model(trained_model, tmpdir) +async def test_update_with_new_domain(trained_rasa_model: Text, tmpdir: Path): + _ = model.unpack_model(trained_rasa_model, tmpdir) new_domain = Domain.empty() diff --git a/tests/core/test_nlg.py b/tests/core/test_nlg.py index 479eed8c25fd..4d5ac70975d5 100644 --- a/tests/core/test_nlg.py +++ b/tests/core/test_nlg.py @@ -49,11 +49,11 @@ def http_nlg(request): return http_server.url -async def test_nlg(http_nlg, default_agent_path): +async def test_nlg(http_nlg, trained_rasa_model): sender = str(uuid.uuid1()) nlg_endpoint = EndpointConfig.from_dict({"url": http_nlg}) - agent = Agent.load(default_agent_path, None, generator=nlg_endpoint) + agent = Agent.load(trained_rasa_model, None, generator=nlg_endpoint) response = await agent.handle_text("/greet", sender_id=sender) assert len(response) == 1 diff --git a/tests/core/test_trackers.py b/tests/core/test_trackers.py index ade53c5287bb..9091394ca283 100644 --- a/tests/core/test_trackers.py +++ b/tests/core/test_trackers.py @@ -155,7 +155,7 @@ async def test_tracker_state_regression_without_bot_utterance(default_agent: Age # (and wasn't reset in between them) expected = ( "action_session_start;action_listen;greet;utter_greet;action_listen;" - "greet;action_listen" + "greet;utter_greet;action_listen" ) assert ( ";".join([e.as_story_string() for e in tracker.events if e.as_story_string()]) @@ -178,6 +178,8 @@ async def test_tracker_state_regression_with_bot_utterance(default_agent: Agent) None, "action_listen", "greet", + "utter_greet", + None, "action_listen", ] @@ -434,7 +436,7 @@ async def test_dump_and_restore_as_json(default_agent, tmpdir_factory): assert restored_tracker == tracker -def test_read_json_dump(default_agent): +def test_read_json_dump(default_agent: Agent): tracker_dump = "data/test_trackers/tracker_moodbot.json" tracker_json = json.loads(rasa.utils.io.read_file(tracker_dump)) diff --git a/tests/nlu/base/test_evaluation.py b/tests/nlu/base/test_evaluation.py index d0fdddc15194..64426d806c5f 100644 --- a/tests/nlu/base/test_evaluation.py +++ b/tests/nlu/base/test_evaluation.py @@ -1,4 +1,5 @@ -from typing import Text +from sanic.request import Request +from typing import Text, Iterator import asyncio import logging @@ -56,7 +57,7 @@ # this event_loop is used by pytest-asyncio, and redefining it # is currently the only way of changing the scope of this fixture @pytest.yield_fixture(scope="session") -def event_loop(request): +def event_loop(request: Request) -> Iterator[asyncio.AbstractEventLoop]: loop = asyncio.get_event_loop_policy().new_event_loop() yield loop loop.close() diff --git a/tests/test_server.py b/tests/test_server.py index 05b13d7fc9e6..9f4ad48889d9 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -598,7 +598,7 @@ def test_requesting_non_existent_tracker(rasa_app: SanicTestClient): content = response.json assert response.status == 200 assert content["paused"] is False - assert content["slots"] == {"location": None, "cuisine": None} + assert content["slots"] == {"name": None} assert content["sender_id"] == "madeupid" assert content["events"] == [ {