def test_restore_with_relative_path(self): self.fake_trash_dir.add_trashed_file( "file1", pj(self.curdir, "path", "to", "file1"), "contents") self.assertEqual( True, file_exists(pj(self.trash_dir, "info", "file1.trashinfo"))) self.assertEqual(True, file_exists(pj(self.trash_dir, "files", "file1"))) result = self.run_command( "trash-restore", ["%(curdir)s" % { 'curdir': "." }, '--sort=path'], input='0') self.assertEqual( """\ 0 2000-01-01 00:00:01 %(curdir)s/path/to/file1 What file to restore [0..0]: """ % {'curdir': self.curdir}, result.stdout) self.assertEqual("", result.stderr) self.assertEqual("contents", read_file(pj(self.curdir, "path/to/file1"))) self.assertEqual( False, file_exists(pj(self.trash_dir, "info", "file1.trashinfo"))) self.assertEqual(False, file_exists(pj(self.trash_dir, "files", "file1")))
def main(): scripts = Scripts(write_file, make_file_executable) scripts.add_script('trash', 'trashcli.put', 'main') scripts.add_script('trash-put', 'trashcli.put', 'main') scripts.add_script('trash-list', 'trashcli.list', 'main') scripts.add_script('trash-restore', 'trashcli.restore', 'main') scripts.add_script('trash-empty', 'trashcli.empty', 'main') scripts.add_script('trash-rm', 'trashcli.rm', 'main') setup( name='trash-cli', version=trash.version, author='Andrea Francia', author_email='*****@*****.**', url='https://github.com/andreafrancia/trash-cli', description='Command line interface to FreeDesktop.org Trash.', long_description=read_file("README.rst"), license='GPL v2', packages=['trashcli'], scripts=scripts.created_scripts, data_files=[('share/man/man1', ['man/man1/trash-empty.1', 'man/man1/trash-list.1', 'man/man1/trash-restore.1', 'man/man1/trash.1', 'man/man1/trash-put.1', 'man/man1/trash-rm.1'])], install_requires=[ 'psutil', ], )
def save_new_version(new_version, path): content = read_file(path) new_content = re.sub(r'^version(\s*)=.*', 'version = \'%s\'' % new_version, content, flags=re.MULTILINE) write_file(path, new_content)
def test_persist_trash_info_first_100_times(self): self.test_persist_trash_info_first_time() trash_info_file = self.info_dir.persist_trash_info( 'dummy-path', b'content') assert self.path / 'dummy-path.suffix-1.trashinfo' == trash_info_file assert 'content' == read_file(trash_info_file)
def test2(self): make_file( self.tmp_dir / 'trash.py', """\ somecode before version="0.20.1.20" somecode after """) bump.save_new_version('0.21.5.11', self.tmp_dir / 'trash.py') result = read_file(self.tmp_dir / "trash.py") assert result == """\
def test_a_trashinfo_file_should_have_been_created(self): read_file(self.temp_dir / 'XDG_DATA_HOME/Trash/info/foo.trashinfo')
def test(self): path = self.tmp_dir / "unreadable" make_unreadable_file(self.tmp_dir / "unreadable") with self.assertRaises(IOError): read_file(path)
def test_short_filename(self): path = self.temp_dir / 'a' atomic_write(path, b'contents') assert 'contents' == read_file(path)