Fix ignore list behavior in doctests (#8213)
This commit is contained in:
@@ -36,8 +36,8 @@ class TestCodeExamples(unittest.TestCase):
|
||||
self,
|
||||
directory: Path,
|
||||
identifier: Union[str, None] = None,
|
||||
ignore_files: Union[List[str], None] = [],
|
||||
n_identifier: Union[str, None] = None,
|
||||
ignore_files: Union[List[str], None] = None,
|
||||
n_identifier: Union[str, List[str], None] = None,
|
||||
only_modules: bool = True,
|
||||
):
|
||||
"""
|
||||
@@ -45,7 +45,7 @@ class TestCodeExamples(unittest.TestCase):
|
||||
the doctests in those files
|
||||
|
||||
Args:
|
||||
directory (:obj:`str`): Directory containing the files
|
||||
directory (:obj:`Path`): Directory containing the files
|
||||
identifier (:obj:`str`): Will parse files containing this
|
||||
ignore_files (:obj:`List[str]`): List of files to skip
|
||||
n_identifier (:obj:`str` or :obj:`List[str]`): Will not parse files containing this/these identifiers.
|
||||
@@ -63,6 +63,7 @@ class TestCodeExamples(unittest.TestCase):
|
||||
else:
|
||||
files = [file for file in files if n_identifier not in file]
|
||||
|
||||
ignore_files = ignore_files or []
|
||||
ignore_files.append("__init__.py")
|
||||
files = [file for file in files if file not in ignore_files]
|
||||
|
||||
@@ -71,8 +72,8 @@ class TestCodeExamples(unittest.TestCase):
|
||||
print("Testing", file)
|
||||
|
||||
if only_modules:
|
||||
module_identifier = file.split(".")[0]
|
||||
try:
|
||||
module_identifier = file.split(".")[0]
|
||||
module_identifier = getattr(transformers, module_identifier)
|
||||
suite = doctest.DocTestSuite(module_identifier)
|
||||
result = unittest.TextTestRunner().run(suite)
|
||||
@@ -84,7 +85,7 @@ class TestCodeExamples(unittest.TestCase):
|
||||
self.assertIs(result.failed, 0)
|
||||
|
||||
def test_modeling_examples(self):
|
||||
transformers_directory = "src/transformers"
|
||||
transformers_directory = Path("src/transformers")
|
||||
files = "modeling"
|
||||
ignore_files = [
|
||||
"modeling_ctrl.py",
|
||||
|
||||
Reference in New Issue
Block a user