Пример #1
0
    def test_multiple_options(self):
        """Test one cleaner with two options"""
        ui = CLI.CliCallback()
        (fd, filename1) = tempfile.mkstemp(prefix='bleachbit-test-worker')
        os.close(fd)
        self.assert_(os.path.exists(filename1))
        (fd, filename2) = tempfile.mkstemp(prefix='bleachbit-test-worker')
        os.close(fd)
        self.assert_(os.path.exists(filename2))

        astr1 = '<action command="delete" search="file" path="%s"/>' % filename1
        astr2 = '<action command="delete" search="file" path="%s"/>' % filename2
        cleaner = TestCleaner.actions_to_cleaner([astr1, astr2])
        backends['test'] = cleaner
        operations = {'test': ['option1', 'option2']}
        worker = Worker(ui, True, operations)
        run = worker.run()
        while run.next():
            pass
        self.assert_(not os.path.exists(filename1),
                     "Path still exists '%s'" % filename1)
        self.assert_(not os.path.exists(filename2),
                     "Path still exists '%s'" % filename2)
        self.assertEqual(worker.total_special, 0)
        self.assertEqual(worker.total_errors, 0)
        self.assertEqual(worker.total_deleted, 2)
Пример #2
0
    def test_deep_scan(self):
        """Test for deep scan"""

        # load cleaners from XML
        import bleachbit.CleanerML
        bleachbit.CleanerML.load_cleaners()

        # DeepScan itself is tested elsewhere, so replace it here
        import bleachbit.DeepScan
        SaveDeepScan = bleachbit.DeepScan.DeepScan
        self.scanned = 0
        parent = self

        class MyDeepScan:
            def add_search(self, dirname, regex):
                parent.assertEqual(dirname, expanduser('~'))
                parent.assertIn(regex, ['^Thumbs\\.db$', '^Thumbs\\.db:encryptable$'])

            def scan(self):
                parent.scanned+=1
                yield True

        bleachbit.DeepScan.DeepScan = MyDeepScan

        # test
        operations = {'deepscan': ['thumbs_db']}
        ui = CLI.CliCallback()
        worker = Worker(ui, False, operations).run()
        while worker.next():
            pass
        self.assertEqual(1, self.scanned)

        # clean up
        bleachbit.DeepScan.DeepScan = SaveDeepScan
Пример #3
0
 def action_test_helper(self, command, special_expected, errors_expected,
                        bytes_expected_posix, count_deleted_posix,
                        bytes_expected_nt, count_deleted_nt):
     ui = CLI.CliCallback()
     (fd, filename) = tempfile.mkstemp(prefix='bleachbit-test-worker')
     os.write(fd, '123')
     os.close(fd)
     self.assert_(os.path.exists(filename))
     astr = '<action command="%s" path="%s"/>' % (command, filename)
     cleaner = TestCleaner.action_to_cleaner(astr)
     backends['test'] = cleaner
     operations = {'test': ['option1']}
     worker = Worker(ui, True, operations)
     run = worker.run()
     while run.next():
         pass
     self.assert_(not os.path.exists(filename),
                  "Path still exists '%s'" % filename)
     self.assertEqual(worker.total_special, special_expected,
                      'For command %s expecting %s special operations but observed %d'
                      % (command, special_expected, worker.total_special))
     self.assertEqual(worker.total_errors, errors_expected,
                      'For command %s expecting %d errors but observed %d'
                      % (command, errors_expected, worker.total_errors))
     if 'posix' == os.name:
         self.assertEqual(worker.total_bytes, bytes_expected_posix)
         self.assertEqual(worker.total_deleted, count_deleted_posix)
     elif 'nt' == os.name:
         self.assertEqual(worker.total_bytes, bytes_expected_nt)
         self.assertEqual(worker.total_deleted, count_deleted_nt)
Пример #4
0
 def test_TestActionProvider(self):
     """Test Worker using Action.TestActionProvider"""
     ui = CLI.CliCallback()
     (fd, filename) = tempfile.mkstemp('bleachbit-test')
     os.write(fd, '123')
     os.close(fd)
     self.assert_(os.path.exists(filename))
     astr = '<action command="test" path="%s"/>' % filename
     cleaner = TestCleaner.action_to_cleaner(astr)
     backends['test'] = cleaner
     operations = {'test': ['option1']}
     worker = Worker(ui, True, operations)
     run = worker.run()
     while run.next():
         pass
     self.assert_(not os.path.exists(filename),
                  "Path still exists '%s'" % filename)
     self.assertEqual(worker.total_special, 3)
     self.assertEqual(worker.total_errors, 2)
     if 'posix' == os.name:
         self.assertEqual(worker.total_bytes, 4096 + 10 + 10)
         self.assertEqual(worker.total_deleted, 3)
     elif 'nt' == os.name:
         self.assertEqual(worker.total_bytes, 3 + 3 + 10 + 10)
         self.assertEqual(worker.total_deleted, 4)
