# Path: orangecontrib/imageanalytics/import_images.py
# class ImportImages:
#     """
#     Importing images into a data table. Scripting part.
# 
#         Examples
#         --------
#         >>> from orangecontrib.imageanalytics.import_images import ImportImages
#         >>> import_images = ImportImages()
#         >>> data, err = import_images("file path")
#         """
#     ImgData = namedtuple(
#         "ImgData",
#         ["path", "format", "height", "width", "size"]
#     )
#     ImgData.isvalid = property(lambda self: True)
# 
#     ImgDataError = namedtuple(
#         "ImgDataError",
#         ["path", "error", "error_str"]
#     )
#     ImgDataError.isvalid = property(lambda self: False)
# 
#     def __init__(self, formats=None, report_progress=None,
#                  case_insensitive=True):
#         if formats is not None:
#             warn(
#                 "formats parameter is deprecated and will be removed in "
#                 "orange3-imageanalytics 0.9.0",
#                 FutureWarning,
#             )
#         self.formats = formats
#         self.report_progress = report_progress
#         self.cancelled = False
#         self.case_insensitive = case_insensitive
# 
#     def __call__(self, start_dir):
#         patterns = ('*',)
#         if self.formats is not None:
#             patterns = ["*.{}".format(fmt.lower() if self.case_insensitive else fmt)
#                         for fmt in self.formats]
# 
#         images = self.image_meta(scan(start_dir), patterns) or []
#         categories = {}
#         for imeta in images:
#             # derive categories from the path relative to the starting dir
#             dirname = os.path.dirname(imeta.path)
#             relpath = os.path.relpath(dirname, start_dir)
#             categories[dirname] = relpath
# 
#         return create_table(images, categories=categories, start_dir=start_dir)
# 
#     def image_meta(self, filescanner, patterns=('*', )):
#         def fnmatch_any(fname, patterns):
#             return any(fnmatch.fnmatch(fname.lower() if self.case_insensitive else fname, pattern)
#                        for pattern in patterns)
# 
#         imgmeta = []
#         batch = []
# 
#         for path in filescanner:
#             if fnmatch_any(path, patterns):
#                 imeta = image_meta_data(path)
#                 imgmeta.append(imeta)
#                 batch.append(imgmeta)
# 
#             if self.cancelled:
#                 return
#                 # raise UserInterruptError
# 
#             if len(batch) == 10 and self.report_progress is not None:
#                 self.report_progress(
#                     namespace(count=len(imgmeta),
#                               lastpath=imgmeta[-1].path,
#                               batch=batch))
#                 batch = []
# 
#         if batch and self.report_progress is not None:
#             self.report_progress(
#                     namespace(count=len(imgmeta),
#                               lastpath=imgmeta[-1].path,
#                               batch=batch))
# 
#         return imgmeta


import logging
import unittest
from os.path import dirname, join
from pkg_resources import get_distribution
from orangecontrib.imageanalytics.import_images import ImportImages
        self.import_images = ImportImages()

    def tearDown(self):
        logging.disable(logging.NOTSET)

    def test_import_cancelled(self):
        """
        Script or widget should not crash if importing is cancelled and result is None
        which cannot be iterable.
        GH-68
        """
        import_images = self.import_images
        import_images.cancelled = True
        import_images("/")

    def test_import_various_formats(self):
        """
        Test if all formats from test_images can be loaded. This directory
        includes all currently supported formats by QImageReader
        """
        table, n_skipped = self.import_images(join(dirname(__file__), "test_images"))
        self.assertEqual(16, len(table))
        self.assertEqual(0, n_skipped)

    def test_deprecation(self):
        """
        When this test starts to fail remove it and remove formats parameter
        from the ImportImages class and everything connected with it.
        """
        self.assertLess(get_distribution("orange3-imageanalytics").version, "0.9.0")

