Skip to content

Commit

Permalink
del HF token in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
anakin87 committed Dec 13, 2024
1 parent 2a9a640 commit 9ec7de7
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def test_to_dict(self):

def test_from_dict(self, monkeypatch):
monkeypatch.delenv("HF_API_TOKEN", raising=False)
monkeypatch.delenv("HF_TOKEN", raising=False)
data = {
"type": "haystack.components.classifiers.zero_shot_document_classifier.TransformersZeroShotDocumentClassifier",
"init_parameters": {
Expand Down Expand Up @@ -73,6 +74,7 @@ def test_from_dict(self, monkeypatch):

def test_from_dict_no_default_parameters(self, monkeypatch):
monkeypatch.delenv("HF_API_TOKEN", raising=False)
monkeypatch.delenv("HF_TOKEN", raising=False)
data = {
"type": "haystack.components.classifiers.zero_shot_document_classifier.TransformersZeroShotDocumentClassifier",
"init_parameters": {"model": "cross-encoder/nli-deberta-v3-xsmall", "labels": ["positive", "negative"]},
Expand Down
1 change: 1 addition & 0 deletions test/components/generators/chat/test_hugging_face_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ def test_from_dict(self, model_info_mock):
@patch("haystack.components.generators.chat.hugging_face_local.pipeline")
def test_warm_up(self, pipeline_mock, monkeypatch):
monkeypatch.delenv("HF_API_TOKEN", raising=False)
monkeypatch.delenv("HF_TOKEN", raising=False)
generator = HuggingFaceLocalChatGenerator(
model="mistralai/Mistral-7B-Instruct-v0.2",
task="text2text-generation",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class TestHuggingFaceLocalGenerator:
@patch("haystack.utils.hf.model_info")
def test_init_default(self, model_info_mock, monkeypatch):
monkeypatch.delenv("HF_API_TOKEN", raising=False)
monkeypatch.delenv("HF_TOKEN", raising=False)
model_info_mock.return_value.pipeline_tag = "text2text-generation"
generator = HuggingFaceLocalGenerator()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def test_warm_up(self, similarity, monkeypatch):
Test that ranker loads the SentenceTransformer model correctly during warm up.
"""
monkeypatch.delenv("HF_API_TOKEN", raising=False)

monkeypatch.delenv("HF_TOKEN", raising=False)
mock_model_class = MagicMock()
mock_model_instance = MagicMock()
mock_model_class.return_value = mock_model_instance
Expand Down
1 change: 1 addition & 0 deletions test/components/rankers/test_transformers_similarity.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ def test_device_map_and_device_raises(self, caplog):
@patch("haystack.components.rankers.transformers_similarity.AutoModelForSequenceClassification.from_pretrained")
def test_device_map_dict(self, mocked_automodel, _mocked_autotokenizer, monkeypatch):
monkeypatch.delenv("HF_API_TOKEN", raising=False)
monkeypatch.delenv("HF_TOKEN", raising=False)
ranker = TransformersSimilarityRanker("model", model_kwargs={"device_map": {"layer_1": 1, "classifier": "cpu"}})

class MockedModel:
Expand Down
3 changes: 3 additions & 0 deletions test/components/readers/test_extractive.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@ def __init__(self):
@patch("haystack.components.readers.extractive.AutoModelForQuestionAnswering.from_pretrained")
def test_device_map_auto(mocked_automodel, _mocked_autotokenizer, monkeypatch):
monkeypatch.delenv("HF_API_TOKEN", raising=False)
monkeypatch.delenv("HF_TOKEN", raising=False)
reader = ExtractiveReader("deepset/roberta-base-squad2", model_kwargs={"device_map": "auto"})
auto_device = ComponentDevice.resolve_device(None)

Expand All @@ -537,6 +538,7 @@ def __init__(self):
@patch("haystack.components.readers.extractive.AutoModelForQuestionAnswering.from_pretrained")
def test_device_map_str(mocked_automodel, _mocked_autotokenizer, monkeypatch):
monkeypatch.delenv("HF_API_TOKEN", raising=False)
monkeypatch.delenv("HF_TOKEN", raising=False)
reader = ExtractiveReader("deepset/roberta-base-squad2", model_kwargs={"device_map": "cpu:0"})

class MockedModel:
Expand All @@ -554,6 +556,7 @@ def __init__(self):
@patch("haystack.components.readers.extractive.AutoModelForQuestionAnswering.from_pretrained")
def test_device_map_dict(mocked_automodel, _mocked_autotokenizer, monkeypatch):
monkeypatch.delenv("HF_API_TOKEN", raising=False)
monkeypatch.delenv("HF_TOKEN", raising=False)
reader = ExtractiveReader(
"deepset/roberta-base-squad2", model_kwargs={"device_map": {"layer_1": 1, "classifier": "cpu"}}
)
Expand Down
3 changes: 3 additions & 0 deletions test/components/routers/test_transformers_text_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def test_to_dict_with_cpu_device(self, mock_auto_config_from_pretrained):
def test_from_dict(self, mock_auto_config_from_pretrained, monkeypatch):
mock_auto_config_from_pretrained.return_value = MagicMock(label2id={"en": 0, "de": 1})
monkeypatch.delenv("HF_API_TOKEN", raising=False)
monkeypatch.delenv("HF_TOKEN", raising=False)
data = {
"type": "haystack.components.routers.transformers_text_router.TransformersTextRouter",
"init_parameters": {
Expand Down Expand Up @@ -84,6 +85,7 @@ def test_from_dict(self, mock_auto_config_from_pretrained, monkeypatch):
def test_from_dict_no_default_parameters(self, mock_auto_config_from_pretrained, monkeypatch):
mock_auto_config_from_pretrained.return_value = MagicMock(label2id={"en": 0, "de": 1})
monkeypatch.delenv("HF_API_TOKEN", raising=False)
monkeypatch.delenv("HF_TOKEN", raising=False)
data = {
"type": "haystack.components.routers.transformers_text_router.TransformersTextRouter",
"init_parameters": {"model": "papluca/xlm-roberta-base-language-detection"},
Expand All @@ -105,6 +107,7 @@ def test_from_dict_no_default_parameters(self, mock_auto_config_from_pretrained,
def test_from_dict_with_cpu_device(self, mock_auto_config_from_pretrained, monkeypatch):
mock_auto_config_from_pretrained.return_value = MagicMock(label2id={"en": 0, "de": 1})
monkeypatch.delenv("HF_API_TOKEN", raising=False)
monkeypatch.delenv("HF_TOKEN", raising=False)
data = {
"type": "haystack.components.routers.transformers_text_router.TransformersTextRouter",
"init_parameters": {
Expand Down
2 changes: 2 additions & 0 deletions test/components/routers/test_zero_shot_text_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def test_to_dict(self):

def test_from_dict(self, monkeypatch):
monkeypatch.delenv("HF_API_TOKEN", raising=False)
monkeypatch.delenv("HF_TOKEN", raising=False)
data = {
"type": "haystack.components.routers.zero_shot_text_router.TransformersZeroShotTextRouter",
"init_parameters": {
Expand Down Expand Up @@ -56,6 +57,7 @@ def test_from_dict(self, monkeypatch):

def test_from_dict_no_default_parameters(self, monkeypatch):
monkeypatch.delenv("HF_API_TOKEN", raising=False)
monkeypatch.delenv("HF_TOKEN", raising=False)
data = {
"type": "haystack.components.routers.zero_shot_text_router.TransformersZeroShotTextRouter",
"init_parameters": {"labels": ["query", "passage"]},
Expand Down

0 comments on commit 9ec7de7

Please sign in to comment.