Пример #5
0
 def test_TestActionProvider(self):
     """Test Worker using Action.TestActionProvider"""
     ui = CLI.CliCallback()
     (fd, filename) = tempfile.mkstemp('bleachbit-test')
     os.write(fd, '123')
     os.close(fd)
     self.assert_(os.path.exists(filename))
     astr = '<action command="test" path="%s"/>' % filename
     cleaner = TestCleaner.action_to_cleaner(astr)
     backends['test'] = cleaner
     operations = { 'test' : [ 'option1' ] }
     worker = Worker(ui, True, operations)
     run = worker.run()
     while run.next():
         pass
     self.assert_(not os.path.exists(filename), \
         "Path still exists '%s'" % filename)
     self.assertEqual(worker.total_special, 3)
     self.assertEqual(worker.total_errors, 2)
     if 'posix' == os.name:
         self.assertEqual(worker.total_bytes, 4096+10+10)
         self.assertEqual(worker.total_deleted, 3)
     elif 'nt' == os.name:
         self.assertEqual(worker.total_bytes, 3+3+10+10)
         self.assertEqual(worker.total_deleted, 4)
Пример #6
0
    def preview_or_run_operations(self, really_delete, operations=None):
        """Preview operations or run operations (delete files)"""

        assert isinstance(really_delete, bool)
        from bleachbit import Worker
        self.start_time = None
        if not operations:
            operations = {}
            for operation in self.get_selected_operations():
                operations[operation] = self.get_operation_options(operation)
        assert isinstance(operations, dict)
        if not operations:  # empty
            GuiBasic.message_dialog(self,
                                    _("You must select an operation"),
                                    Gtk.MessageType.WARNING, Gtk.ButtonsType.OK)
            return
        try:
            self.set_sensitive(False)
            self.textbuffer.set_text("")
            self.progressbar.show()
            self.worker = Worker.Worker(self, really_delete, operations)
        except Exception:
            logger.exception('Error in Worker()')
        else:
            self.start_time = time.time()
            worker = self.worker.run()
            GLib.idle_add(worker.__next__)
Пример #7
0
    def preview_or_run_operations(self, really_delete, operations=None):
        """Preview operations or run operations (delete files)"""

        assert (isinstance(really_delete, bool))
        from bleachbit import Worker
        self.start_time = None
        if None == operations:
            operations = {}
            for operation in self.get_selected_operations():
                operations[operation] = self.get_operation_options(operation)
        assert (isinstance(operations, dict))
        if 0 == len(operations):
            GuiBasic.message_dialog(self.window,
                                    _("You must select an operation"),
                                    gtk.MESSAGE_WARNING, gtk.BUTTONS_OK)
            return
        try:
            self.set_sensitive(False)
            self.textbuffer.set_text("")
            self.progressbar.show()
            self.worker = Worker.Worker(self, really_delete, operations)
        except Exception:
            logger.exception('Error in Worker()')
        else:
            self.start_time = time.time()
            worker = self.worker.run()
            gobject.idle_add(worker.next)
Пример #8
0
    def test_multiple_options(self):
        """Test one cleaner with two options"""
        ui = CLI.CliCallback()
        filename1 = self.mkstemp(prefix='bleachbit-test-worker')
        filename2 = self.mkstemp(prefix='bleachbit-test-worker')

        astr1 = '<action command="delete" search="file" path="%s"/>' % filename1
        astr2 = '<action command="delete" search="file" path="%s"/>' % filename2
        cleaner = TestCleaner.actions_to_cleaner([astr1, astr2])
        backends['test'] = cleaner
        operations = {'test': ['option1', 'option2']}
        worker = Worker(ui, True, operations)
        run = worker.run()
        while next(run):
            pass
        del backends['test']
        self.assertNotExists(filename1)
        self.assertNotExists(filename2)
        self.assertEqual(worker.total_special, 0)
        self.assertEqual(worker.total_errors, 0)
        self.assertEqual(worker.total_deleted, 2)
Пример #9
0
    def test_deep_scan(self):
        """Test for deep scan"""

        # load cleaners from XML
        import bleachbit.CleanerML
        list(bleachbit.CleanerML.load_cleaners())

        # DeepScan itself is tested elsewhere, so replace it here
        import bleachbit.DeepScan
        SaveDeepScan = bleachbit.DeepScan.DeepScan
        self.scanned = 0
        parent = self

        class MyDeepScan:
            def __init__(self, searches):
                for (path, searches) in searches.items():
                    parent.assertEqual(path, os.path.expanduser('~'))
                    for s in searches:
                        parent.assertIn(
                            s.regex,
                            ['^Thumbs\\.db$', '^Thumbs\\.db:encryptable$'])

            def scan(self):
                parent.scanned += 1
                yield True

        bleachbit.DeepScan.DeepScan = MyDeepScan

        # test
        operations = {'deepscan': ['thumbs_db']}
        ui = CLI.CliCallback()
        worker = Worker(ui, False, operations).run()
        while next(worker):
            pass
        self.assertEqual(1, self.scanned)

        # clean up
        bleachbit.DeepScan.DeepScan = SaveDeepScan
Пример #10
0
def preview_or_clean(operations, really_clean):
    """Preview deletes and other changes"""
    cb = CliCallback()
    worker = Worker.Worker(cb, really_clean, operations).run()
    while worker.next():
        pass