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): self.empty_all_trashdirs = Mock() self.empty_trashdir = Mock() self.cmd = EmptyCmd(None, None, None, None, None, None, None, None, None) self.cmd.empty_all_trashdirs = self.empty_all_trashdirs self.cmd.empty_trashdir = self.empty_trashdir
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 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.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 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.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 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.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 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 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 empty(argv=sys.argv, stdout=sys.stdout, stderr=sys.stderr, environ=os.environ): from trashcli.empty import EmptyCmd from trashcli.list_mount_points import mount_points from datetime import datetime from trashcli.trash import FileSystemReader from trashcli.fs import FileRemover from trashcli.trash import version return EmptyCmd( out=stdout, err=stderr, environ=environ, list_volumes=mount_points, now=datetime.now, file_reader=FileSystemReader(), getuid=os.getuid, file_remover=FileRemover(), version=version, ).run(*argv)