# Path: DataPlotly/gui/gui_utils.py
# class GuiUtils:
#     """
#     Utilities for GUI plugin components
#     """
# 
#     @staticmethod
#     def get_icon(icon: str) -> QIcon:
#         """
#         Returns a plugin icon
#         :param icon: icon name (svg file name)
#         :return: QIcon
#         """
#         path = GuiUtils.get_icon_svg(icon)
#         if not path:
#             return QIcon()
# 
#         return QIcon(path)
# 
#     @staticmethod
#     def get_icon_svg(icon: str) -> str:
#         """
#         Returns a plugin icon's SVG file path
#         :param icon: icon name (svg file name)
#         :return: icon svg path
#         """
#         path = os.path.join(
#             os.path.dirname(__file__),
#             '..',
#             'icons',
#             icon)
#         if not os.path.exists(path):
#             return ''
# 
#         return path
# 
#     @staticmethod
#     def get_ui_file_path(file: str) -> str:
#         """
#         Returns a UI file's path
#         :param file: file name (uifile name)
#         :return: ui file path
#         """
#         path = os.path.join(
#             os.path.dirname(__file__),
#             '..',
#             'ui',
#             file)
#         if not os.path.exists(path):
#             return ''
# 
#         return path
# 
# Path: DataPlotly/test/utilities.py
# def get_qgis_app(cleanup=True):
#     """ Start one QGIS application to test against.
# 
#     :returns: Handle to QGIS app, canvas, iface and parent. If there are any
#         errors the tuple members will be returned as None.
#     :rtype: (QgsApplication, CANVAS, IFACE, PARENT)
# 
#     If QGIS is already running the handle to that app will be returned.
#     """
# 
#     global QGIS_APP, PARENT, IFACE, CANVAS  # pylint: disable=W0603
# 
#     if iface:
#         QGIS_APP = QgsApplication
#         CANVAS = iface.mapCanvas()
#         PARENT = iface.mainWindow()
#         IFACE = iface
#         return QGIS_APP, CANVAS, IFACE, PARENT
# 
#     global QGISAPP  # pylint: disable=global-variable-undefined
# 
#     try:
#         QGISAPP
#     except NameError:
#         myGuiFlag = True  # All test will run qgis in gui mode
# 
#         # In python3 we need to convert to a bytes object (or should
#         # QgsApplication accept a QString instead of const char* ?)
#         try:
#             argvb = list(map(os.fsencode, sys.argv))
#         except AttributeError:
#             argvb = sys.argv
# 
#         # Note: QGIS_PREFIX_PATH is evaluated in QgsApplication -
#         # no need to mess with it here.
#         QGISAPP = QgsApplication(argvb, myGuiFlag)
# 
#         QGISAPP.initQgis()
#         s = QGISAPP.showSettings()
#         LOGGER.debug(s)
# 
#         def debug_log_message(message, tag, level):
#             """
#             Prints a debug message to a log
#             :param message: message to print
#             :param tag: log tag
#             :param level: log message level (severity)
#             :return:
#             """
#             print('{}({}): {}'.format(tag, level, message))
# 
#         QgsApplication.instance().messageLog().messageReceived.connect(
#             debug_log_message)
# 
#         if cleanup:
#             @atexit.register
#             def exitQgis():  # pylint: disable=unused-variable
#                 """
#                 Gracefully closes the QgsApplication instance
#                 """
#                 try:
#                     QGISAPP.exitQgis()  # pylint: disable=used-before-assignment
#                     QGISAPP = None  # pylint: disable=redefined-outer-name
#                 except NameError:
#                     pass
# 
#     if PARENT is None:
#         # noinspection PyPep8Naming
#         PARENT = QWidget()
# 
#     if CANVAS is None:
#         # noinspection PyPep8Naming
#         CANVAS = QgsMapCanvas(PARENT)
#         CANVAS.resize(QSize(400, 400))
# 
#     if IFACE is None:
#         # QgisInterface is a stub implementation of the QGIS plugin interface
#         # noinspection PyPep8Naming
#         IFACE = QgisInterface(CANVAS)
# 
#     return QGISAPP, CANVAS, IFACE, PARENT


