Skip to content

Commit

Permalink
Remove BaseTestComponent (#5613)
Browse files Browse the repository at this point in the history
* Remove BaseTestComponent

* Add release notes
  • Loading branch information
silvanocerza authored Aug 23, 2023
1 parent d5599df commit 66f615a
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 64 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
preview:
- Remove `BaseTestComponent` class used to test `Component`s
10 changes: 1 addition & 9 deletions test/preview/components/audio/test_whisper_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,11 @@
from haystack.preview.dataclasses import Document
from haystack.preview.components.audio import LocalWhisperTranscriber

from test.preview.components.base import BaseTestComponent


SAMPLES_PATH = Path(__file__).parent.parent.parent / "test_files"


class Test_LocalWhisperTranscriber(BaseTestComponent):
@pytest.mark.unit
def test_save_load(self, tmp_path):
self.assert_can_be_saved_and_loaded_in_pipeline(
LocalWhisperTranscriber(model_name_or_path="large-v2"), tmp_path
)

class TestLocalWhisperTranscriber:
@pytest.mark.unit
def test_init(self):
transcriber = LocalWhisperTranscriber(
Expand Down
14 changes: 1 addition & 13 deletions test/preview/components/audio/test_whisper_remote.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,12 @@
from pathlib import Path
from unittest.mock import MagicMock, patch

import pytest
import requests

from haystack.preview.dataclasses import Document
from haystack.preview.components.audio.whisper_remote import RemoteWhisperTranscriber, OPENAI_TIMEOUT

from test.preview.components.base import BaseTestComponent


class TestRemoteWhisperTranscriber(BaseTestComponent):
"""
Tests for RemoteWhisperTranscriber.
"""

@pytest.mark.unit
def test_save_load(self, tmp_path):
self.assert_can_be_saved_and_loaded_in_pipeline(RemoteWhisperTranscriber(api_key="just a test"), tmp_path)

class TestRemoteWhisperTranscriber:
@pytest.mark.unit
def test_init_unknown_model(self):
with pytest.raises(ValueError, match="not recognized"):
Expand Down
16 changes: 0 additions & 16 deletions test/preview/components/base.py

This file was deleted.

10 changes: 1 addition & 9 deletions test/preview/components/classifiers/test_file_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,13 @@
import pytest

from haystack.preview.components.classifiers.file_classifier import FileExtensionClassifier
from test.preview.components.base import BaseTestComponent
from test.conftest import preview_samples_path


@pytest.mark.skipif(
sys.platform in ["win32", "cygwin"],
reason="Can't run on Windows Github CI, need access to registry to get mime types",
)
class TestFileExtensionClassifier(BaseTestComponent):
@pytest.mark.unit
def test_save_load(self, tmp_path):
self.assert_can_be_saved_and_loaded_in_pipeline(
FileExtensionClassifier(mime_types=["text/plain", "audio/x-wav", "image/jpeg"]), tmp_path
)

class TestFileExtensionClassifier:
@pytest.mark.unit
def test_run(self, preview_samples_path):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
from langdetect import LangDetectException

from haystack.preview.components.file_converters.txt import TextFileToDocument
from test.preview.components.base import BaseTestComponent


class TestTextfileToDocument(BaseTestComponent):
class TestTextfileToDocument:
@pytest.mark.unit
def test_run(self, preview_samples_path):
"""
Expand Down
14 changes: 1 addition & 13 deletions test/preview/components/retrievers/test_memory_retriever.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
from haystack.preview.dataclasses import Document
from haystack.preview.document_stores import MemoryDocumentStore

from test.preview.components.base import BaseTestComponent


@pytest.fixture()
def mock_docs():
Expand All @@ -22,17 +20,7 @@ def mock_docs():
]


class TestMemoryRetriever(BaseTestComponent):
# TODO: We're going to rework these tests when we'll remove BaseTestComponent.
# We also need to implement `to_dict` and `from_dict` to test this properly.
# @pytest.mark.unit
# def test_save_load(self, tmp_path):
# self.assert_can_be_saved_and_loaded_in_pipeline(MemoryRetriever(MemoryDocumentStore()), tmp_path)

# @pytest.mark.unit
# def test_save_load_with_parameters(self, tmp_path):
# self.assert_can_be_saved_and_loaded_in_pipeline(MemoryRetriever(top_k=5, scale_score=False), tmp_path)

class TestMemoryRetriever:
@pytest.mark.unit
def test_init_default(self):
retriever = MemoryRetriever(MemoryDocumentStore())
Expand Down
3 changes: 1 addition & 2 deletions test/preview/components/writers/document_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
from haystack.preview import Document
from haystack.preview.components.writers.document_writer import DocumentWriter
from haystack.preview.document_stores import DuplicatePolicy
from test.preview.components.base import BaseTestComponent


class TestDocumentWriter(BaseTestComponent):
class TestDocumentWriter:
@pytest.mark.unit
def test_run(self):
mocked_document_store = MagicMock()
Expand Down

0 comments on commit 66f615a

Please sign in to comment.