Exemple #1
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)
Exemple #2
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)
 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)
Exemple #4
0
    def test_delete(self):
        """Delete files in a test environment"""

        # make some files
        base = os.path.expanduser("~/bleachbit-deepscan-test")
        if os.path.exists(base):
            shutil.rmtree(base)
        os.mkdir(base)
        f_del1 = os.path.join(base, "foo.txt.bbtestbak")
        file(f_del1, "w").write("")
        f_keep = os.path.join(base, "foo.txt")
        file(f_keep, "w").write("")
        subdir = os.path.join(base, "sub")
        os.mkdir(subdir)
        f_del2 = os.path.join(base, "sub/bar.ini.bbtestbak")
        file(f_del2, "w").write("")

        # sanity check
        self.assert_(os.path.exists(f_del1))
        self.assert_(os.path.exists(f_keep))
        self.assert_(os.path.exists(f_del2))

        # run deep scan
        astr = '<action command="delete" search="deep" regex="\.bbtestbak$" cache="false"/>'
        import TestCleaner

        cleaner = TestCleaner.action_to_cleaner(astr)
        from bleachbit.Worker import backends, Worker

        backends["test"] = cleaner
        operations = {"test": ["option1"]}
        from bleachbit import CLI

        ui = CLI.CliCallback()
        worker = Worker(ui, True, operations)
        run = worker.run()
        while run.next():
            pass

        # validate results
        self.assert_(not os.path.exists(f_del1))
        self.assert_(os.path.exists(f_keep))
        self.assert_(not os.path.exists(f_del2))

        # clean up
        shutil.rmtree(base)
Exemple #5
0
    def test_delete(self):
        """Delete files in a test environment"""

        # make some files
        base = os.path.expanduser('~/bleachbit-deepscan-test')
        if os.path.exists(base):
            shutil.rmtree(base)
        os.mkdir(base)
        f_del1 = os.path.join(base, 'foo.txt.bbtestbak')
        file(f_del1, 'w').write('')
        f_keep = os.path.join(base, 'foo.txt')
        file(f_keep, 'w').write('')
        subdir = os.path.join(base, 'sub')
        os.mkdir(subdir)
        f_del2 = os.path.join(base, 'sub/bar.ini.bbtestbak')
        file(f_del2, 'w').write('')

        # sanity check
        self.assert_(os.path.exists(f_del1))
        self.assert_(os.path.exists(f_keep))
        self.assert_(os.path.exists(f_del2))

        # run deep scan
        astr = '<action command="delete" search="deep" regex="\.bbtestbak$" cache="false"/>'
        import TestCleaner
        cleaner = TestCleaner.action_to_cleaner(astr)
        from bleachbit.Worker import backends, Worker
        backends['test'] = cleaner
        operations = {'test': ['option1']}
        from bleachbit import CLI
        ui = CLI.CliCallback()
        worker = Worker(ui, True, operations)
        run = worker.run()
        while run.next():
            pass

        # validate results
        self.assert_(not os.path.exists(f_del1))
        self.assert_(os.path.exists(f_keep))
        self.assert_(not os.path.exists(f_del2))

        # clean up
        shutil.rmtree(base)