dc6079821b
Docs Tests / Check for file changes (push) Has been cancelled
Docs Tests / Test Documentation (push) Has been cancelled
Docs Tests / Documentation Linting Checks (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.10, test-performance) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.10, test-policies) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.8, test-cli) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.8, test-core-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.8, test-full-model-training) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.8, test-nlu-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.8, test-nlu-predictors) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.8, test-other-unit-tests) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.8, test-performance) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.8, test-policies) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.9, test-cli) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.9, test-core-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.9, test-full-model-training) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.9, test-nlu-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.9, test-nlu-predictors) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.9, test-other-unit-tests) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.9, test-performance) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.9, test-policies) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.10, test-cli) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.10, test-core-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.10, test-full-model-training) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.10, test-nlu-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.10, test-nlu-predictors) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.10, test-other-unit-tests) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.10, test-performance) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.10, test-policies) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.8, test-cli) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.8, test-core-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.8, test-full-model-training) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.8, test-nlu-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.8, test-nlu-predictors) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.8, test-other-unit-tests) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.8, test-performance) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.8, test-policies) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.9, test-cli) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.9, test-core-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.9, test-full-model-training) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.9, test-nlu-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.9, test-nlu-predictors) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.9, test-other-unit-tests) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.9, test-performance) (push) Has been cancelled
Continuous Integration / Run Tests (windows-2022, 3.9, test-policies) (push) Has been cancelled
Continuous Integration / Run Flaky Tests (ubuntu-24.04, 3.10) (push) Has been cancelled
Continuous Integration / Run Flaky Tests (ubuntu-24.04, 3.8) (push) Has been cancelled
Continuous Integration / Run Flaky Tests (ubuntu-24.04, 3.9) (push) Has been cancelled
Continuous Integration / Run Flaky Tests (windows-2022, 3.10) (push) Has been cancelled
Continuous Integration / Run Flaky Tests (windows-2022, 3.8) (push) Has been cancelled
Continuous Integration / Run Flaky Tests (windows-2022, 3.9) (push) Has been cancelled
Continuous Integration / Check for file changes (push) Has been cancelled
Continuous Integration / Wait for docs tests (push) Has been cancelled
Continuous Integration / Code Quality (push) Has been cancelled
Continuous Integration / Check for changelog (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.10, test-cli) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.10, test-core-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.10, test-full-model-training) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.10, test-nlu-featurizers) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.10, test-nlu-predictors) (push) Has been cancelled
Continuous Integration / Run Tests (ubuntu-24.04, 3.10, test-other-unit-tests) (push) Has been cancelled
Continuous Integration / Upload coverage reports to codeclimate (push) Has been cancelled
Continuous Integration / Run Non-Sequential Integration Tests (push) Has been cancelled
Continuous Integration / Run Broker Integration Tests (push) Has been cancelled
Continuous Integration / Run Sequential Integration Tests (push) Has been cancelled
Continuous Integration / Build Docker base images and setup environment (push) Has been cancelled
Continuous Integration / Build Docker (default) (push) Has been cancelled
Continuous Integration / Build Docker (full) (push) Has been cancelled
Continuous Integration / Build Docker (mitie-en) (push) Has been cancelled
Continuous Integration / Build Docker (spacy-de) (push) Has been cancelled
Continuous Integration / Build Docker (spacy-en) (push) Has been cancelled
Continuous Integration / Build Docker (spacy-it) (push) Has been cancelled
Continuous Integration / Deploy to PyPI (push) Has been cancelled
Continuous Integration / Notify Slack & Publish Release Notes (push) Has been cancelled
Publish Documentation / Evaluate release tag (push) Has been cancelled
Publish Documentation / Prebuild Docs (push) Has been cancelled
Publish Documentation / Preview Docs (push) Has been cancelled
Publish Documentation / Check for file changes (push) Has been cancelled
Publish Documentation / Publish Docs (push) Has been cancelled
Automatic PR Merger / mergepal (push) Has been cancelled
CI Github Actions / Run Tests (push) Has been cancelled
Semgrep / Semgrep Workflow Security Scan (push) Has been cancelled
127 lines
3.9 KiB
Python
127 lines
3.9 KiB
Python
import inspect
|
|
import os.path
|
|
import tempfile
|
|
from typing import Dict, Text, Any, Optional
|
|
from unittest.mock import Mock
|
|
from _pytest.monkeypatch import MonkeyPatch
|
|
|
|
import rasa.shared.utils.io
|
|
from rasa.core.policies.ted_policy import TEDPolicy
|
|
from rasa.engine.graph import ExecutionContext, GraphComponent
|
|
from rasa.engine.storage.resource import Resource
|
|
from rasa.engine.storage.storage import ModelStorage
|
|
from rasa.engine.training import fingerprinting
|
|
from rasa.nlu.classifiers.diet_classifier import DIETClassifier
|
|
from rasa.nlu.selectors.response_selector import ResponseSelector
|
|
from tests.engine.training.test_components import FingerprintableText
|
|
|
|
|
|
def test_fingerprint_stays_same():
|
|
key1 = fingerprinting.calculate_fingerprint_key(
|
|
TEDPolicy, TEDPolicy.get_default_config(), {"input": FingerprintableText("Hi")}
|
|
)
|
|
key2 = fingerprinting.calculate_fingerprint_key(
|
|
TEDPolicy, TEDPolicy.get_default_config(), {"input": FingerprintableText("Hi")}
|
|
)
|
|
|
|
assert key1 == key2
|
|
|
|
|
|
def test_fingerprint_changes_due_to_class():
|
|
key1 = fingerprinting.calculate_fingerprint_key(
|
|
DIETClassifier,
|
|
TEDPolicy.get_default_config(),
|
|
{"input": FingerprintableText("Hi")},
|
|
)
|
|
key2 = fingerprinting.calculate_fingerprint_key(
|
|
ResponseSelector,
|
|
TEDPolicy.get_default_config(),
|
|
{"input": FingerprintableText("Hi")},
|
|
)
|
|
|
|
assert key1 != key2
|
|
|
|
|
|
def test_fingerprint_changes_due_to_config():
|
|
key1 = fingerprinting.calculate_fingerprint_key(
|
|
TEDPolicy, {}, {"input": FingerprintableText("Hi")}
|
|
)
|
|
key2 = fingerprinting.calculate_fingerprint_key(
|
|
ResponseSelector,
|
|
TEDPolicy.get_default_config(),
|
|
{"input": FingerprintableText("Hi")},
|
|
)
|
|
|
|
assert key1 != key2
|
|
|
|
|
|
def test_fingerprint_changes_due_to_inputs():
|
|
key1 = fingerprinting.calculate_fingerprint_key(
|
|
TEDPolicy, {}, {"input": FingerprintableText("Hi")}
|
|
)
|
|
key2 = fingerprinting.calculate_fingerprint_key(
|
|
ResponseSelector,
|
|
TEDPolicy.get_default_config(),
|
|
{"input": FingerprintableText("bye")},
|
|
)
|
|
|
|
assert key1 != key2
|
|
|
|
|
|
def test_fingerprint_changes_due_to_changed_source(monkeypatch: MonkeyPatch):
|
|
key1 = fingerprinting.calculate_fingerprint_key(
|
|
TEDPolicy, {}, {"input": FingerprintableText("Hi")}
|
|
)
|
|
|
|
get_source_mock = Mock(return_value="other implementation")
|
|
monkeypatch.setattr(inspect, inspect.getsource.__name__, get_source_mock)
|
|
|
|
key2 = fingerprinting.calculate_fingerprint_key(
|
|
TEDPolicy, {}, {"input": FingerprintableText("Hi")}
|
|
)
|
|
|
|
assert key1 != key2
|
|
|
|
get_source_mock.assert_called_once_with(TEDPolicy)
|
|
|
|
|
|
def test_fingerprint_changes_when_external_file_changes():
|
|
tmp_file = tempfile.mktemp()
|
|
|
|
class MinimalComponent(GraphComponent):
|
|
@classmethod
|
|
def create(
|
|
cls,
|
|
config: Dict[Text, Any],
|
|
model_storage: ModelStorage,
|
|
resource: Resource,
|
|
execution_context: ExecutionContext,
|
|
) -> "MinimalComponent":
|
|
return MinimalComponent()
|
|
|
|
@classmethod
|
|
def fingerprint_addon(cls, config: Dict[str, Any]) -> Optional[str]:
|
|
if not os.path.exists(tmp_file):
|
|
return None
|
|
else:
|
|
return rasa.shared.utils.io.get_text_hash(open(tmp_file, "r").read())
|
|
|
|
with open(tmp_file, "w") as external_data:
|
|
external_data.write("This is a test.")
|
|
|
|
fingerprint_1 = fingerprinting.calculate_fingerprint_key(MinimalComponent, {}, {})
|
|
|
|
fingerprint_2 = fingerprinting.calculate_fingerprint_key(MinimalComponent, {}, {})
|
|
|
|
assert fingerprint_1 == fingerprint_2
|
|
|
|
# overwrite the original external data
|
|
with open(tmp_file, "w") as external_data:
|
|
external_data.write("This is a test for changes in external data.")
|
|
|
|
fingerprint_3 = fingerprinting.calculate_fingerprint_key(MinimalComponent, {}, {})
|
|
|
|
assert fingerprint_3 != fingerprint_1
|
|
|
|
os.remove(tmp_file)
|