Rewriten as class Sweeper with code improvements and optimizations.
This commit is contained in:
parent
41cd0fe6c6
commit
0c04f67b93
5 changed files with 243 additions and 264 deletions
|
|
@ -3,7 +3,7 @@
|
|||
# License: GPLv3
|
||||
|
||||
import unittest
|
||||
from sweeper import file_dups, iter_file_dups
|
||||
from sweeper import Sweeper
|
||||
import os
|
||||
|
||||
mydir = os.path.dirname(os.path.realpath(__file__))
|
||||
|
|
@ -11,7 +11,8 @@ mydir = os.path.dirname(os.path.realpath(__file__))
|
|||
|
||||
class TestSweeper(unittest.TestCase):
|
||||
def test_file_dups_dups(self):
|
||||
dups = file_dups([os.path.join(mydir, 'testfiles_dups')])
|
||||
swp = Sweeper(topdirs=[os.path.join(mydir, 'testfiles_dups')])
|
||||
dups = swp.file_dups()
|
||||
dups_exist = False
|
||||
for h, flist in dups.items():
|
||||
if len(flist) > 1:
|
||||
|
|
@ -19,24 +20,26 @@ class TestSweeper(unittest.TestCase):
|
|||
self.assertTrue(dups_exist)
|
||||
|
||||
def test_file_dups_nodups(self):
|
||||
dups = file_dups([os.path.join(mydir, 'testfiles_nodups')])
|
||||
swp = Sweeper(topdirs=[os.path.join(mydir, 'testfiles_nodups')])
|
||||
dups = swp.file_dups()
|
||||
for h, flist in dups.items():
|
||||
self.assertTrue(len(flist) == 1)
|
||||
|
||||
# does not actually test safe_mode, we would need to find
|
||||
# hash collision
|
||||
def test_file_dups_safe_mode(self):
|
||||
dups = file_dups([os.path.join(mydir, 'testfiles_dups')],
|
||||
safe_mode=True)
|
||||
swp = Sweeper(topdirs=[os.path.join(mydir, 'testfiles_dups')],
|
||||
safe_mode=True)
|
||||
dups = swp.file_dups()
|
||||
for h, flist in dups.items():
|
||||
if len(flist) > 1:
|
||||
dups_exist = True
|
||||
self.assertTrue(dups_exist)
|
||||
|
||||
def test_iter_file_dups_dups(self):
|
||||
it = iter_file_dups([os.path.join(mydir, 'testfiles_dups')])
|
||||
swp = Sweeper(topdirs=[os.path.join(mydir, 'testfiles_dups')])
|
||||
dups_exist = False
|
||||
for x in it:
|
||||
for x in swp:
|
||||
dups_exist = True
|
||||
filepath, h, dups = x
|
||||
self.assertNotIn(filepath, dups)
|
||||
|
|
@ -44,9 +47,9 @@ class TestSweeper(unittest.TestCase):
|
|||
self.assertTrue(dups_exist)
|
||||
|
||||
def test_iter_file_dups_nodups(self):
|
||||
it = iter_file_dups([os.path.join(mydir, 'testfiles_nodups')])
|
||||
swp = Sweeper([os.path.join(mydir, 'testfiles_nodups')])
|
||||
dups_exist = False
|
||||
for x in it:
|
||||
for x in swp:
|
||||
dups_exist = True
|
||||
break
|
||||
self.assertFalse(dups_exist)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue