MCPcopy Create free account
hub / github.com/huggingface/transformers / analyze_directory

Method analyze_directory

tests/test_doc_samples.py:35–84  ·  view source on GitHub ↗

Runs through the specific directory, looking for the files identified with `identifier`. Executes the doctests in those files Args: directory (:obj:`str`): Directory containing the files identifier (:obj:`str`): Will parse files containing this

(
        self,
        directory: Path,
        identifier: Union[str, None] = None,
        ignore_files: Union[List[str], None] = [],
        n_identifier: Union[str, None] = None,
        only_modules: bool = True,
    )

Source from the content-addressed store, hash-verified

33@slow
34class TestCodeExamples(unittest.TestCase):
35 def analyze_directory(
36 self,
37 directory: Path,
38 identifier: Union[str, None] = None,
39 ignore_files: Union[List[str], None] = [],
40 n_identifier: Union[str, None] = None,
41 only_modules: bool = True,
42 ):
43 """
44 Runs through the specific directory, looking for the files identified with `identifier`. Executes
45 the doctests in those files
46
47 Args:
48 directory (:obj:`str`): Directory containing the files
49 identifier (:obj:`str`): Will parse files containing this
50 ignore_files (:obj:`List[str]`): List of files to skip
51 n_identifier (:obj:`str` or :obj:`List[str]`): Will not parse files containing this/these identifiers.
52 only_modules (:obj:`bool`): Whether to only analyze modules
53 """
54 files = [file for file in os.listdir(directory) if os.path.isfile(os.path.join(directory, file))]
55
56 if identifier is not None:
57 files = [file for file in files if identifier in file]
58
59 if n_identifier is not None:
60 if isinstance(n_identifier, List):
61 for n_ in n_identifier:
62 files = [file for file in files if n_ not in file]
63 else:
64 files = [file for file in files if n_identifier not in file]
65
66 ignore_files.append("__init__.py")
67 files = [file for file in files if file not in ignore_files]
68
69 for file in files:
70 # Open all files
71 print("Testing", file)
72
73 if only_modules:
74 try:
75 module_identifier = file.split(".")[0]
76 module_identifier = getattr(transformers, module_identifier)
77 suite = doctest.DocTestSuite(module_identifier)
78 result = unittest.TextTestRunner().run(suite)
79 self.assertIs(len(result.failures), 0)
80 except AttributeError:
81 logger.info(f"{module_identifier} is not a module.")
82 else:
83 result = doctest.testfile(str(".." / directory / file), optionflags=doctest.ELLIPSIS)
84 self.assertIs(result.failed, 0)
85
86 def test_modeling_examples(self):
87 transformers_directory = "src/transformers"

Callers 5

test_doc_sourcesMethod · 0.95

Calls 1

runMethod · 0.45

Tested by

no test coverage detected