# Path: orangecontrib/imageanalytics/utils/image_utils.py
# def filter_image_attributes(data: Table) -> List[Variable]:
#     """
#     Filter out attributes which can potentially be an image attributes. The
#     selection includes all String and Categorical attributes from meta part of
#     the table. Put attributes with "type" == "image" first - they are more likely
#     to be image attributes.
# 
#     Parameters
#     ----------
#     data
#         Table with data
# 
#     Returns
#     -------
#     List of variables that can be image attributes
#     """
#     m = data.domain.metas
#     m = [a for a in m if isinstance(a, (StringVariable, DiscreteVariable))]
#     return sorted(m, key=lambda a: a.attributes.get("type") == "image", reverse=True)
# 
# def extract_paths(
#     data: Table, column: Union[DiscreteVariable, StringVariable]
# ) -> List[Optional[str]]:
#     """
#     Extract image/file paths from datatable column. If column has an origin attribute
#     it will be added as a prefix to the path otherwise just values of column will be
#     returned.
# 
#     Parameters
#     ----------
#     data
#         Table that have column with file paths/URL in metas
#     column
#         Variable which is a path attribute. Must be string or categorical
# 
#     Returns
#     -------
#     List of file paths or URLs
#     """
#     return [extract_image_path(inst, column) for inst in data]
# 
# Path: orangecontrib/imageanalytics/widgets/tests/utils.py
# def load_images():
#     path = os.path.join(os.path.dirname(os.path.realpath(__file__)),
#                         "test_images")
#     files = [[x] for x in sorted(os.listdir(path))]
# 
#     image_var = StringVariable(name="Images")
#     image_var.attributes["type"] = "image"
#     image_var.attributes["origin"] = path
# 
#     table = Table(Domain([], [], [image_var]),
#                   np.empty((len(files), 0), dtype=float), None, files)
# 
#     return table


import os
import unittest
import numpy as np
from unittest import TestCase
from Orange.data import (
    Domain,
    DiscreteVariable,
    ContinuousVariable,
    Table,
    StringVariable,
)
from orangecontrib.imageanalytics.utils.image_utils import (
    filter_image_attributes,
    extract_paths,
)
from orangecontrib.imageanalytics.widgets.tests.utils import load_images
        # add some more attributes
        a, b, c = DiscreteVariable("a"), ContinuousVariable("b"), table.domain.metas[0]
        domain = Domain([], metas=[a, b, c])
        table_new = table.transform(domain)
        # c - attribute with image type should be first
        self.assertEqual([c, a], filter_image_attributes(table_new))

        domain = Domain([], metas=[])
        table_new = table.transform(domain)
        self.assertEqual([], filter_image_attributes(table_new))

    def test_extract_paths(self):
        origin = os.path.abspath(
            os.path.join(
                os.path.dirname(os.path.realpath(__file__)),
                "..", "..",
                "widgets",
                "tests",
                "test_images",
            )
        )
        images = [
            "afternoon-4175917_640.jpg",
            "atomium-4179270_640.jpg",
            "kittens-4020199_640.jpg",
            "landscape-2130524_640.jpg",
        ]
        expected_paths = [os.path.join(origin, image) for image in images]

        # test with string variable

# Path: orangecontrib/imageanalytics/utils/image_utils.py
# def filter_image_attributes(data: Table) -> List[Variable]:
#     """
#     Filter out attributes which can potentially be an image attributes. The
#     selection includes all String and Categorical attributes from meta part of
#     the table. Put attributes with "type" == "image" first - they are more likely
#     to be image attributes.
# 
#     Parameters
#     ----------
#     data
#         Table with data
# 
#     Returns
#     -------
#     List of variables that can be image attributes
#     """
#     m = data.domain.metas
#     m = [a for a in m if isinstance(a, (StringVariable, DiscreteVariable))]
#     return sorted(m, key=lambda a: a.attributes.get("type") == "image", reverse=True)
# 
# def extract_paths(
#     data: Table, column: Union[DiscreteVariable, StringVariable]
# ) -> List[Optional[str]]:
#     """
#     Extract image/file paths from datatable column. If column has an origin attribute
#     it will be added as a prefix to the path otherwise just values of column will be
#     returned.
# 
#     Parameters
#     ----------
#     data
#         Table that have column with file paths/URL in metas
#     column
#         Variable which is a path attribute. Must be string or categorical
# 
#     Returns
#     -------
#     List of file paths or URLs
#     """
#     return [extract_image_path(inst, column) for inst in data]
# 
# Path: orangecontrib/imageanalytics/widgets/tests/utils.py
# def load_images():
#     path = os.path.join(os.path.dirname(os.path.realpath(__file__)),
#                         "test_images")
#     files = [[x] for x in sorted(os.listdir(path))]
# 
#     image_var = StringVariable(name="Images")
#     image_var.attributes["type"] = "image"
#     image_var.attributes["origin"] = path
# 
#     table = Table(Domain([], [], [image_var]),
#                   np.empty((len(files), 0), dtype=float), None, files)
# 
#     return table


# Path: orangecontrib/imageanalytics/utils/tests/test_image_utils.py
import os
import unittest
import numpy as np
from unittest import TestCase
from Orange.data import (
    Domain,
    DiscreteVariable,
    ContinuousVariable,
    Table,
    StringVariable,
)
from orangecontrib.imageanalytics.utils.image_utils import (
    filter_image_attributes,
    extract_paths,
)
from orangecontrib.imageanalytics.widgets.tests.utils import load_images

        # add some more attributes
        a, b, c = DiscreteVariable("a"), ContinuousVariable("b"), table.domain.metas[0]
        domain = Domain([], metas=[a, b, c])
        table_new = table.transform(domain)
        # c - attribute with image type should be first
        self.assertEqual([c, a], filter_image_attributes(table_new))

        domain = Domain([], metas=[])
        table_new = table.transform(domain)
        self.assertEqual([], filter_image_attributes(table_new))

    def test_extract_paths(self):
        origin = os.path.abspath(
            os.path.join(
                os.path.dirname(os.path.realpath(__file__)),
                "..", "..",
                "widgets",
                "tests",
                "test_images",
            )
        )
        images = [
            "afternoon-4175917_640.jpg",
            "atomium-4179270_640.jpg",
            "kittens-4020199_640.jpg",
            "landscape-2130524_640.jpg",
        ]
        expected_paths = [os.path.join(origin, image) for image in images]

        # test with string variable

        table = load_images()