Skip to content

Commit

Permalink
Make non-numeric delta comparison case insensitive
Browse files Browse the repository at this point in the history
Fixes #239.
  • Loading branch information
Virgil Dupras committed Nov 23, 2013
1 parent 0e54257 commit c34c956
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 11 deletions.
14 changes: 4 additions & 10 deletions core/app.py
Expand Up @@ -21,8 +21,7 @@
from hscommon.path import Path
from hscommon.conflict import smart_move, smart_copy
from hscommon.gui.progress_window import ProgressWindow
from hscommon.util import (delete_if_empty, first, escape, nonone, format_time_decimal, allsame,
rem_file_ext)
from hscommon.util import delete_if_empty, first, escape, nonone, format_time_decimal, allsame
from hscommon.trans import tr
from hscommon.plat import ISWINDOWS
from hscommon import desktop
Expand Down Expand Up @@ -90,10 +89,7 @@ def format_dupe_count(c):
return str(c) if c else '---'

def cmp_value(dupe, attrname):
if attrname == 'name':
value = rem_file_ext(dupe.name)
else:
value = getattr(dupe, attrname, '')
value = getattr(dupe, attrname, '')
return value.lower() if isinstance(value, str) else value

def fix_surrogate_encoding(s, encoding='utf-8'):
Expand Down Expand Up @@ -205,13 +201,11 @@ def _get_dupe_sort_key(self, dupe, get_group, key, delta):
else:
result = cmp_value(dupe, key)
if delta:
refval = getattr(get_group().ref, key)
refval = cmp_value(get_group().ref, key)
if key in self.result_table.DELTA_COLUMNS:
result -= refval
else:
# We use directly getattr() because cmp_value() does thing that we don't want to do
# when we want to determine whether two values are exactly the same.
same = getattr(dupe, key) == refval
same = cmp_value(dupe, key) == refval
result = (same, result)
return result

Expand Down
2 changes: 1 addition & 1 deletion core/gui/result_table.py
Expand Up @@ -42,7 +42,7 @@ def is_cell_delta(self, column_name):
dupe_info = self.data
ref_info = self._group.ref.get_display_info(group=self._group, delta=False)
for key, value in dupe_info.items():
if ref_info[key] != value:
if (key not in self._delta_columns) and (ref_info[key].lower() != value.lower()):
self._delta_columns.add(key)
return column_name in self._delta_columns

Expand Down
10 changes: 10 additions & 0 deletions core/tests/result_table_test.py
Expand Up @@ -44,3 +44,13 @@ def test_delta_flags_delta_mode_on_non_delta_columns():
assert not app.rtable[3].is_cell_delta('name')
# "ibabtu" == "ibabtu", flag off
assert not app.rtable[4].is_cell_delta('name')

def test_delta_flags_delta_mode_on_non_delta_columns_case_insensitive():
# Comparison that occurs for non-numeric columns to check whether they're delta is case
# insensitive
app = app_with_results()
app.app.results.groups[1].ref.name = "ibAbtu"
app.app.results.groups[1].dupes[0].name = "IBaBTU"
app.rtable.delta_values = True
# "ibAbtu" == "IBaBTU", flag off
assert not app.rtable[4].is_cell_delta('name')
17 changes: 17 additions & 0 deletions core/tests/results_test.py
Expand Up @@ -230,6 +230,23 @@ def test_group_of_duplicate_after_removal(self):
# also remove group ref
assert self.results.get_group_of_duplicate(ref) is None

def test_dupe_list_sort_delta_values_nonnumeric(self):
# When sorting dupes in delta mode on a non-numeric column, our first sort criteria is if
# the string is the same as its ref.
g1r, g1d1, g1d2, g2r, g2d1 = self.objects
# "aaa" makes our dupe go first in alphabetical order, but since we have the same value as
# ref, we're going last.
g2r.name = g2d1.name = "aaa"
self.results.sort_dupes('name', delta=True)
eq_("aaa", self.results.dupes[2].name)

def test_dupe_list_sort_delta_values_nonnumeric_case_insensitive(self):
# Non-numeric delta sorting comparison is case insensitive
g1r, g1d1, g1d2, g2r, g2d1 = self.objects
g2r.name = "AaA"
g2d1.name = "aAa"
self.results.sort_dupes('name', delta=True)
eq_("aAa", self.results.dupes[2].name)

class TestCaseResultsWithSavedResults:
def setup_method(self, method):
Expand Down

0 comments on commit c34c956

Please sign in to comment.