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)
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)
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)
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)