2014-01-27 06:31:40 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# Author: Darko Poljak <darko.poljak@gmail.com>
|
|
|
|
# License: GPLv3
|
|
|
|
|
|
|
|
import unittest
|
2014-08-09 22:06:32 +00:00
|
|
|
from sweeper import Sweeper
|
2014-01-27 06:31:40 +00:00
|
|
|
import os
|
|
|
|
|
|
|
|
mydir = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
|
|
|
|
|
|
|
|
class TestSweeper(unittest.TestCase):
|
|
|
|
def test_file_dups_dups(self):
|
2014-08-09 22:06:32 +00:00
|
|
|
swp = Sweeper(topdirs=[os.path.join(mydir, 'testfiles_dups')])
|
|
|
|
dups = swp.file_dups()
|
2014-01-27 06:31:40 +00:00
|
|
|
dups_exist = False
|
|
|
|
for h, flist in dups.items():
|
|
|
|
if len(flist) > 1:
|
|
|
|
dups_exist = True
|
|
|
|
self.assertTrue(dups_exist)
|
|
|
|
|
|
|
|
def test_file_dups_nodups(self):
|
2014-08-09 22:06:32 +00:00
|
|
|
swp = Sweeper(topdirs=[os.path.join(mydir, 'testfiles_nodups')])
|
|
|
|
dups = swp.file_dups()
|
2014-01-27 06:31:40 +00:00
|
|
|
for h, flist in dups.items():
|
|
|
|
self.assertTrue(len(flist) == 1)
|
|
|
|
|
2014-02-06 09:11:06 +00:00
|
|
|
# does not actually test safe_mode, we would need to find
|
|
|
|
# hash collision
|
|
|
|
def test_file_dups_safe_mode(self):
|
2014-08-09 22:06:32 +00:00
|
|
|
swp = Sweeper(topdirs=[os.path.join(mydir, 'testfiles_dups')],
|
|
|
|
safe_mode=True)
|
|
|
|
dups = swp.file_dups()
|
2014-02-06 09:11:06 +00:00
|
|
|
for h, flist in dups.items():
|
|
|
|
if len(flist) > 1:
|
|
|
|
dups_exist = True
|
|
|
|
self.assertTrue(dups_exist)
|
|
|
|
|
2014-02-07 07:30:48 +00:00
|
|
|
def test_iter_file_dups_dups(self):
|
2014-08-09 22:06:32 +00:00
|
|
|
swp = Sweeper(topdirs=[os.path.join(mydir, 'testfiles_dups')])
|
2014-02-06 13:42:51 +00:00
|
|
|
dups_exist = False
|
2014-08-09 22:06:32 +00:00
|
|
|
for x in swp:
|
2014-02-06 13:42:51 +00:00
|
|
|
dups_exist = True
|
2014-02-07 07:30:48 +00:00
|
|
|
filepath, h, dups = x
|
|
|
|
self.assertNotIn(filepath, dups)
|
|
|
|
self.assertTrue(len(dups) > 0)
|
2014-02-06 13:42:51 +00:00
|
|
|
self.assertTrue(dups_exist)
|
|
|
|
|
2014-02-07 07:30:48 +00:00
|
|
|
def test_iter_file_dups_nodups(self):
|
2014-08-09 22:06:32 +00:00
|
|
|
swp = Sweeper([os.path.join(mydir, 'testfiles_nodups')])
|
2014-02-07 07:30:48 +00:00
|
|
|
dups_exist = False
|
2014-08-09 22:06:32 +00:00
|
|
|
for x in swp:
|
2014-02-07 07:30:48 +00:00
|
|
|
dups_exist = True
|
|
|
|
break
|
|
|
|
self.assertFalse(dups_exist)
|
|
|
|
|
2014-01-27 06:31:40 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|