Пример #1
0
    def _image_grouping(self, images: Collection[core.Image]) -> None:
        gen = core.image_grouping(images, self._conf['sensitivity'])
        duplicates_found = 0
        groups_num = 0
        for group in gen:
            if self._interrupted:
                self.interrupted.emit()
                return

            group_index, image_group = group

            if groups_num == group_index:  # new group
                duplicates_found += len(image_group)
                groups_num += 1
            else:
                # if it's an existing group, a new image was added to the group
                duplicates_found += 1

            self.duplicates_found.emit(duplicates_found)
            self.groups_found.emit(groups_num)

            # shallow copy of an image group
            # cause don't want to mess with mutexes
            self.image_group.emit((group_index, image_group.copy()))

        self._update_progressbar(self.PROG_MAX)

        self.image_group.emit((0, []))
Пример #2
0
    def test_closest_called_with_bktree_image_and_sensitivity_args(self):
        with mock.patch('pybktree.BKTree', return_value='bktree'):
            with mock.patch(CORE + '_closest',
                            return_value=(None, None)) as mock_closest_call:
                list(core.image_grouping(self.images, 0))

        calls = [
            mock.call('bktree', self.mock_image1, 0),
            mock.call('bktree', self.mock_image2, 0)
        ]
        mock_closest_call.assert_has_calls(calls)
Пример #3
0
    def test_return_if_image_not_in_checked_and_closest_in_checked(self):
        checked = {self.mock_image2: 0}
        with mock.patch('builtins.dict', return_value=checked):
            with mock.patch(CORE + '_closest',
                            return_value=(1, self.mock_image2)):
                with mock.patch(CORE + '_add_img_to_existing_group',
                                return_value='exist_group') as mock_add_call:
                    res = list(core.image_grouping([self.mock_image1], 1))

        mock_add_call.assert_called_once_with(self.mock_image2,
                                              self.mock_image1, checked, [])
        self.assertListEqual(res, ['exist_group'])
Пример #4
0
    def test_yield_add_new_group_res_if_image_and_closest_not_in_checked(self):
        checked = {}
        with mock.patch('builtins.dict', return_value=checked):
            with mock.patch(CORE + '_closest',
                            return_value=(1, self.mock_image2)):
                with mock.patch(CORE + '_add_new_group',
                                return_value='new_group') as mock_add_call:
                    res = list(core.image_grouping([self.mock_image1], 1))

        mock_add_call.assert_called_once_with(self.mock_image1,
                                              self.mock_image2, checked, [], 1)
        self.assertListEqual(res, ['new_group'])
Пример #5
0
    def test_loop_continue_if_there_is_no_closest_image(self):
        with mock.patch(CORE + '_closest', return_value=(None, None)):
            with mock.patch(CORE + '_add_new_group') as mock_add_call:
                list(core.image_grouping(self.images, 0))

        mock_add_call.assert_not_called()
Пример #6
0
 def test_raise_TypeError_if_BKTree_raise_TypeError(self):
     with mock.patch('pybktree.BKTree', side_effect=TypeError):
         with self.assertRaises(TypeError):
             list(core.image_grouping(self.images, 0))
Пример #7
0
    def test_BKTree_called_with_hamming_dist_and_images_args(self):
        with mock.patch('pybktree.BKTree') as mock_tree_call:
            with mock.patch(CORE + '_closest', return_value=(None, None)):
                list(core.image_grouping(self.images, 0))

        mock_tree_call.assert_called_once_with(core.Image.hamming, self.images)
Пример #8
0
    def test_return_nothing_if_no_image_groups(self):
        res = list(core.image_grouping([], 0))

        self.assertListEqual(res, [])