def test_lambda_returning_Image_difference_returned_if_sort_type_0(self):
        s = core.Sort(0)
        mock_image = mock.Mock(spec=core.Image)
        mock_image.difference = 32
        res = s.key()

        self.assertEqual(res(mock_image), 32)
    def test_lambda_returning_Image_path_returned_if_sort_type_3(self):
        s = core.Sort(3)
        mock_image = mock.Mock(spec=core.Image)
        mock_image.path = 'path'
        res = s.key()

        self.assertEqual(res(mock_image), 'path')
    def test_lambda_returning_neg_Image_size_returned_if_sort_type_1(self):
        s = core.Sort(1)
        mock_image = mock.Mock(spec=core.Image)
        mock_image.size = 23
        res = s.key()

        self.assertEqual(res(mock_image), -23)
    def test_sort_called_with_Sort_key_func_return_as_arg(self):
        mock_images = mock.Mock(spec=list)
        s = core.Sort(2)
        with mock.patch(CORE + 'Sort.key', return_value='key_func'):
            s.sort(mock_images)

        mock_images.sort.assert_called_once_with(key='key_func')
    def test_lambda_returning_neg_Image_w_h_prod_returned_if_sort_type_2(self):
        s = core.Sort(2)
        mock_image = mock.Mock(spec=core.Image)
        mock_image.width = 10
        mock_image.height = 13
        res = s.key()

        self.assertEqual(res(mock_image), -130)
示例#6
0
    def _insertIndex(self, new_w: duplicatewidget.DuplicateWidget) -> int:
        key = core.Sort(self._conf['sort']).key()

        left, right = 0, len(self.widgets) - 1
        new_w_key = key(new_w.image)

        while left <= right:
            middle = (right + left) // 2

            if new_w_key < key(self.widgets[middle].image):
                right = middle - 1
            else:
                left = middle + 1

        return left
 def test_raise_ValueError_if_pass_not_implemented_sort_type(self):
     with self.assertRaises(ValueError):
         core.Sort(10)
    def test_passed_sort_type_assigned_to_attr_sort_type(self):
        s = core.Sort(2)

        self.assertEqual(s._sort_type, 2)
    def test_default_sort_type(self):
        s = core.Sort()

        self.assertEqual(s._sort_type, 0)