diff options
author | Picca Frédéric-Emmanuel <picca@debian.org> | 2017-10-07 07:59:01 +0200 |
---|---|---|
committer | Picca Frédéric-Emmanuel <picca@debian.org> | 2017-10-07 07:59:01 +0200 |
commit | bfa4dba15485b4192f8bbe13345e9658c97ecf76 (patch) | |
tree | fb9c6e5860881fbde902f7cbdbd41dc4a3a9fb5d /silx/gui/test/utils.py | |
parent | f7bdc2acff3c13a6d632c28c4569690ab106eed7 (diff) |
New upstream version 0.6.0+dfsg
Diffstat (limited to 'silx/gui/test/utils.py')
-rw-r--r-- | silx/gui/test/utils.py | 36 |
1 files changed, 32 insertions, 4 deletions
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 """ |