diff options
author | Picca Frédéric-Emmanuel <picca@synchrotron-soleil.fr> | 2017-08-18 14:48:52 +0200 |
---|---|---|
committer | Picca Frédéric-Emmanuel <picca@synchrotron-soleil.fr> | 2017-08-18 14:48:52 +0200 |
commit | f7bdc2acff3c13a6d632c28c4569690ab106eed7 (patch) | |
tree | 9d67cdb7152ee4e711379e03fe0546c7c3b97303 /silx/app/test |
Import Upstream version 0.5.0+dfsg
Diffstat (limited to 'silx/app/test')
-rw-r--r-- | silx/app/test/__init__.py | 41 | ||||
-rw-r--r-- | silx/app/test/test_view.py | 135 |
2 files changed, 176 insertions, 0 deletions
diff --git a/silx/app/test/__init__.py b/silx/app/test/__init__.py new file mode 100644 index 0000000..54241dc --- /dev/null +++ b/silx/app/test/__init__.py @@ -0,0 +1,41 @@ +# coding: utf-8 +# /*########################################################################## +# +# 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 +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +# +# ###########################################################################*/ +__authors__ = ["V. Valls"] +__license__ = "MIT" +__date__ = "30/03/2017" + + +import logging +import os +import sys +import unittest + + +_logger = logging.getLogger(__name__) + + +def suite(): + test_suite = unittest.TestSuite() + return test_suite diff --git a/silx/app/test/test_view.py b/silx/app/test/test_view.py new file mode 100644 index 0000000..774bc01 --- /dev/null +++ b/silx/app/test/test_view.py @@ -0,0 +1,135 @@ +# coding: utf-8 +# /*########################################################################## +# +# 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 +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +# +# ###########################################################################*/ +"""Module testing silx.app.view""" + +__authors__ = ["V. Valls"] +__license__ = "MIT" +__date__ = "12/04/2017" + + +import unittest +from silx.gui.test.utils import TestCaseQt +from .. import view +import sys + + +class QApplicationMock(object): + + def __init__(self, args): + pass + + def exec_(self): + return 0 + + def deleteLater(self): + pass + + +class ViewerMock(object): + + def __init__(self): + super(ViewerMock, self).__init__() + self.__class__._instance = self + self.appendFileCalls = [] + + def appendFile(self, filename): + self.appendFileCalls.append(filename) + + def resize(self, size): + pass + + def show(self): + pass + + +class TestLauncher(unittest.TestCase): + """Test command line parsing""" + + @classmethod + def setUpClass(cls): + super(TestLauncher, cls).setUpClass() + cls._Viewer = view.Viewer + view.Viewer = ViewerMock + cls._QApplication = view.qt.QApplication + view.qt.QApplication = QApplicationMock + + @classmethod + def tearDownClass(cls): + view.Viewer = cls._Viewer + view.qt.QApplication = cls._QApplication + cls._Viewer = None + super(TestLauncher, cls).tearDownClass() + + def testHelp(self): + try: + result = view.main(["view", "--help"]) + self.assertNotEqual(result, 0) + except SystemExit as e: + result = e.args[0] + self.assertEqual(result, 0) + + def testWrongOption(self): + try: + result = view.main(["view", "--foo"]) + self.assertNotEqual(result, 0) + except SystemExit as e: + result = e.args[0] + self.assertNotEqual(result, 0) + + def testWrongFile(self): + try: + result = view.main(["view", "__file.not.found__"]) + self.assertNotEqual(result, 0) + except SystemExit as e: + result = e.args[0] + self.assertNotEqual(result, 0) + + def testFile(self): + # sys.executable is an existing readable file + result = view.main(["view", sys.executable]) + self.assertEqual(result, 0) + viewer = ViewerMock._instance + self.assertEqual(viewer.appendFileCalls, [sys.executable]) + ViewerMock._instance = None + + +class TestViewer(TestCaseQt): + """Test for Viewer class""" + + def testConstruct(self): + widget = view.Viewer() + self.qWaitForWindowExposed(widget) + + +def suite(): + test_suite = unittest.TestSuite() + loader = unittest.defaultTestLoader.loadTestsFromTestCase + test_suite.addTest(loader(TestViewer)) + test_suite.addTest(loader(TestLauncher)) + return test_suite + + +if __name__ == '__main__': + unittest.main(defaultTest='suite') |