mirror of https://github.com/kivy/kivy.git
Added tests for sorted_keys after data changed in trim ops.
This commit is contained in:
parent
d2688e01f1
commit
430f2e793b
|
@ -103,6 +103,8 @@ class DictAdapter(ListAdapter):
|
|||
def trim_left_of_sel(self, *args):
|
||||
'''Cut list items with indices in sorted_keys that are less than the
|
||||
index of the first selected item, if there is selection.
|
||||
|
||||
sorted_keys will be updated by update_for_new_data().
|
||||
'''
|
||||
if len(self.selection) > 0:
|
||||
selected_keys = [sel.text for sel in self.selection]
|
||||
|
@ -113,6 +115,8 @@ class DictAdapter(ListAdapter):
|
|||
def trim_right_of_sel(self, *args):
|
||||
'''Cut list items with indices in sorted_keys that are greater than
|
||||
the index of the last selected item, if there is selection.
|
||||
|
||||
sorted_keys will be updated by update_for_new_data().
|
||||
'''
|
||||
if len(self.selection) > 0:
|
||||
selected_keys = [sel.text for sel in self.selection]
|
||||
|
@ -125,6 +129,8 @@ class DictAdapter(ListAdapter):
|
|||
greater than the index of the last selected item, if there is
|
||||
selection. This preserves intervening list items within the selected
|
||||
range.
|
||||
|
||||
sorted_keys will be updated by update_for_new_data().
|
||||
'''
|
||||
if len(self.selection) > 0:
|
||||
selected_keys = [sel.text for sel in self.selection]
|
||||
|
@ -136,6 +142,8 @@ class DictAdapter(ListAdapter):
|
|||
def cut_to_sel(self, *args):
|
||||
'''Same as trim_to_sel, but intervening list items within the selected
|
||||
range are cut also, leaving only list items that are selected.
|
||||
|
||||
sorted_keys will be updated by update_for_new_data().
|
||||
'''
|
||||
if len(self.selection) > 0:
|
||||
selected_keys = [sel.text for sel in self.selection]
|
||||
|
|
|
@ -1261,6 +1261,14 @@ class AdaptersTestCase(unittest.TestCase):
|
|||
|
||||
letters = [l for l in alphabet]
|
||||
|
||||
def sorted_keys_ok(letters_dict_adapter):
|
||||
sorted_keys_ok = True
|
||||
for key in letters_dict_adapter.sorted_keys:
|
||||
if not key in letters_dict_adapter.data:
|
||||
sorted_keys_ok = False
|
||||
break
|
||||
return sorted_keys_ok
|
||||
|
||||
# trim left of sel
|
||||
|
||||
letters_dict_adapter = DictAdapter(
|
||||
|
@ -1282,6 +1290,8 @@ class AdaptersTestCase(unittest.TestCase):
|
|||
letters_dict_adapter.trim_right_of_sel()
|
||||
self.assertEqual(len(letters_dict_adapter.data), 1)
|
||||
|
||||
self.assertTrue(sorted_keys_ok(letters_dict_adapter))
|
||||
|
||||
# trim right of sel
|
||||
|
||||
letters_dict_adapter = DictAdapter(
|
||||
|
@ -1303,6 +1313,8 @@ class AdaptersTestCase(unittest.TestCase):
|
|||
letters_dict_adapter.trim_left_of_sel()
|
||||
self.assertEqual(len(letters_dict_adapter.data), 1)
|
||||
|
||||
self.assertTrue(sorted_keys_ok(letters_dict_adapter))
|
||||
|
||||
# trim to sel
|
||||
|
||||
letters_dict_adapter = DictAdapter(
|
||||
|
@ -1325,6 +1337,8 @@ class AdaptersTestCase(unittest.TestCase):
|
|||
letters_dict_adapter.trim_to_sel()
|
||||
self.assertEqual(len(letters_dict_adapter.data), 7)
|
||||
|
||||
self.assertTrue(sorted_keys_ok(letters_dict_adapter))
|
||||
|
||||
# cut to sel
|
||||
|
||||
letters_dict_adapter = DictAdapter(
|
||||
|
@ -1347,3 +1361,4 @@ class AdaptersTestCase(unittest.TestCase):
|
|||
letters_dict_adapter.cut_to_sel()
|
||||
self.assertEqual(len(letters_dict_adapter.data), 2)
|
||||
|
||||
self.assertTrue(sorted_keys_ok(letters_dict_adapter))
|
||||
|
|
Loading…
Reference in New Issue