def test_rm_with_one_nonexistant(self): write('existant', 'contents') self.assertRaises(FileNotFoundError, lambda: rm('existant', 'nonexistant')) self.assertEqual(['existant'], ls()) rm('existant', 'nonexistant', ignore_missing=True) self.assertEqual([], ls())
def test_mv_single_file_to_nonexistant_folder(self): write('file', 'contents') self.assertRaises(RuntimeError, lambda: move_to('file', 'folder', create_dir=False)) move_to('file', 'folder') self.assertEqual(['folder'], ls()) self.assertEqual(['file'], ls('folder')) self.assertEqual('contents', read('folder/file')) rm('folder', recursively=True)
def test_mv_single_file_to_existing_folder(self): write('file', 'contents') mkdir('folder') move_to('file', 'folder') self.assertEqual(['folder'], ls()) self.assertEqual(['file'], ls('folder')) self.assertEqual('contents', read('folder/file')) rm('folder', recursively=True)
def test_rm_with_one_with_contents(self): write('existant', 'contents') mkdir('folder') write('folder/file', 'contents') self.assertRaises(CannotRemoveDirectoryError, lambda: rm('existant', 'folder', interactive=False)) self.assertEqual(['existant', 'folder'], ls()) rm('existant', 'folder', recursively=True) self.assertEqual([], ls())
def test_mv_dst_exists(self): write('src', 'abc') write('file', 'def') self.assertRaises(RuntimeError, lambda: mv('src', 'file')) self.assertEqual(['file', 'src'], ls()) mv('src', 'file', overwrite=True) self.assertEqual(['file'], ls()) self.assertEqual('abc', read('file')) rm('file')
def test_rm_nonemptydir(self): mkdir('path') write('path/file', 'contents') self.assertRaises(CannotRemoveDirectoryError, lambda: rm('path', interactive=False)) self.assertEqual(['path'], ls()) rm('path', recursively=True) self.assertEqual([], ls()) mkdir('path') write('path/file', '') Interactive.ask_question = lambda _: "n" rm('path') self.assertEqual(['path'], ls()) Interactive.ask_question = lambda _: "y" rm("path") self.assertEqual([], ls())
def modified(self, *args): cd(INITIAL_PWD) cd('..') system('rm -r tests') mkdir('tests') cd('tests') fn(self, *args) self.assertEqual(INITIAL_PWD, pwd()) self.assertEqual(ls(), [])
def test_mv_dst_folder_doesnt_exist(self): write('src', 'abc') mv('src', 'folder/file') self.assertEqual(['folder'], ls()) self.assertEqual(['file'], ls('folder')) self.assertEqual('abc', read('folder/file')) mv('folder/file', 'folder/to/a/file') self.assertEqual(['folder'], ls()) self.assertEqual(['to'], ls('folder')) self.assertEqual(['a'], ls('folder/to')) self.assertEqual(['file'], ls('folder/to/a')) self.assertEqual('abc', read('folder/to/a/file')) rm('folder', recursively=True)
def test_rm_symlink_to_folder(self): mkdir('folder') symlink('folder', 'link') rm('link') self.assertEqual(['folder'], ls()) rm('folder')
def test_rm_symlink(self): write('file', 'contents') symlink('file', 'link') rm('link') self.assertEqual(['file'], ls()) rm('file')
def test_rmdir(self): mkdir('empty-folder') rm('empty-folder') self.assertEqual([], ls())
def test_chaining(self): write('test', '') and write('test2', '') self.assertEqual(ls(), ['test', 'test2']) rm('test', 'test2')