def test_sorting_list_of_objects(self): expected_result = [ self.object5, self.object4, self.object2, self.object1, self.object3 ] assert(natural_sort.sort(self.objects_to_sort, ('name', 'version')) == expected_result)
def test_sorting_with_descending_column(self): expected_result = [ {'name': 'def', 'version': '1.2.2'}, {'name': 'def', 'version': '1.2.10'}, {'name': 'abc', 'version': '1.2.2'}, {'name': 'abc', 'version': '1.2.10'}, {'name': 'abc', 'version': '1.3.2'}, ] assert(natural_sort.sort(self.dicts_to_sort, ('-name', 'version')) == expected_result)
def test_sorting_list_of_dicts(self): expected_result = [ {'name': 'abc', 'version': '1.2.2'}, {'name': 'abc', 'version': '1.2.10'}, {'name': 'abc', 'version': '1.3.2'}, {'name': 'def', 'version': '1.2.2'}, {'name': 'def', 'version': '1.2.10'}, ] assert(natural_sort.sort(self.dicts_to_sort, ('name', 'version')) == expected_result)
def test_sorting_list_of_strings(self): expected_result = [ '1.2.2', '1.2.10', '1.3.2', '2.1', '2.1.0' ] assert(natural_sort.sort(self.strings_to_sort) == expected_result)
def test_sorting_objects_with_property_as_key(self): expected_result = [ self.object5, self.object4, self.object2, self.object1, self.object3 ] assert(natural_sort.sort(self.objects_to_sort, ('name', 'v_version')) == expected_result)
def test_sorting_dicts_without_specifying_key_names(self): expected_result_when_sorting_by_name_then_version = [ {'name': 'abc', 'version': '1.2.2'}, {'name': 'abc', 'version': '1.2.10'}, {'name': 'abc', 'version': '1.3.2'}, {'name': 'def', 'version': '1.2.2'}, {'name': 'def', 'version': '1.2.10'}, ] expected_result_when_sorting_by_version_then_name = [ {'name': 'abc', 'version': '1.2.2'}, {'name': 'def', 'version': '1.2.2'}, {'name': 'abc', 'version': '1.2.10'}, {'name': 'def', 'version': '1.2.10'}, {'name': 'abc', 'version': '1.3.2'}, ] assert(natural_sort.sort(self.dicts_to_sort) == expected_result_when_sorting_by_version_then_name or natural_sort.sort(self.dicts_to_sort) == expected_result_when_sorting_by_name_then_version)
def test_sorting_objects_without_specifying_key_names(self): # Sorted by name, then version. expected_result_possibility_1 = [ self.object5, self.object4, self.object2, self.object1, self.object3 ] # Sorted by version, then name. expected_result_possibility_2 = [ self.object5, self.object1, self.object4, self.object3, self.object2 ] assert(natural_sort.sort(self.objects_to_sort) == expected_result_possibility_1 or natural_sort.sort(self.objects_to_sort) == expected_result_possibility_2)
def test_sorting_empty_list(self): assert(natural_sort.sort([]) == [])