def test_empty(self): with self.os_mocks as (listdir, lstat, _): listdir.return_value = [] spider = Spider(self.fstree, '.') time.sleep(0.01) spider.stop() listdir.assert_called_with('.') self.assertFalse(lstat.called) self.assertFalse(self.fstree.add_path.called)
def test_one_file(self): with self.os_mocks as (listdir, lstat, S_ISDIR): listdir.return_value = ['foo'] lstat.return_value = self.file_stat S_ISDIR.return_value = False spider = Spider(self.fstree, '.') time.sleep(0.01) spider.stop() listdir.assert_called_with('.') lstat.assert_called_width('./foo') S_ISDIR.assert_called_with(self.file_stat.st_mode) self.fstree.add_path.assert_called_with('./foo', self.file_stat)
def test_recurse_into_dir(self): with self.os_mocks as (listdir, lstat, S_ISDIR): listdir.side_effect = values(['foo'], []) lstat.side_effect = values(self.dir_stat) S_ISDIR.side_effect = values(True) spider = Spider(self.fstree, '.') time.sleep(0.01) spider.stop() self.assertEqual(listdir.call_args_list, [ (('.', ), {}), (('./foo', ), {}), ]) self.assertEqual(lstat.call_args_list, [ (('./foo', ), {}), ]) self.assertEqual(S_ISDIR.call_args_list, [ ((self.dir_stat.st_mode, ), {}), ])
def test_recurse_into_dir(self): with self.os_mocks as (listdir, lstat, S_ISDIR): listdir.side_effect = values(['foo'], []) lstat.side_effect = values(self.dir_stat) S_ISDIR.side_effect = values(True) spider = Spider(self.fstree, '.') time.sleep(0.01) spider.stop() self.assertEqual(listdir.call_args_list, [ (('.',), {}), (('./foo',), {}), ]) self.assertEqual(lstat.call_args_list, [ (('./foo',), {}), ]) self.assertEqual(S_ISDIR.call_args_list, [ ((self.dir_stat.st_mode,), {}), ])