diff options
Diffstat (limited to 'silx/gui/test')
-rw-r--r-- | silx/gui/test/test_icons.py | 56 | ||||
-rw-r--r-- | silx/gui/test/utils.py | 36 |
2 files changed, 81 insertions, 11 deletions
diff --git a/silx/gui/test/test_icons.py b/silx/gui/test/test_icons.py index f363c43..d747761 100644 --- a/silx/gui/test/test_icons.py +++ b/silx/gui/test/test_icons.py @@ -26,13 +26,17 @@ __authors__ = ["V. Valls"] __license__ = "MIT" -__date__ = "26/04/2017" +__date__ = "06/09/2017" import gc import unittest import weakref +import tempfile +import shutil +import os +import silx.resources from silx.gui import qt from silx.gui.test.utils import TestCaseQt from silx.gui import icons @@ -41,14 +45,49 @@ from silx.gui import icons class TestIcons(TestCaseQt): """Test to check that icons module.""" + @classmethod + def setUpClass(cls): + super(TestIcons, cls).setUpClass() + + cls.tmpDirectory = tempfile.mkdtemp(prefix="resource_") + os.mkdir(os.path.join(cls.tmpDirectory, "gui")) + destination = os.path.join(cls.tmpDirectory, "gui", "icons") + os.mkdir(destination) + shutil.copy(silx.resources.resource_filename("gui/icons/zoom-in.png"), destination) + shutil.copy(silx.resources.resource_filename("gui/icons/zoom-out.svg"), destination) + + @classmethod + def tearDownClass(cls): + super(TestIcons, cls).tearDownClass() + shutil.rmtree(cls.tmpDirectory) + + def setUp(self): + # Store the original configuration + self._oldResources = dict(silx.resources._RESOURCE_DIRECTORIES) + silx.resources.register_resource_directory("test", "foo.bar", forced_path=self.tmpDirectory) + unittest.TestCase.setUp(self) + + def tearDown(self): + unittest.TestCase.tearDown(self) + # Restiture the original configuration + silx.resources._RESOURCE_DIRECTORIES = self._oldResources + + def testIcon(self): + icon = icons.getQIcon("silx:gui/icons/zoom-out") + self.assertIsNotNone(icon) + + def testPrefix(self): + icon = icons.getQIcon("silx:gui/icons/zoom-out") + self.assertIsNotNone(icon) + def testSvgIcon(self): if "svg" not in qt.supportedImageFormats(): self.skipTest("SVG not supported") - icon = icons.getQIcon("test-svg") + icon = icons.getQIcon("test:gui/icons/zoom-out") self.assertIsNotNone(icon) def testPngIcon(self): - icon = icons.getQIcon("test-png") + icon = icons.getQIcon("test:gui/icons/zoom-in") self.assertIsNotNone(icon) def testUnexistingIcon(self): @@ -99,16 +138,19 @@ class TestAnimatedIcons(TestCaseQt): icon = icons.MultiImageAnimatedIcon("process-working") self.assertIsNotNone(icon) + def testPrefixedResourceExists(self): + icon = icons.MultiImageAnimatedIcon("silx:gui/icons/process-working") + self.assertIsNotNone(icon) + def testMultiImageIconNotExists(self): self.assertRaises(ValueError, icons.MultiImageAnimatedIcon, "not-exists") def suite(): + loadTests = unittest.defaultTestLoader.loadTestsFromTestCase test_suite = unittest.TestSuite() - test_suite.addTest( - unittest.defaultTestLoader.loadTestsFromTestCase(TestIcons)) - test_suite.addTest( - unittest.defaultTestLoader.loadTestsFromTestCase(TestAnimatedIcons)) + test_suite.addTest(loadTests(TestIcons)) + test_suite.addTest(loadTests(TestAnimatedIcons)) return test_suite diff --git a/silx/gui/test/utils.py b/silx/gui/test/utils.py index 50cf7bf..19c448a 100644 --- a/silx/gui/test/utils.py +++ b/silx/gui/test/utils.py @@ -1,7 +1,7 @@ # coding: utf-8 # /*########################################################################## # -# Copyright (c) 2016 European Synchrotron Radiation Facility +# Copyright (c) 2016-2017 European Synchrotron Radiation Facility # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -26,7 +26,7 @@ __authors__ = ["T. Vincent"] __license__ = "MIT" -__date__ = "11/04/2017" +__date__ = "01/09/2017" import gc @@ -35,8 +35,8 @@ import unittest import time import functools import sys +import os -logging.basicConfig() _logger = logging.getLogger(__name__) from silx.gui import qt @@ -349,8 +349,36 @@ class TestCaseQt(unittest.TestCase): return result + def logScreenShot(self, level=logging.ERROR): + """Take a screenshot and log it into the logging system if the + logger is enabled for the expected level. -class SignalListener(): + The screenshot is stored in the directory "./build/test-debug", and + the logging system only log the path to this file. + + :param level: Logging level + """ + if not _logger.isEnabledFor(level): + return + basedir = os.path.abspath(os.path.join("build", "test-debug")) + if not os.path.exists(basedir): + os.makedirs(basedir) + filename = "Screenshot_%s.png" % self.id() + filename = os.path.join(basedir, filename) + + if not hasattr(self.qapp, "primaryScreen"): + # Qt4 + winId = qt.QApplication.desktop().winId() + pixmap = qt.QPixmap.grabWindow(winId) + else: + # Qt5 + screen = self.qapp.primaryScreen() + pixmap = screen.grabWindow(0) + pixmap.save(filename) + _logger.log(level, "Screenshot saved at %s", filename) + + +class SignalListener(object): """Util to listen a Qt event and store parameters """ |