def run(self, *argv): file_reader = FileSystemReader() file_reader.list_volumes = lambda: self.volumes ListCmd( out=self.stdout, err=self.stderr, environ=self.environ, getuid=self.fake_getuid, file_reader=file_reader, list_volumes=lambda: self.volumes, ).run(*argv)
def run(self, *argv): file_reader = FileSystemReader() file_reader.list_volumes = lambda: self.volumes volumes_listing = Mock(spec=VolumesListing) volumes_listing.list_volumes.return_value = self.volumes ListCmd( out=self.stdout, err=self.stderr, environ=self.environ, getuid=self.fake_getuid, file_reader=file_reader, volumes_listing=volumes_listing, ).run(*argv)
def test_help_output(self): err, out = StringIO(), StringIO() cmd = EmptyCmd( err=err, out=out, environ={}, list_volumes=no_volumes, now=None, file_reader=FileSystemReader(), getuid=None, file_remover=None, version=None, ) cmd.run('trash-empty', '--help') assert_equal( out.getvalue(), dedent("""\ Usage: trash-empty [days] Purge trashed files. Options: --version show program's version number and exit -h, --help show this help message and exit Report bugs to https://github.com/andreafrancia/trash-cli/issues """))
def setUp(self): require_empty_dir('sandbox') self.out = Mock() self.listing = ListTrashinfos(self.out, FileSystemReader(), None) self.index = 0
def run(self, argv): args = argv[1:] self.exit_code = 0 if not args: self.stderr.write('Usage:\n' ' trash-rm PATTERN\n' '\n' 'Please specify PATTERN\n') self.exit_code = 8 return trashcan = CleanableTrashcan(FileRemover()) cmd = Filter(trashcan.delete_trashinfo_and_backup_copy) cmd.use_pattern(args[0]) file_reader = FileSystemReader() listing = ListTrashinfos(cmd.delete_if_matches) top_trashdir_rules = TopTrashDirRules(file_reader) trashdirs = TrashDirs(self.environ, self.getuid, list_volumes=self.list_volumes, top_trashdir_rules=top_trashdir_rules) trashdirs.on_trash_dir_found = listing.list_from_volume_trashdir trashdirs.list_trashdirs()
def setUp(self): require_empty_dir('sandbox/xdh') self.stderr = StringIO() self.trash_rm = RmCmd(environ = {'XDG_DATA_HOME':'sandbox/xdh'} , getuid = 123 , list_volumes = lambda:[] , stderr = self.stderr , file_reader = FileSystemReader())
def setUp(self): self.xdg_data_home = MyPath.make_temp_dir() self.stderr = StringIO() self.trash_rm = RmCmd(environ={'XDG_DATA_HOME': self.xdg_data_home}, getuid=123, list_volumes=lambda: [], stderr=self.stderr, file_reader=FileSystemReader())
def setUp(self): self.xdg_data_home = MyPath.make_temp_dir() self.stderr = StringIO() self.trash_rm = RmCmd(environ={'XDG_DATA_HOME': self.xdg_data_home}, getuid=lambda: 123, volumes_listing=VolumesListing(lambda: []), stderr=self.stderr, file_reader=FileSystemReader()) self.fake_trash_dir = FakeTrashDir(self.xdg_data_home / 'Trash')
def main(): from trashcli.list_mount_points import os_mount_points cmd = RmCmd(environ = os.environ , getuid = os.getuid , list_volumes = os_mount_points , stderr = sys.stderr , file_reader = FileSystemReader()) cmd.run(sys.argv) return cmd.exit_code
def setUp(self): require_empty_dir('topdir') self.empty=EmptyCmd( out = StringIO(), err = StringIO(), environ = {}, list_volumes = lambda: ['topdir'], now = None, file_reader = FileSystemReader(), getuid = lambda: 123, file_remover = FileRemover(), version = None, )
def setUp(self): self.err, self.out = StringIO(), StringIO() self.cmd = EmptyCmd( err = self.err, out = self.out, environ = {}, list_volumes = no_volumes, now = None, file_reader = FileSystemReader(), getuid = None, file_remover = None, version = None, )
def main(): from trashcli.list_mount_points import os_mount_points from trashcli.fstab import VolumesListing volumes_listing = VolumesListing(os_mount_points) cmd = RmCmd(environ=os.environ, getuid=os.getuid, volumes_listing=volumes_listing, stderr=sys.stderr, file_reader=FileSystemReader()) cmd.run(sys.argv) return cmd.exit_code
def main(argv=sys.argv, stdout=sys.stdout, stderr=sys.stderr, environ=os.environ): return EmptyCmd(out=stdout, err=stderr, environ=environ, volumes_listing=VolumesListing(os_mount_points), now=datetime.now, file_reader=FileSystemReader(), getuid=os.getuid, file_remover=FileRemover(), version=trash.version, volume_of=volume_of).run(*argv)
def setUp(self): self.temp_dir = MyPath.make_temp_dir() self.top_dir = self.temp_dir / 'topdir' require_empty_dir(self.top_dir) self.empty = EmptyCmd( out=StringIO(), err=StringIO(), environ={}, list_volumes=lambda: [self.top_dir], now=None, file_reader=FileSystemReader(), getuid=lambda: 123, file_remover=FileRemover(), version=None, )
def setUp(self): require_empty_dir('XDG_DATA_HOME') self.xdg_data_home = 'XDG_DATA_HOME' self.environ = {'XDG_DATA_HOME':'XDG_DATA_HOME'} self.now = MagicMock(side_effect=RuntimeError) self.empty_cmd=EmptyCmd( out = StringIO(), err = StringIO(), environ = self.environ, list_volumes = no_volumes, now = self.now, file_reader = FileSystemReader(), getuid = None, file_remover = FileRemover(), version = None, )
def test_it_print_version(self): err, out = StringIO(), StringIO() cmd = EmptyCmd(err = err, out = out, environ = {}, list_volumes = no_volumes, now = None, file_reader = FileSystemReader(), getuid = None, file_remover = None, version = '1.2.3', ) cmd.run('trash-empty', '--version') assert_equal(out.getvalue(), dedent("""\ trash-empty 1.2.3 """))
def setUp(self): require_empty_dir('XDG_DATA_HOME') self.info_dir_path = 'XDG_DATA_HOME/Trash/info' self.files_dir_path = 'XDG_DATA_HOME/Trash/files' self.environ = {'XDG_DATA_HOME':'XDG_DATA_HOME'} now = MagicMock(side_effect=RuntimeError) self.empty_cmd = EmptyCmd( out = StringIO(), err = StringIO(), environ = self.environ, list_volumes = no_volumes, now = now, file_reader = FileSystemReader(), getuid = None, file_remover = FileRemover(), version = None, )
def setUp(self): self.tmp_dir = MyPath.make_temp_dir() self.unreadable_dir = self.tmp_dir / 'data/Trash/files/unreadable' self.volumes_listing = Mock(spec=VolumesListing) self.volumes_listing.list_volumes.return_value = [self.unreadable_dir] self.err=StringIO() self.empty = EmptyCmd( out=StringIO(), err=self.err, environ={'XDG_DATA_HOME':self.tmp_dir / 'data'}, volumes_listing=self.volumes_listing, now=None, file_reader=FileSystemReader(), getuid=lambda: 123, file_remover=FileRemover(), version=None, volume_of=lambda x: "volume_of %s" % x )
def setUp(self): self.temp_dir = MyPath.make_temp_dir() self.top_dir = self.temp_dir / 'topdir' self.volumes_listing = Mock(spec=VolumesListing) self.volumes_listing.list_volumes.return_value = [self.top_dir] require_empty_dir(self.top_dir) self.empty = EmptyCmd( out=StringIO(), err=StringIO(), environ={}, volumes_listing=self.volumes_listing, now=None, file_reader=FileSystemReader(), getuid=lambda: 123, file_remover=FileRemover(), version=None, volume_of=lambda x: "volume_of %s" % x )
def test_trash_empty_last_line(self): from trashcli.empty import EmptyCmd from trashcli.fs import FileSystemReader cmd = EmptyCmd( self.out, StringIO(), [], lambda: [], now=None, file_reader=FileSystemReader(), getuid=None, file_remover=None, version=None, ) cmd.run('', '--help') self.assert_last_line_of_output_is( 'Report bugs to https://github.com/andreafrancia/trash-cli/issues')
def main(argv=sys.argv, stdout=sys.stdout, stderr=sys.stderr, environ=os.environ): from trashcli.list_mount_points import os_mount_points from datetime import datetime from trashcli.fs import FileSystemReader from trashcli.fs import FileRemover from trashcli.trash import version return EmptyCmd( out=stdout, err=stderr, environ=environ, list_volumes=os_mount_points, now=datetime.now, file_reader=FileSystemReader(), getuid=os.getuid, file_remover=FileRemover(), version=version, ).run(*argv)
def setUp(self): self.tmp_dir = MyPath.make_temp_dir() self.trash_dir = self.tmp_dir / 'Trash' self.out = Mock() self.listing = ListTrashinfos(self.out, FileSystemReader(), None) self.index = 0
def _report_original_location(self, trashinfo_path): file_reader = FileSystemReader() trashinfo = file_reader.contents_of(trashinfo_path) path = parse_path(trashinfo) complete_path = os.path.join(self.volume, path) self.out(complete_path, trashinfo_path)
run('chmod +t sandbox/sticky') assert has_sticky_bit('sandbox/sticky') def test_has_sticky_bit_returns_false(self): make_empty_file("sandbox/non-sticky") run('chmod -t sandbox/non-sticky') assert not has_sticky_bit("sandbox/non-sticky") def setUp(self): require_empty_dir('sandbox') is_sticky_dir = FileSystemReader().is_sticky_dir class Test_is_sticky_dir: def test_dir_non_sticky(self): mkdirs('sandbox/dir') assert not is_sticky_dir('sandbox/dir') def test_dir_sticky(self): mkdirs('sandbox/dir') set_sticky_bit('sandbox/dir') assert is_sticky_dir('sandbox/dir') def test_non_dir_but_sticky(self): make_empty_file('sandbox/dir') set_sticky_bit('sandbox/dir')
def setUp(self): self.tmp_dir = MyPath.make_temp_dir() self.trash_dir = self.tmp_dir / 'Trash' self.fake_trash_dir = FakeTrashDir(self.trash_dir) self.listing = ListTrashinfos(FileSystemReader())
def list_from_volume_trashdir(self, trashdir_path, volume): self.volume = volume self.trashdir = TrashDir(FileSystemReader()) self.trashdir.open(trashdir_path, volume) self.trashdir.each_trashinfo(self._report_original_location)