# Path: orangecontrib/imageanalytics/import_images.py
# class ImportImages:
#     """
#     Importing images into a data table. Scripting part.
# 
#         Examples
#         --------
#         >>> from orangecontrib.imageanalytics.import_images import ImportImages
#         >>> import_images = ImportImages()
#         >>> data, err = import_images("file path")
#         """
#     ImgData = namedtuple(
#         "ImgData",
#         ["path", "format", "height", "width", "size"]
#     )
#     ImgData.isvalid = property(lambda self: True)
# 
#     ImgDataError = namedtuple(
#         "ImgDataError",
#         ["path", "error", "error_str"]
#     )
#     ImgDataError.isvalid = property(lambda self: False)
# 
#     def __init__(self, formats=None, report_progress=None,
#                  case_insensitive=True):
#         if formats is not None:
#             warn(
#                 "formats parameter is deprecated and will be removed in "
#                 "orange3-imageanalytics 0.9.0",
#                 FutureWarning,
#             )
#         self.formats = formats
#         self.report_progress = report_progress
#         self.cancelled = False
#         self.case_insensitive = case_insensitive
# 
#     def __call__(self, start_dir):
#         patterns = ('*',)
#         if self.formats is not None:
#             patterns = ["*.{}".format(fmt.lower() if self.case_insensitive else fmt)
#                         for fmt in self.formats]
# 
#         images = self.image_meta(scan(start_dir), patterns) or []
#         categories = {}
#         for imeta in images:
#             # derive categories from the path relative to the starting dir
#             dirname = os.path.dirname(imeta.path)
#             relpath = os.path.relpath(dirname, start_dir)
#             categories[dirname] = relpath
# 
#         return create_table(images, categories=categories, start_dir=start_dir)
# 
#     def image_meta(self, filescanner, patterns=('*', )):
#         def fnmatch_any(fname, patterns):
#             return any(fnmatch.fnmatch(fname.lower() if self.case_insensitive else fname, pattern)
#                        for pattern in patterns)
# 
#         imgmeta = []
#         batch = []
# 
#         for path in filescanner:
#             if fnmatch_any(path, patterns):
#                 imeta = image_meta_data(path)
#                 imgmeta.append(imeta)
#                 batch.append(imgmeta)
# 
#             if self.cancelled:
#                 return
#                 # raise UserInterruptError
# 
#             if len(batch) == 10 and self.report_progress is not None:
#                 self.report_progress(
#                     namespace(count=len(imgmeta),
#                               lastpath=imgmeta[-1].path,
#                               batch=batch))
#                 batch = []
# 
#         if batch and self.report_progress is not None:
#             self.report_progress(
#                     namespace(count=len(imgmeta),
#                               lastpath=imgmeta[-1].path,
#                               batch=batch))
# 
#         return imgmeta


# Path: orangecontrib/imageanalytics/tests/test_import_images.py
import logging
import unittest
from os.path import dirname, join
from pkg_resources import get_distribution
from orangecontrib.imageanalytics.import_images import ImportImages

        self.import_images = ImportImages()

    def tearDown(self):
        logging.disable(logging.NOTSET)

    def test_import_cancelled(self):
        """
        Script or widget should not crash if importing is cancelled and result is None
        which cannot be iterable.
        GH-68
        """
        import_images = self.import_images
        import_images.cancelled = True
        import_images("/")

    def test_import_various_formats(self):
        """
        Test if all formats from test_images can be loaded. This directory
        includes all currently supported formats by QImageReader
        """
        table, n_skipped = self.import_images(join(dirname(__file__), "test_images"))
        self.assertEqual(16, len(table))
        self.assertEqual(0, n_skipped)

    def test_deprecation(self):
        """
        When this test starts to fail remove it and remove formats parameter
        from the ImportImages class and everything connected with it.
        """
        self.assertLess(get_distribution("orange3-imageanalytics").version, "0.9.0")

        self.import_images = ImportImages(formats=("jpg", "png"))