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

Method listdir

src/_pytest/_py/path.py:803–824  ·  src/_pytest/_py/path.py::LocalPath.listdir

List directory contents, possibly filter by the given fil func and possibly sorted.

(self, fil=None, sort=None)

Source from the content-addressed store, hash-verified

801 _patternchars = set(class="st">"*?[" + os.sep)
802
803 def listdir(self, fil=None, sort=None):
804 class="st">"""List directory contents, possibly filter by the given fil func
805 and possibly sorted.
806 class="st">"""
807 if fil is None and sort is None:
808 names = error.checked_call(os.listdir, self.strpath)
809 return map_as_list(self._fastjoin, names)
810 if isinstance(fil, str):
811 if not self._patternchars.intersection(fil):
812 child = self._fastjoin(fil)
813 if exists(child.strpath):
814 return [child]
815 return []
816 fil = FNMatcher(fil)
817 names = error.checked_call(os.listdir, self.strpath)
818 res = []
819 for name in names:
820 child = self._fastjoin(name)
821 if fil is None or fil(child):
822 res.append(child)
823 self._sortlist(res, sort)
824 return res
825
826 def size(self) -> int:
827 class="st">""class="st">"Return size of the underlying file object"class="st">""

Callers 12

genMethod · 0.80
make_numbered_dirMethod · 0.80
test_pyc_vs_pyoMethod · 0.80
test_listdirMethod · 0.80
test_listdir_filterMethod · 0.80
test_listdir_sortedMethod · 0.80
test_sysexecMethod · 0.80
test_listdir_single_argFunction · 0.80
test_mkdtemp_rootdirFunction · 0.80
test_listdirMethod · 0.80

Calls 6

_fastjoinMethod · 0.95
_sortlistMethod · 0.95
map_as_listFunction · 0.85
FNMatcherClass · 0.85
checked_callMethod · 0.80
appendMethod · 0.80

Tested by 10

test_pyc_vs_pyoMethod · 0.64
test_listdirMethod · 0.64
test_listdir_filterMethod · 0.64
test_listdir_sortedMethod · 0.64
test_sysexecMethod · 0.64
test_listdir_single_argFunction · 0.64
test_mkdtemp_rootdirFunction · 0.64
test_listdirMethod · 0.64