Beispiel #1
0
    def test_should_work_with_non_empty_dirs(self, stat, walk):
        walk.return_value = [
            ('virtual', ['dir'], []),
            ('virtual/dir', [], ['123.file'])
        ]
        path123 = 'virtual/dir/123.file'

        files = list(sut.files_of_dir('virtual'))
        self.assertEqual(len(stat.mock_calls), 1)
        self.assertEqual(len(walk.mock_calls), 1)
        stat.assert_called_once_with(path123)
        self.assertEqual(list(map(lambda e: e.path, files)), [path123])
Beispiel #2
0
 def test_should_respect_is_excluded(self, stat, walk):
     def exclude_dotfindd(path):
         return basename(path) == '.findd'
     walk.return_value = [
         ('virtual', ['.findd'], ['root.file']),
     ]
     is_excluded = Mock(side_effect=exclude_dotfindd)
     files = list(sut.files_of_dir('virtual', is_excluded=is_excluded))
     self.assertEqual(len(walk.mock_calls), 1)
     self.assertEqual(len(is_excluded.mock_calls), 2)
     self.assertEqual(len(stat.mock_calls), 1)
     self.assertEqual(walk.return_value[0][1], [])
     paths = list(map(lambda e: e.path, files))
     self.assertEqual(paths, [join('virtual', 'root.file')])
Beispiel #3
0
 def _step1_scan_fs(self):
     progress = Progress('scanning fs')
     __LOG__.debug('scanning %s', quote(self.base_dir))
     new_files_found = 0
     progress.start(self)
     for entry in files_of_dir(self.base_dir, self.is_excluded):
         progress.update(self)
         rel_path = os.path.relpath(entry.path, self.base_dir)
         if rel_path not in self.visited_files:
             new_files_found = new_files_found + 1
             db_file = model.File(
                 path=u(rel_path),
                 mtime=int(entry.stats.st_mtime),
                 size=entry.stats.st_size,
             )
             self.hash_queue.append(
                 entry.path,
                 entry.stats.st_size,
                 db_file
             )
     progress.finish(self)
     __LOG__.debug('%d new files found', new_files_found)
     return new_files_found
Beispiel #4
0
 def test_should_work_with_empty_dirs(self, walk):
     walk.return_value = [('virtual', [], [])]
     self.assertEqual(list(sut.files_of_dir('virtual')), [])
     self.assertEqual(len(walk.mock_calls), 1)