# 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
        self.assertListEqual(expected_paths, paths)

        # test with string variable including unknown values
        with table.unlocked():
            table.metas[0, 0] = ""
        paths = extract_paths(table, column=table.domain.metas[0])
        self.assertListEqual([None] + expected_paths[1:], paths)

        # test with categorical variable
        var = DiscreteVariable("images", values=images)
        var.attributes.update(table.domain.metas[0].attributes)
        new_domain = Domain([], metas=[var])
        new_table = Table.from_numpy(
            new_domain, np.empty((4, 0)), metas=np.array([[0], [1], [2], [3]])
        )
        paths = extract_paths(new_table, column=new_domain.metas[0])
        self.assertEqual(expected_paths, paths)

        # test with categorical variable including unknown values
        with table.unlocked():
            table.metas[0, 0] = ""
        paths = extract_paths(table, column=table.domain.metas[0])
        self.assertListEqual([None] + expected_paths[1:], paths)

        # test string no origin
        var = StringVariable("images")
        new_domain = Domain([], metas=[var])
        new_table = Table.from_numpy(
            new_domain, np.empty((4, 0)), metas=np.array([[f"/{x}"] for x in images])
        )

# 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

        self.assertListEqual(expected_paths, paths)

        # test with string variable including unknown values
        with table.unlocked():
            table.metas[0, 0] = ""
        paths = extract_paths(table, column=table.domain.metas[0])
        self.assertListEqual([None] + expected_paths[1:], paths)

        # test with categorical variable
        var = DiscreteVariable("images", values=images)
        var.attributes.update(table.domain.metas[0].attributes)
        new_domain = Domain([], metas=[var])
        new_table = Table.from_numpy(
            new_domain, np.empty((4, 0)), metas=np.array([[0], [1], [2], [3]])
        )
        paths = extract_paths(new_table, column=new_domain.metas[0])
        self.assertEqual(expected_paths, paths)

        # test with categorical variable including unknown values
        with table.unlocked():
            table.metas[0, 0] = ""
        paths = extract_paths(table, column=table.domain.metas[0])
        self.assertListEqual([None] + expected_paths[1:], paths)

        # test string no origin
        var = StringVariable("images")
        new_domain = Domain([], metas=[var])
        new_table = Table.from_numpy(
            new_domain, np.empty((4, 0)), metas=np.array([[f"/{x}"] for x in images])
        )

        paths = extract_paths(new_table, column=new_domain.metas[0])