def test_no_roots(self): files = list(iter_files([], '.c', _glob=self._glob, _walk=self._walk)) self.assertEqual(files, []) self.assertEqual(self.calls, [])
def test_one_root(self): self._return_walk = [ [fixpath('spam/file1.c'), fixpath('spam/file2.c')], ] files = list(iter_files(['spam'], '.c', _glob=self._glob, _walk=self._walk)) self.assertEqual(files, [ fixpath('spam/file1.c'), fixpath('spam/file2.c'), ]) self.assertEqual(self.calls, [ ('_walk', ('spam', '.c', _walk_tree)), ])
def test_single_suffix(self): self._return_walk = [ [fixpath('spam/file1.c'), fixpath('spam/eggs/file3.c'), ], ] files = list(iter_files('spam', '.c', _glob=self._glob, _walk=self._walk)) self.assertEqual(files, [ fixpath('spam/file1.c'), fixpath('spam/eggs/file3.c'), ]) self.assertEqual(self.calls, [ ('_walk', ('spam', '.c', _walk_tree)), ])
def test_relparent(self): dirnames = self.set_files( ('/x/y/z/spam', ['file1.c', 'file2.c']), ('/x/y/z/eggs', ['ham/file3.c']), ) files = list(iter_files(dirnames, '.c', fixpath('/x/y'), _glob=self._glob, _walk=self._walk)) self.assertEqual(files, [ fixpath('z/spam/file1.c'), fixpath('z/spam/file2.c'), fixpath('z/eggs/ham/file3.c'), ]) self.assertEqual(self.calls, [ ('_walk', (fixpath('/x/y/z/spam'), '.c', _walk_tree)), ('_walk', (fixpath('/x/y/z/eggs'), '.c', _walk_tree)), ])
def test_no_suffix(self): expected = [fixpath('spam/file1.c'), fixpath('spam/file1.h'), fixpath('spam/file1.o'), fixpath('spam/eggs/file3.c'), ] for suffix in (None, '', ()): with self.subTest(suffix): self.calls.clear() self._return_walk = [list(expected)] files = list(iter_files('spam', suffix, _glob=self._glob, _walk=self._walk)) self.assertEqual(files, expected) self.assertEqual(self.calls, [ ('_walk', ('spam', suffix, _walk_tree)), ])
def test_multiple_roots(self): dirnames = self.set_files( ('spam', ['file1.c', 'file2.c']), ('eggs', ['ham/file3.c']), ) files = list(iter_files(dirnames, '.c', _glob=self._glob, _walk=self._walk)) self.assertEqual(files, [ fixpath('spam/file1.c'), fixpath('spam/file2.c'), fixpath('eggs/ham/file3.c'), ]) self.assertEqual(self.calls, [ ('_walk', ('spam', '.c', _walk_tree)), ('_walk', ('eggs', '.c', _walk_tree)), ])
def test_typical(self): dirnames = self.set_files( ('spam', ['file1.c', 'file2.c']), ('eggs', ['ham/file3.h']), ) suffixes = ('.c', '.h') files = list(iter_files(dirnames, suffixes, _glob=self._glob, _walk=self._walk)) self.assertEqual(files, [ fixpath('spam/file1.c'), fixpath('spam/file2.c'), fixpath('eggs/ham/file3.h'), ]) self.assertEqual(self.calls, [ ('_walk', ('spam', None, _walk_tree)), ('_walk', ('eggs', None, _walk_tree)), ])
def test_glob(self): dirnames = self.set_files( ('spam', ['file1.c', 'file2.c']), ('eggs', ['ham/file3.c']), ) files = list(iter_files(dirnames, '.c', get_files=glob_tree, _walk=self._walk, _glob=self._glob)) self.assertEqual(files, [ fixpath('spam/file1.c'), fixpath('spam/file2.c'), fixpath('eggs/ham/file3.c'), ]) self.assertEqual(self.calls, [ ('_glob', ('spam', '.c')), ('_glob', ('eggs', '.c')), ])
def test_alt_walk_func(self): dirnames = self.set_files( ('spam', ['file1.c', 'file2.c']), ('eggs', ['ham/file3.c']), ) def get_files(root): return None files = list(iter_files(dirnames, '.c', get_files=get_files, _walk=self._walk, _glob=self._glob)) self.assertEqual(files, [ fixpath('spam/file1.c'), fixpath('spam/file2.c'), fixpath('eggs/ham/file3.c'), ]) self.assertEqual(self.calls, [ ('_walk', ('spam', '.c', get_files)), ('_walk', ('eggs', '.c', get_files)), ])