Don't allow dupes from ref folders to step down from their ref position during reprioritization.

This commit is contained in:
Virgil Dupras 2011-09-23 13:14:57 -04:00
parent 11aa2c147c
commit 9fac97c147
6 changed files with 28 additions and 14 deletions

View File

@ -290,7 +290,8 @@ class Group:
def prioritize(self, key_func, tie_breaker=None):
# tie_breaker(ref, dupe) --> True if dupe should be ref
self.ordered.sort(key=key_func)
master_key_func = lambda x: (-x.is_ref, key_func(x))
self.ordered.sort(key=master_key_func)
if tie_breaker is None:
return
ref = self.ref
@ -318,6 +319,8 @@ class Group:
pass
def switch_ref(self, with_dupe):
if self.ref.is_ref:
return
try:
self.ordered.remove(with_dupe)
self.ordered.insert(0, with_dupe)

View File

@ -80,7 +80,7 @@ class Scanner:
@staticmethod
def _key_func(dupe):
return (not dupe.is_ref, -dupe.size)
return -dupe.size
@staticmethod
def _tie_breaker(ref, dupe):

View File

@ -416,6 +416,8 @@ class TestCaseDupeGuru_renameSelected:
fp = open(str(p + 'foo bar 3'),mode='w')
fp.close()
files = fs.get_files(p)
for f in files:
f.is_ref = False
matches = engine.getmatches(files)
groups = engine.get_groups(matches)
g = groups[0]

View File

@ -599,6 +599,16 @@ class TestCaseGroup:
g.switch_ref(NamedObject('',True))
assert o2 is g.ref
def test_switch_ref_from_ref_dir(self):
# When the ref dupe is from a ref dir, switch_ref() does nothing
o1 = no(with_words=True)
o2 = no(with_words=True)
o1.is_ref = True
g = Group()
g.add_match(get_match(o1, o2))
g.switch_ref(o2)
assert o1 is g.ref
def test_get_match_of(self):
g = Group()
for m in get_match_triangle():
@ -684,6 +694,15 @@ class TestCaseGroup:
g.prioritize(key_func, tie_breaker)
assert g.ref is o2
def test_prioritize_with_ref_dupe(self):
# when the ref dupe of a group is from a ref dir, make it stay on top.
g = get_test_group()
o1, o2, o3 = g
o1.is_ref = True
o2.size = 2
g.prioritize(lambda x: -x.size)
assert g.ref is o1
def test_list_like(self):
g = Group()
o1,o2 = (NamedObject("foo",True),NamedObject("bar",True))

View File

@ -794,14 +794,4 @@ class TestCaseResultsRefFile:
def test_stat_line(self):
expected = '0 / 2 (0.00 B / 2.00 B) duplicates marked.'
eq_(expected, self.results.stat_line)
def test_make_ref(self):
d = self.results.groups[0].dupes[1] #non-ref
r = self.results.groups[0].ref
self.results.make_ref(d)
expected = '0 / 1 (0.00 B / 1.00 B) duplicates marked.'
eq_(expected, self.results.stat_line)
self.results.make_ref(r)
expected = '0 / 2 (0.00 B / 2.00 B) duplicates marked.'
eq_(expected, self.results.stat_line)

View File

@ -11,5 +11,5 @@ from core.scanner import Scanner as ScannerBase
class ScannerME(ScannerBase):
@staticmethod
def _key_func(dupe):
return (not dupe.is_ref, -dupe.bitrate, -dupe.size)
return (-dupe.bitrate, -dupe.size)