def test_the_attempt_of_deleting_a_dot_directory_should_signaled_as_error(self): argument="." class StubReporter: def __init__(self): self.has_been_called=False def unable_to_trash_dot_entries(self,file): self.has_been_called=True assert_equals(file, argument) reporter=StubReporter() trashcan = GlobalTrashCan(reporter=reporter) trashcan.trash('.') assert_true(reporter.has_been_called)
class TrashPutCmd: def __init__(self, stdout, stderr): self.stdout=stdout self.stderr=stderr def run(self,argv): parser = self.get_option_parser() (options, args) = parser.parse_args(argv[1:]) if len(args) <= 0: parser.error("Please specify the files to trash.") reporter=Reporter(self.get_logger(options.verbose,argv[0])) self.trashcan=GlobalTrashCan(reporter=reporter) self.trash_all(args) def trash_all(self, args): for arg in args : self.trash(arg) def trash(self, arg): self.trashcan.trash(Path(arg)) def get_option_parser(self): from trashcli import version from optparse import OptionParser from trashcli.cli.util import NoWrapFormatter parser = OptionParser(usage="%prog [OPTION]... FILE...", description="Put files in trash", version="%%prog %s" % version, formatter=NoWrapFormatter(), epilog= """To remove a file whose name starts with a `-', for example `-foo', use one of these commands: trash -- -foo trash ./-foo Report bugs to http://code.google.com/p/trash-cli/issues""") parser.add_option("-d", "--directory", action="store_true", help="ignored (for GNU rm compatibility)") parser.add_option("-f", "--force", action="store_true", help="ignored (for GNU rm compatibility)") parser.add_option("-i", "--interactive", action="store_true", help="ignored (for GNU rm compatibility)") parser.add_option("-r", "-R", "--recursive", action="store_true", help="ignored (for GNU rm compatibility)") parser.add_option("-v", "--verbose", action="store_true", help="explain what is being done", dest="verbose") return parser def get_logger(self,verbose,argv0): import os.path class MyLogger: def __init__(self, stderr): self.program_name = os.path.basename(argv0) self.stderr=stderr def info(self,message): if verbose: self.emit(message) def warning(self,message): self.emit(message) def emit(self, message): self.stderr.write("%s: %s\n" % (self.program_name,message)) return MyLogger(self.stderr)