def test_scandir_scandir(self): """Test example.scandir() which uses `scandir.scandir()`. The scandir module has been replaced with the fake_scandir module so the fake filesystem path entries are returned instead of `scandir.DirEntry` objects. """ self.fs.create_file('/test/text.txt') self.fs.create_dir('/test/dir') entries = sorted(example.scan_dir('/test'), key=lambda e: e.name) self.assertEqual(2, len(entries)) self.assertEqual('text.txt', entries[1].name) self.assertTrue(entries[0].is_dir()) self.assertTrue(entries[1].is_file())
def test_os_scandir(self): """Test example.scandir() which uses `os.scandir()`. The os module has been replaced with the fake os module so the fake filesystem path entries are returned instead of `os.DirEntry` objects. """ self.fs.create_file('/test/text.txt') self.fs.create_dir('/test/dir') self.fs.create_file('/linktest/linked') self.fs.create_symlink('/test/linked_file', '/linktest/linked') entries = sorted(example.scan_dir('/test'), key=lambda e: e.name) self.assertEqual(3, len(entries)) self.assertEqual('linked_file', entries[1].name) self.assertTrue(entries[0].is_dir()) self.assertTrue(entries[1].is_symlink()) self.assertTrue(entries[2].is_file())