Skip to content

Commit

Permalink
[tests] add the missing require_sacremoses decorator (#29504)
Browse files Browse the repository at this point in the history
* add sacremoses check

* fix style

* for FlaubertTokenizer

* HerbertTokenizer fix

* add typeHint

* Update src/transformers/testing_utils.py

Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com>

* make less skipped

* make quality

* remove import

---------

Co-authored-by: amyeroberts <22614925+amyeroberts@users.noreply.github.com>
  • Loading branch information
faaany and amyeroberts authored Mar 8, 2024
1 parent bc764f4 commit 8e589c8
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/transformers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1078,6 +1078,7 @@
"is_psutil_available",
"is_py3nvml_available",
"is_pyctcdecode_available",
"is_sacremoses_available",
"is_safetensors_available",
"is_scipy_available",
"is_sentencepiece_available",
Expand Down Expand Up @@ -5882,6 +5883,7 @@
is_psutil_available,
is_py3nvml_available,
is_pyctcdecode_available,
is_sacremoses_available,
is_safetensors_available,
is_scipy_available,
is_sentencepiece_available,
Expand Down
8 changes: 8 additions & 0 deletions src/transformers/testing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
is_pytest_available,
is_pytorch_quantization_available,
is_rjieba_available,
is_sacremoses_available,
is_safetensors_available,
is_scipy_available,
is_sentencepiece_available,
Expand Down Expand Up @@ -562,6 +563,13 @@ def require_sentencepiece(test_case):
return unittest.skipUnless(is_sentencepiece_available(), "test requires SentencePiece")(test_case)


def require_sacremoses(test_case):
"""
Decorator marking a test that requires Sacremoses. These tests are skipped when Sacremoses isn't installed.
"""
return unittest.skipUnless(is_sacremoses_available(), "test requires Sacremoses")(test_case)


def require_seqio(test_case):
"""
Decorator marking a test that requires SentencePiece. These tests are skipped when SentencePiece isn't installed.
Expand Down
4 changes: 2 additions & 2 deletions tests/models/biogpt/test_modeling_biogpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import math
import unittest

from transformers import BioGptConfig, is_torch_available
from transformers import BioGptConfig, is_sacremoses_available, is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

from ...generation.test_utils import GenerationTesterMixin
Expand Down Expand Up @@ -294,7 +294,7 @@ class BioGptModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTesterMix
"token-classification": BioGptForTokenClassification,
"zero-shot": BioGptForSequenceClassification,
}
if is_torch_available()
if is_torch_available() and is_sacremoses_available()
else {}
)
test_pruning = False
Expand Down
3 changes: 2 additions & 1 deletion tests/models/biogpt/test_tokenization_biogpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@
import unittest

from transformers.models.biogpt.tokenization_biogpt import VOCAB_FILES_NAMES, BioGptTokenizer
from transformers.testing_utils import slow
from transformers.testing_utils import require_sacremoses, slow

from ...test_tokenization_common import TokenizerTesterMixin


@require_sacremoses
class BioGptTokenizationTest(TokenizerTesterMixin, unittest.TestCase):
tokenizer_class = BioGptTokenizer
test_rust_tokenizer = False
Expand Down
4 changes: 2 additions & 2 deletions tests/models/flaubert/test_modeling_flaubert.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import tempfile
import unittest

from transformers import FlaubertConfig, is_torch_available
from transformers import FlaubertConfig, is_sacremoses_available, is_torch_available
from transformers.testing_utils import require_torch, require_torch_accelerator, slow, torch_device

from ...test_configuration_common import ConfigTester
Expand Down Expand Up @@ -386,7 +386,7 @@ class FlaubertModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase
"token-classification": FlaubertForTokenClassification,
"zero-shot": FlaubertForSequenceClassification,
}
if is_torch_available()
if is_torch_available() and is_sacremoses_available()
else {}
)

Expand Down
3 changes: 2 additions & 1 deletion tests/models/herbert/test_tokenization_herbert.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@

from transformers import HerbertTokenizer, HerbertTokenizerFast
from transformers.models.herbert.tokenization_herbert import VOCAB_FILES_NAMES
from transformers.testing_utils import get_tests_dir, require_tokenizers, slow
from transformers.testing_utils import get_tests_dir, require_sacremoses, require_tokenizers, slow

from ...test_tokenization_common import TokenizerTesterMixin


@require_sacremoses
@require_tokenizers
class HerbertTokenizationTest(TokenizerTesterMixin, unittest.TestCase):
tokenizer_class = HerbertTokenizer
Expand Down

0 comments on commit 8e589c8

Please sign in to comment.