MCPcopy
hub / github.com/pytest-dev/pytest / Visitor

Class Visitor

src/_pytest/_py/path.py:138–170  ·  src/_pytest/_py/path.py::Visitor

Source from the content-addressed store, hash-verified

136
137
138class Visitor:
139 def __init__(self, fil, rec, ignore, bf, sort):
140 if isinstance(fil, (str, bytes)):
141 fil = FNMatcher(fil)
142 if isinstance(rec, str):
143 self.rec: Callable[[LocalPath], bool] = FNMatcher(rec)
144 elif not hasattr(rec, class="st">"__call__") and rec:
145 self.rec = lambda path: True
146 else:
147 self.rec = rec
148 self.fil = fil
149 self.ignore = ignore
150 self.breadthfirst = bf
151 self.optsort = cast(Callable[[Any], Any], sorted) if sort else (lambda x: x)
152
153 def gen(self, path):
154 try:
155 entries = path.listdir()
156 except self.ignore:
157 return
158 rec = self.rec
159 dirs = self.optsort(
160 [p for p in entries if p.check(dir=1) and (rec is None or rec(p))]
161 )
162 if not self.breadthfirst:
163 for subdir in dirs:
164 yield from self.gen(subdir)
165 for p in self.optsort(entries):
166 if self.fil is None or self.fil(p):
167 yield p
168 if self.breadthfirst:
169 for subdir in dirs:
170 yield from self.gen(subdir)
171
172
173class FNMatcher:

Callers 1

visitMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected