예제 #1
0
    def test_glob_pattern_if_nonrecursive_search(self):
        self.mock_path.exists.return_value = True
        self.mock_path.glob.return_value = []
        with mock.patch(CORE + 'Path', return_value=self.mock_path):
            list(core.find_image(['folder'], recursive=False))

        self.mock_path.glob.assert_called_once_with('*')
예제 #2
0
    def test_return_nothing_if_path_isnt_file(self):
        self.mock_path.exists.return_value = True
        image_path = mock.Mock(spec=Path)
        image_path.is_file.return_value = False
        self.mock_path.glob.return_value = [image_path]
        with mock.patch(CORE + 'Path', return_value=self.mock_path):
            res = list(core.find_image(['folder'], recursive=False))

        self.assertListEqual(res, [])
예제 #3
0
    def test_return_proper_Image_obj(self):
        self.mock_path.exists.return_value = True
        image_path = mock.MagicMock(spec=Path)
        image_path.is_file.return_value = True
        image_path.suffix = '.png'
        image_path.__str__.return_value = 'img_path'
        self.mock_path.glob.return_value = [image_path]
        with mock.patch(CORE + 'Path', return_value=self.mock_path):
            res = list(core.find_image(['folder'], recursive=False))

        self.assertEqual(len(res), 1)
        self.assertEqual(res[0].path, 'img_path')
예제 #4
0
    def _find_images(self) -> Set[core.Image]:
        filter_size = self._conf['filter_img_size']
        min_w, max_w = self._conf['min_width'], self._conf['max_width']
        min_h, max_h = self._conf['min_height'], self._conf['max_height']

        images = set()
        gen = core.find_image(self._folders, self._conf['subfolders'])
        for img in gen:
            if self._interrupted:
                self.interrupted.emit()
                return set()

            if not filter_size or (min_w <= img.width <= max_w
                                   and min_h <= img.height <= max_h):
                images.add(img)
                # Slower than showing the result number
                self.images_loaded.emit(len(images))

        if not images:
            self.image_group.emit((0, []))

        return images
예제 #5
0
 def test_raise_FileNotFoundError(self):
     self.mock_path.exists.return_value = False
     with mock.patch(CORE + 'Path', return_value=self.mock_path):
         with self.assertRaises(FileNotFoundError):
             list(core.find_image(['folder']))
예제 #6
0
    def test_return_nothing_if_pass_empty_folders_list(self):
        paths = list(core.find_image([]))

        self.assertListEqual(paths, [])