import unittest
from DataPlotly.gui.gui_utils import GuiUtils
from .utilities import get_qgis_app
"""

__author__ = '(C) 2018 by Nyall Dawson'
__date__ = '20/04/2018'
__copyright__ = 'Copyright 2018, North Road'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'


QGIS_APP = get_qgis_app()


class GuiUtilsTest(unittest.TestCase):
    """Test GuiUtils work."""

    def testGetIcon(self):
        """
        Tests get_icon
        """
        self.assertFalse(
            GuiUtils.get_icon('dataplotly.svg').isNull())
        self.assertTrue(GuiUtils.get_icon('not_an_icon.svg').isNull())

    def testGetIconSvg(self):
        """
        Tests get_icon svg path
        """
        self.assertTrue(
            GuiUtils.get_icon_svg('dataplotly.svg'))
        self.assertIn('dataplotly.svg',

# Path: DataPlotly/gui/gui_utils.py
# class GuiUtils:
#     """
#     Utilities for GUI plugin components
#     """
# 
#     @staticmethod
#     def get_icon(icon: str) -> QIcon:
#         """
#         Returns a plugin icon
#         :param icon: icon name (svg file name)
#         :return: QIcon
#         """
#         path = GuiUtils.get_icon_svg(icon)
#         if not path:
#             return QIcon()
# 
#         return QIcon(path)
# 
#     @staticmethod
#     def get_icon_svg(icon: str) -> str:
#         """
#         Returns a plugin icon's SVG file path
#         :param icon: icon name (svg file name)
#         :return: icon svg path
#         """
#         path = os.path.join(
#             os.path.dirname(__file__),
#             '..',
#             'icons',
#             icon)
#         if not os.path.exists(path):
#             return ''
# 
#         return path
# 
#     @staticmethod
#     def get_ui_file_path(file: str) -> str:
#         """
#         Returns a UI file's path
#         :param file: file name (uifile name)
#         :return: ui file path
#         """
#         path = os.path.join(
#             os.path.dirname(__file__),
#             '..',
#             'ui',
#             file)
#         if not os.path.exists(path):
#             return ''
# 
#         return path
# 
# Path: DataPlotly/test/utilities.py
# def get_qgis_app(cleanup=True):
#     """ Start one QGIS application to test against.
# 
#     :returns: Handle to QGIS app, canvas, iface and parent. If there are any
#         errors the tuple members will be returned as None.
#     :rtype: (QgsApplication, CANVAS, IFACE, PARENT)
# 
#     If QGIS is already running the handle to that app will be returned.
#     """
# 
#     global QGIS_APP, PARENT, IFACE, CANVAS  # pylint: disable=W0603
# 
#     if iface:
#         QGIS_APP = QgsApplication
#         CANVAS = iface.mapCanvas()
#         PARENT = iface.mainWindow()
#         IFACE = iface
#         return QGIS_APP, CANVAS, IFACE, PARENT
# 
#     global QGISAPP  # pylint: disable=global-variable-undefined
# 
#     try:
#         QGISAPP
#     except NameError:
#         myGuiFlag = True  # All test will run qgis in gui mode
# 
#         # In python3 we need to convert to a bytes object (or should
#         # QgsApplication accept a QString instead of const char* ?)
#         try:
#             argvb = list(map(os.fsencode, sys.argv))
#         except AttributeError:
#             argvb = sys.argv
# 
#         # Note: QGIS_PREFIX_PATH is evaluated in QgsApplication -
#         # no need to mess with it here.
#         QGISAPP = QgsApplication(argvb, myGuiFlag)
# 
#         QGISAPP.initQgis()
#         s = QGISAPP.showSettings()
#         LOGGER.debug(s)
# 
#         def debug_log_message(message, tag, level):
#             """
#             Prints a debug message to a log
#             :param message: message to print
#             :param tag: log tag
#             :param level: log message level (severity)
#             :return:
#             """
#             print('{}({}): {}'.format(tag, level, message))
# 
#         QgsApplication.instance().messageLog().messageReceived.connect(
#             debug_log_message)
# 
#         if cleanup:
#             @atexit.register
#             def exitQgis():  # pylint: disable=unused-variable
#                 """
#                 Gracefully closes the QgsApplication instance
#                 """
#                 try:
#                     QGISAPP.exitQgis()  # pylint: disable=used-before-assignment
#                     QGISAPP = None  # pylint: disable=redefined-outer-name
#                 except NameError:
#                     pass
# 
#     if PARENT is None:
#         # noinspection PyPep8Naming
#         PARENT = QWidget()
# 
#     if CANVAS is None:
#         # noinspection PyPep8Naming
#         CANVAS = QgsMapCanvas(PARENT)
#         CANVAS.resize(QSize(400, 400))
# 
#     if IFACE is None:
#         # QgisInterface is a stub implementation of the QGIS plugin interface
#         # noinspection PyPep8Naming
#         IFACE = QgisInterface(CANVAS)
# 
#     return QGISAPP, CANVAS, IFACE, PARENT


# Path: DataPlotly/test/test_guiutils.py
import unittest
from DataPlotly.gui.gui_utils import GuiUtils
from .utilities import get_qgis_app

"""

__author__ = '(C) 2018 by Nyall Dawson'
__date__ = '20/04/2018'
__copyright__ = 'Copyright 2018, North Road'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'


QGIS_APP = get_qgis_app()


class GuiUtilsTest(unittest.TestCase):
    """Test GuiUtils work."""

    def testGetIcon(self):
        """
        Tests get_icon
        """
        self.assertFalse(
            GuiUtils.get_icon('dataplotly.svg').isNull())
        self.assertTrue(GuiUtils.get_icon('not_an_icon.svg').isNull())

    def testGetIconSvg(self):
        """
        Tests get_icon svg path
        """
        self.assertTrue(
            GuiUtils.get_icon_svg('dataplotly.svg'))
        self.assertIn('dataplotly.svg',

                      GuiUtils.get_icon_svg('dataplotly.svg'))