mirror of
https://github.com/arsenetar/dupeguru.git
synced 2025-03-10 05:34:36 +00:00
Fixed unittests.
This commit is contained in:
parent
fc5a0d914b
commit
9226a4fb7c
@ -121,9 +121,8 @@ class TestCaseDupeGuru:
|
|||||||
# It's possible that rename operation has its selected row swept off from under it, thus
|
# It's possible that rename operation has its selected row swept off from under it, thus
|
||||||
# making the selected row None. Don't crash when it happens.
|
# making the selected row None. Don't crash when it happens.
|
||||||
dgapp = DupeGuru()
|
dgapp = DupeGuru()
|
||||||
rtable = ResultTable(CallLogger(), dgapp)
|
|
||||||
# selected_row is None because there's no result.
|
# selected_row is None because there's no result.
|
||||||
assert not rtable.rename_selected('foo') # no crash
|
assert not dgapp.result_table.rename_selected('foo') # no crash
|
||||||
|
|
||||||
class TestCaseDupeGuru_clean_empty_dirs:
|
class TestCaseDupeGuru_clean_empty_dirs:
|
||||||
def pytest_funcarg__do_setup(self, request):
|
def pytest_funcarg__do_setup(self, request):
|
||||||
@ -174,7 +173,8 @@ class TestCaseDupeGuruWithResults:
|
|||||||
self.dtree_gui = CallLogger()
|
self.dtree_gui = CallLogger()
|
||||||
self.dtree = DirectoryTree(self.dtree_gui, self.app)
|
self.dtree = DirectoryTree(self.dtree_gui, self.app)
|
||||||
self.rtable_gui = CallLogger()
|
self.rtable_gui = CallLogger()
|
||||||
self.rtable = ResultTable(self.rtable_gui, self.app)
|
self.rtable = self.app.result_table
|
||||||
|
self.rtable.view = self.rtable_gui
|
||||||
self.dpanel.connect()
|
self.dpanel.connect()
|
||||||
self.dtree.connect()
|
self.dtree.connect()
|
||||||
self.rtable.connect()
|
self.rtable.connect()
|
||||||
@ -200,7 +200,7 @@ class TestCaseDupeGuruWithResults:
|
|||||||
def test_GetObjects_after_sort(self, do_setup):
|
def test_GetObjects_after_sort(self, do_setup):
|
||||||
objects = self.objects
|
objects = self.objects
|
||||||
groups = self.groups[:] # we need an un-sorted reference
|
groups = self.groups[:] # we need an un-sorted reference
|
||||||
self.rtable.sort(0, False) #0 = Filename
|
self.rtable.sort('name', False)
|
||||||
r = self.rtable[1]
|
r = self.rtable[1]
|
||||||
assert r._group is groups[1]
|
assert r._group is groups[1]
|
||||||
assert r._dupe is objects[4]
|
assert r._dupe is objects[4]
|
||||||
@ -233,7 +233,7 @@ class TestCaseDupeGuruWithResults:
|
|||||||
app = self.app
|
app = self.app
|
||||||
objects = self.objects
|
objects = self.objects
|
||||||
groups = self.groups[:] #To keep the old order in memory
|
groups = self.groups[:] #To keep the old order in memory
|
||||||
self.rtable.sort(0, False) #0 = Filename
|
self.rtable.sort('name', False) #0
|
||||||
#Now, the group order is supposed to be reversed
|
#Now, the group order is supposed to be reversed
|
||||||
self.rtable.select([1, 2, 3])
|
self.rtable.select([1, 2, 3])
|
||||||
eq_(len(app.selected_dupes), 3)
|
eq_(len(app.selected_dupes), 3)
|
||||||
@ -260,7 +260,7 @@ class TestCaseDupeGuruWithResults:
|
|||||||
app = self.app
|
app = self.app
|
||||||
objects = self.objects
|
objects = self.objects
|
||||||
self.rtable.power_marker = True
|
self.rtable.power_marker = True
|
||||||
self.rtable.sort(0, False) #0 = Filename
|
self.rtable.sort('name', False)
|
||||||
self.rtable.select([0, 1, 2])
|
self.rtable.select([0, 1, 2])
|
||||||
eq_(len(app.selected_dupes), 3)
|
eq_(len(app.selected_dupes), 3)
|
||||||
assert app.selected_dupes[0] is objects[4]
|
assert app.selected_dupes[0] is objects[4]
|
||||||
@ -429,7 +429,8 @@ class TestCaseDupeGuru_renameSelected:
|
|||||||
self.p = p
|
self.p = p
|
||||||
self.files = files
|
self.files = files
|
||||||
self.rtable_gui = CallLogger()
|
self.rtable_gui = CallLogger()
|
||||||
self.rtable = ResultTable(self.rtable_gui, self.app)
|
self.rtable = self.app.result_table
|
||||||
|
self.rtable.view = self.rtable_gui
|
||||||
self.rtable.connect()
|
self.rtable.connect()
|
||||||
|
|
||||||
def test_simple(self, do_setup):
|
def test_simple(self, do_setup):
|
||||||
|
@ -9,15 +9,16 @@
|
|||||||
from hscommon.testutil import TestApp as TestAppBase, eq_, with_app
|
from hscommon.testutil import TestApp as TestAppBase, eq_, with_app
|
||||||
from hscommon.path import Path
|
from hscommon.path import Path
|
||||||
from hscommon.util import get_file_ext, format_size
|
from hscommon.util import get_file_ext, format_size
|
||||||
|
from hscommon.gui.column import Column
|
||||||
from jobprogress.job import nulljob, JobCancelled
|
from jobprogress.job import nulljob, JobCancelled
|
||||||
|
|
||||||
from .. import engine
|
from .. import engine
|
||||||
from .. import prioritize
|
from .. import prioritize
|
||||||
from ..engine import getwords
|
from ..engine import getwords
|
||||||
from ..app import DupeGuru as DupeGuruBase, Column, cmp_value
|
from ..app import DupeGuru as DupeGuruBase, cmp_value
|
||||||
from ..gui.details_panel import DetailsPanel
|
from ..gui.details_panel import DetailsPanel
|
||||||
from ..gui.directory_tree import DirectoryTree
|
from ..gui.directory_tree import DirectoryTree
|
||||||
from ..gui.result_table import ResultTable
|
from ..gui.result_table import ResultTable as ResultTableBase
|
||||||
from ..gui.prioritize_dialog import PrioritizeDialog
|
from ..gui.prioritize_dialog import PrioritizeDialog
|
||||||
|
|
||||||
class DupeGuruView:
|
class DupeGuruView:
|
||||||
@ -36,18 +37,22 @@ class DupeGuruView:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class DupeGuru(DupeGuruBase):
|
class ResultTable(ResultTableBase):
|
||||||
COLUMNS = [
|
COLUMNS = [
|
||||||
|
Column('marked', ''),
|
||||||
Column('name', 'Filename'),
|
Column('name', 'Filename'),
|
||||||
Column('folder_path', 'Directory'),
|
Column('folder_path', 'Directory'),
|
||||||
Column('size', 'Size (KB)'),
|
Column('size', 'Size (KB)'),
|
||||||
Column('extension', 'Kind'),
|
Column('extension', 'Kind'),
|
||||||
]
|
]
|
||||||
DELTA_COLUMNS = {'size', }
|
DELTA_COLUMNS = {'size', }
|
||||||
|
|
||||||
|
class DupeGuru(DupeGuruBase):
|
||||||
METADATA_TO_READ = ['size']
|
METADATA_TO_READ = ['size']
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
DupeGuruBase.__init__(self, DupeGuruView(), '/tmp')
|
DupeGuruBase.__init__(self, DupeGuruView(), '/tmp')
|
||||||
|
self.result_table = ResultTable(self)
|
||||||
|
|
||||||
def _get_display_info(self, dupe, group, delta):
|
def _get_display_info(self, dupe, group, delta):
|
||||||
size = dupe.size
|
size = dupe.size
|
||||||
@ -55,21 +60,21 @@ class DupeGuru(DupeGuruBase):
|
|||||||
if m and delta:
|
if m and delta:
|
||||||
r = group.ref
|
r = group.ref
|
||||||
size -= r.size
|
size -= r.size
|
||||||
return [
|
return {
|
||||||
dupe.name,
|
'name': dupe.name,
|
||||||
str(dupe.folder_path),
|
'folder_path': str(dupe.folder_path),
|
||||||
format_size(size, 0, 1, False),
|
'size': format_size(size, 0, 1, False),
|
||||||
dupe.extension if hasattr(dupe, 'extension') else '---',
|
'extension': dupe.extension if hasattr(dupe, 'extension') else '---',
|
||||||
]
|
}
|
||||||
|
|
||||||
def _get_dupe_sort_key(self, dupe, get_group, key, delta):
|
def _get_dupe_sort_key(self, dupe, get_group, key, delta):
|
||||||
r = cmp_value(dupe, self.COLUMNS[key])
|
r = cmp_value(dupe, key)
|
||||||
if delta and (key in self.DELTA_COLUMNS):
|
if delta and (key in self.result_table.DELTA_COLUMNS):
|
||||||
r -= cmp_value(get_group().ref, self.COLUMNS[key])
|
r -= cmp_value(get_group().ref, key)
|
||||||
return r
|
return r
|
||||||
|
|
||||||
def _get_group_sort_key(self, group, key):
|
def _get_group_sort_key(self, group, key):
|
||||||
return cmp_value(group.ref, self.COLUMNS[key])
|
return cmp_value(group.ref, key)
|
||||||
|
|
||||||
def _prioritization_categories(self):
|
def _prioritization_categories(self):
|
||||||
return prioritize.all_categories()
|
return prioritize.all_categories()
|
||||||
@ -120,14 +125,20 @@ def GetTestGroups():
|
|||||||
|
|
||||||
class TestApp(TestAppBase):
|
class TestApp(TestAppBase):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
def link_gui(gui):
|
||||||
|
gui.view = self.make_logger()
|
||||||
|
if hasattr(gui, 'columns'): # tables
|
||||||
|
gui.columns.view = self.make_logger()
|
||||||
|
return gui
|
||||||
|
|
||||||
|
TestAppBase.__init__(self)
|
||||||
make_gui = self.make_gui
|
make_gui = self.make_gui
|
||||||
self.app = DupeGuru()
|
self.app = DupeGuru()
|
||||||
# XXX After hscommon.testutil.TestApp has had its default parent changed to seomthing
|
self.default_parent = self.app
|
||||||
# customizable (with adjustments in moneyguru) we can get rid of 'parent='
|
self.rtable = link_gui(self.app.result_table)
|
||||||
make_gui('rtable', ResultTable, parent=self.app)
|
make_gui('dtree', DirectoryTree)
|
||||||
make_gui('dtree', DirectoryTree, parent=self.app)
|
make_gui('dpanel', DetailsPanel)
|
||||||
make_gui('dpanel', DetailsPanel, parent=self.app)
|
make_gui('pdialog', PrioritizeDialog)
|
||||||
make_gui('pdialog', PrioritizeDialog, parent=self.app)
|
|
||||||
for elem in [self.rtable, self.dtree, self.dpanel]:
|
for elem in [self.rtable, self.dtree, self.dpanel]:
|
||||||
elem.connect()
|
elem.connect()
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ def test_kind_reprioritization(app):
|
|||||||
app.pdialog.criteria_list.select([1]) # ext2
|
app.pdialog.criteria_list.select([1]) # ext2
|
||||||
app.pdialog.add_selected()
|
app.pdialog.add_selected()
|
||||||
app.pdialog.perform_reprioritization()
|
app.pdialog.perform_reprioritization()
|
||||||
eq_(app.rtable[0].data[0], 'foo2.ext2')
|
eq_(app.rtable[0].data['name'], 'foo2.ext2')
|
||||||
|
|
||||||
@with_app(app_normal_results)
|
@with_app(app_normal_results)
|
||||||
def test_folder_subcrit(app):
|
def test_folder_subcrit(app):
|
||||||
@ -67,7 +67,7 @@ def test_folder_reprioritization(app):
|
|||||||
app.pdialog.criteria_list.select([1]) # folder2
|
app.pdialog.criteria_list.select([1]) # folder2
|
||||||
app.pdialog.add_selected()
|
app.pdialog.add_selected()
|
||||||
app.pdialog.perform_reprioritization()
|
app.pdialog.perform_reprioritization()
|
||||||
eq_(app.rtable[0].data[0], 'foo2.ext2')
|
eq_(app.rtable[0].data['name'], 'foo2.ext2')
|
||||||
|
|
||||||
@with_app(app_normal_results)
|
@with_app(app_normal_results)
|
||||||
def test_prilist_display(app):
|
def test_prilist_display(app):
|
||||||
@ -99,7 +99,7 @@ def test_size_reprioritization(app):
|
|||||||
app.pdialog.criteria_list.select([0]) # highest
|
app.pdialog.criteria_list.select([0]) # highest
|
||||||
app.pdialog.add_selected()
|
app.pdialog.add_selected()
|
||||||
app.pdialog.perform_reprioritization()
|
app.pdialog.perform_reprioritization()
|
||||||
eq_(app.rtable[0].data[0], 'foo2.ext2')
|
eq_(app.rtable[0].data['name'], 'foo2.ext2')
|
||||||
|
|
||||||
@with_app(app_normal_results)
|
@with_app(app_normal_results)
|
||||||
def test_reorder_prioritizations(app):
|
def test_reorder_prioritizations(app):
|
||||||
@ -137,7 +137,7 @@ def app_one_name_ends_with_number():
|
|||||||
def test_filename_reprioritization(app):
|
def test_filename_reprioritization(app):
|
||||||
app.add_pri_criterion("Filename", 0) # Ends with a number
|
app.add_pri_criterion("Filename", 0) # Ends with a number
|
||||||
app.pdialog.perform_reprioritization()
|
app.pdialog.perform_reprioritization()
|
||||||
eq_(app.rtable[0].data[0], 'foo1.ext')
|
eq_(app.rtable[0].data['name'], 'foo1.ext')
|
||||||
|
|
||||||
#---
|
#---
|
||||||
def app_with_subfolders():
|
def app_with_subfolders():
|
||||||
@ -166,8 +166,8 @@ def test_folder_crit_includes_subfolders(app):
|
|||||||
app.add_pri_criterion("Folder", 1) # foo
|
app.add_pri_criterion("Folder", 1) # foo
|
||||||
app.pdialog.perform_reprioritization()
|
app.pdialog.perform_reprioritization()
|
||||||
# Both foo and foo/bar dupes will be prioritized
|
# Both foo and foo/bar dupes will be prioritized
|
||||||
eq_(app.rtable[0].data[0], 'foo2')
|
eq_(app.rtable[0].data['name'], 'foo2')
|
||||||
eq_(app.rtable[2].data[0], 'foo4')
|
eq_(app.rtable[2].data['name'], 'foo4')
|
||||||
|
|
||||||
@with_app(app_with_subfolders)
|
@with_app(app_with_subfolders)
|
||||||
def test_display_something_on_empty_extensions(app):
|
def test_display_something_on_empty_extensions(app):
|
||||||
|
@ -119,16 +119,16 @@ class TestCaseResultsWithSomeGroups:
|
|||||||
def test_sort_groups(self):
|
def test_sort_groups(self):
|
||||||
self.results.make_ref(self.objects[1]) #We want to make the 1024 sized object to go ref.
|
self.results.make_ref(self.objects[1]) #We want to make the 1024 sized object to go ref.
|
||||||
g1,g2 = self.groups
|
g1,g2 = self.groups
|
||||||
self.results.sort_groups(2) #2 is the key for size
|
self.results.sort_groups('size')
|
||||||
assert self.results.groups[0] is g2
|
assert self.results.groups[0] is g2
|
||||||
assert self.results.groups[1] is g1
|
assert self.results.groups[1] is g1
|
||||||
self.results.sort_groups(2,False)
|
self.results.sort_groups('size', False)
|
||||||
assert self.results.groups[0] is g1
|
assert self.results.groups[0] is g1
|
||||||
assert self.results.groups[1] is g2
|
assert self.results.groups[1] is g2
|
||||||
|
|
||||||
def test_set_groups_when_sorted(self):
|
def test_set_groups_when_sorted(self):
|
||||||
self.results.make_ref(self.objects[1]) #We want to make the 1024 sized object to go ref.
|
self.results.make_ref(self.objects[1]) #We want to make the 1024 sized object to go ref.
|
||||||
self.results.sort_groups(2)
|
self.results.sort_groups('size')
|
||||||
objects,matches,groups = GetTestGroups()
|
objects,matches,groups = GetTestGroups()
|
||||||
g1,g2 = groups
|
g1,g2 = groups
|
||||||
g1.switch_ref(objects[1])
|
g1.switch_ref(objects[1])
|
||||||
@ -159,9 +159,9 @@ class TestCaseResultsWithSomeGroups:
|
|||||||
o3.size = 3
|
o3.size = 3
|
||||||
o4.size = 2
|
o4.size = 2
|
||||||
o5.size = 1
|
o5.size = 1
|
||||||
self.results.sort_dupes(2)
|
self.results.sort_dupes('size')
|
||||||
eq_([o5,o3,o2],self.results.dupes)
|
eq_([o5,o3,o2],self.results.dupes)
|
||||||
self.results.sort_dupes(2,False)
|
self.results.sort_dupes('size', False)
|
||||||
eq_([o2,o3,o5],self.results.dupes)
|
eq_([o2,o3,o5],self.results.dupes)
|
||||||
|
|
||||||
def test_dupe_list_remember_sort(self):
|
def test_dupe_list_remember_sort(self):
|
||||||
@ -171,7 +171,7 @@ class TestCaseResultsWithSomeGroups:
|
|||||||
o3.size = 3
|
o3.size = 3
|
||||||
o4.size = 2
|
o4.size = 2
|
||||||
o5.size = 1
|
o5.size = 1
|
||||||
self.results.sort_dupes(2)
|
self.results.sort_dupes('size')
|
||||||
self.results.make_ref(o2)
|
self.results.make_ref(o2)
|
||||||
eq_([o5,o3,o1],self.results.dupes)
|
eq_([o5,o3,o1],self.results.dupes)
|
||||||
|
|
||||||
@ -182,14 +182,14 @@ class TestCaseResultsWithSomeGroups:
|
|||||||
o3.size = 3 #-7
|
o3.size = 3 #-7
|
||||||
o4.size = 20
|
o4.size = 20
|
||||||
o5.size = 1 #-19
|
o5.size = 1 #-19
|
||||||
self.results.sort_dupes(2,delta=True)
|
self.results.sort_dupes('size', delta=True)
|
||||||
eq_([o5,o2,o3],self.results.dupes)
|
eq_([o5,o2,o3],self.results.dupes)
|
||||||
|
|
||||||
def test_sort_empty_list(self):
|
def test_sort_empty_list(self):
|
||||||
#There was an infinite loop when sorting an empty list.
|
#There was an infinite loop when sorting an empty list.
|
||||||
app = DupeGuru()
|
app = DupeGuru()
|
||||||
r = app.results
|
r = app.results
|
||||||
r.sort_dupes(0)
|
r.sort_dupes('name')
|
||||||
eq_([],r.dupes)
|
eq_([],r.dupes)
|
||||||
|
|
||||||
def test_dupe_list_update_on_remove_duplicates(self):
|
def test_dupe_list_update_on_remove_duplicates(self):
|
||||||
@ -720,13 +720,13 @@ class TestCaseResultsFilter:
|
|||||||
self.results.make_ref(self.objects[1]) # to have the 1024 b obkect as ref
|
self.results.make_ref(self.objects[1]) # to have the 1024 b obkect as ref
|
||||||
g1,g2 = self.groups
|
g1,g2 = self.groups
|
||||||
self.results.apply_filter('a') # Matches both group
|
self.results.apply_filter('a') # Matches both group
|
||||||
self.results.sort_groups(2) #2 is the key for size
|
self.results.sort_groups('size')
|
||||||
assert self.results.groups[0] is g2
|
assert self.results.groups[0] is g2
|
||||||
assert self.results.groups[1] is g1
|
assert self.results.groups[1] is g1
|
||||||
self.results.apply_filter(None)
|
self.results.apply_filter(None)
|
||||||
assert self.results.groups[0] is g2
|
assert self.results.groups[0] is g2
|
||||||
assert self.results.groups[1] is g1
|
assert self.results.groups[1] is g1
|
||||||
self.results.sort_groups(2, False)
|
self.results.sort_groups('size', False)
|
||||||
self.results.apply_filter('a')
|
self.results.apply_filter('a')
|
||||||
assert self.results.groups[1] is g2
|
assert self.results.groups[1] is g2
|
||||||
assert self.results.groups[0] is g1
|
assert self.results.groups[0] is g1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user