def _test_encoding(self, fn): """Test encoding""" fullpath = self.write_file(fn) # Add Unicode paths to encourage a crash. subdir = os.path.join(self.tempdir, u'ɡælɪk.dir') os.mkdir(subdir) subfile = os.path.join(subdir, u'ɡælɪk.file') common.touch_file(subfile) ds = DeepScan() for use_unicode in (False, True): if use_unicode: search_dir = unicode(self.tempdir) else: search_dir = self.tempdir self.assertIsInstance(search_dir, str) ds.add_search(search_dir, '\.[Bb][Aa][Kk]$') found = False for ret in ds.scan(): if ret == True: # True is used to yield to GTK+, but it is not # needed in this test. continue self.assertExists(ret) if ret == fullpath: found = True self.assertTrue(found, u"Did not find '%s'" % fullpath) os.unlink(fullpath) self.assertNotExists(fullpath) import shutil shutil.rmtree(subdir)
def _test_encoding(self, fn): """Test encoding""" fullpath = self.write_file(fn) # Add Unicode paths to encourage a crash. subdir = os.path.join(self.tempdir, 'ɡælɪk.dir') os.mkdir(subdir) subfile = os.path.join(subdir, 'ɡælɪk.file') common.touch_file(subfile) searches = {self.tempdir: []} searches[self.tempdir].append( Search(command='delete', regex='\.[Bb][Aa][Kk]$')) ds = DeepScan(searches) found = False for cmd in ds.scan(): if cmd == True: # True is used to yield to GTK+, but it is not # needed in this test. continue self.assertExists(cmd.path) if cmd.path == fullpath: found = True self.assertTrue(found, "Did not find '%s'" % fullpath) os.unlink(fullpath) self.assertNotExists(fullpath) import shutil shutil.rmtree(subdir)
def test_DeepScan(self): """Unit test for class DeepScan. Preview real files.""" path = os.path.expanduser('~') searches = {path: []} for regex in ('^Makefile$', '~$', 'bak$', '^Thumbs.db$', '^Thumbs.db:encryptable$'): searches[path].append(Search(command='delete', regex=regex)) ds = DeepScan(searches) for cmd in ds.scan(): if True == cmd: # it's yielding control to the GTK idle loop continue self.assertLExists(cmd.path)
def test_DeepScan(self): """Unit test for class DeepScan. Preview real files.""" ds = DeepScan() path = expanduser('~') ds.add_search(path, '^Makefile$') ds.add_search(path, '~$') ds.add_search(path, 'bak$') ds.add_search(path, '^Thumbs.db$') ds.add_search(path, '^Thumbs.db:encryptable$') for ret in ds.scan(): if True == ret: # it's yielding control to the GTK idle loop continue self.assertLExists(ret)
def test_DeepScan(self): """Unit test for class DeepScan. Preview real files.""" ds = DeepScan() path = os.path.expanduser("~") ds.add_search(path, "^Makefile$") ds.add_search(path, "~$") ds.add_search(path, "bak$") ds.add_search(path, "^Thumbs.db$") ds.add_search(path, "^Thumbs.db:encryptable$") for ret in ds.scan(): if True == ret: # it's yielding control to the GTK idle loop continue self.assert_(isinstance(ret, (str, unicode)), "Expecting string but got '%s' (%s)" % (ret, str(type(ret)))) self.assert_(os.path.lexists(ret))
def test_DeepScan(self): """Unit test for class DeepScan. Preview real files.""" ds = DeepScan() path = os.path.expanduser('~') ds.add_search(path, '^Makefile$') ds.add_search(path, '~$') ds.add_search(path, 'bak$') ds.add_search(path, '^Thumbs.db$') ds.add_search(path, '^Thumbs.db:encryptable$') for ret in ds.scan(): if True == ret: # it's yielding control to the GTK idle loop continue self.assert_(isinstance(ret, (str, unicode)), "Expecting string but got '%s' (%s)" % (ret, str(type(ret)))) self.assert_(os.path.lexists(ret))
def _test_encoding(self, fn): """Test encoding""" fullpath = self.write_file(fn) ds = DeepScan() ds.add_search(self.tempdir, '^%s$' % fn) found = False for ret in ds.scan(): if True == ret: continue print(ret) self.assertEqual(ret, fullpath) found = True self.assertTrue(found, "Did not find '%s'" % fullpath) os.unlink(fullpath) self.assertNotExists(fullpath)
def test_DeepScan(self): """Unit test for class DeepScan. Preview real files.""" ds = DeepScan() path = expanduser('~') ds.add_search(path, '^Makefile$') ds.add_search(path, '~$') ds.add_search(path, 'bak$') ds.add_search(path, '^Thumbs.db$') ds.add_search(path, '^Thumbs.db:encryptable$') try: for ret in ds.scan(): if True == ret: # it's yielding control to the GTK idle loop continue self.assertLExists(ret) except UnicodeDecodeError: # Expectedly ds.scan() throws exception # when we have unicode paths and LANG==C. self.assertTrue(os.environ['LANG'] == 'C')
def _test_encoding(self, fn): """Test encoding""" tempd = tempfile.mkdtemp(prefix='bleachbit-test-deepscan') self.assert_(os.path.exists(tempd)) fullpath = os.path.join(tempd, fn) common.touch_file(fullpath) ds = DeepScan() ds.add_search(tempd, '^%s$' % fn) found = False for ret in ds.scan(): if True == ret: continue self.assert_(ret == fullpath) found = True self.assert_(found, "Did not find '%s'" % fullpath) os.unlink(fullpath) self.assert_(not os.path.exists(fullpath)) os.rmdir(tempd) self.assert_(not os.path.exists(tempd))