summaryrefslogtreecommitdiff
path: root/silx/app/view/test/test_launcher.py
diff options
context:
space:
mode:
authorFrédéric-Emmanuel Picca <picca@debian.org>2018-08-08 14:09:02 +0200
committerFrédéric-Emmanuel Picca <picca@debian.org>2018-08-08 14:09:02 +0200
commit75271d5d9979b204baf8172b2a03da4330b14083 (patch)
tree22a2e31692654f1464c6fc8463cafe6598d9bdc4 /silx/app/view/test/test_launcher.py
parent989033673e36f8d9959dd2d3a8285e5339bfae0c (diff)
parent302d3bcf3ef555284ce1bcf5cd7cd371addfa608 (diff)
Merge tag 'debian/0.8.0+dfsg-1' into debian/stretch-backports
silx release 0.8.0+dfsg-1 for unstable (sid) (maintainer view tag generated by dgit --quilt=gbp)
Diffstat (limited to 'silx/app/view/test/test_launcher.py')
-rw-r--r--silx/app/view/test/test_launcher.py145
1 files changed, 145 insertions, 0 deletions
diff --git a/silx/app/view/test/test_launcher.py b/silx/app/view/test/test_launcher.py
new file mode 100644
index 0000000..aabccf0
--- /dev/null
+++ b/silx/app/view/test/test_launcher.py
@@ -0,0 +1,145 @@
+# 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__ = "07/06/2018"
+
+
+import os
+import sys
+import unittest
+import logging
+import subprocess
+
+from silx.test.utils import test_options
+from .. import main
+from silx import __main__ as silx_main
+
+_logger = logging.getLogger(__name__)
+
+
+@unittest.skipUnless(test_options.WITH_QT_TEST, test_options.WITH_QT_TEST_REASON)
+class TestLauncher(unittest.TestCase):
+ """Test command line parsing"""
+
+ def testHelp(self):
+ # option -h must cause a raise SystemExit or a return 0
+ try:
+ parser = main.createParser()
+ parser.parse_args(["view", "--help"])
+ result = 0
+ except SystemExit as e:
+ result = e.args[0]
+ self.assertEqual(result, 0)
+
+ def testWrongOption(self):
+ try:
+ parser = main.createParser()
+ parser.parse_args(["view", "--foo"])
+ self.fail()
+ except SystemExit as e:
+ result = e.args[0]
+ self.assertNotEqual(result, 0)
+
+ def testWrongFile(self):
+ try:
+ parser = main.createParser()
+ result = parser.parse_args(["view", "__file.not.found__"])
+ result = 0
+ except SystemExit as e:
+ result = e.args[0]
+ self.assertEqual(result, 0)
+
+ def executeCommandLine(self, command_line, env):
+ """Execute a command line.
+
+ Log output as debug in case of bad return code.
+ """
+ _logger.info("Execute: %s", " ".join(command_line))
+ p = subprocess.Popen(command_line,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE,
+ env=env)
+ out, err = p.communicate()
+ _logger.info("Return code: %d", p.returncode)
+ try:
+ out = out.decode('utf-8')
+ except UnicodeError:
+ pass
+ try:
+ err = err.decode('utf-8')
+ except UnicodeError:
+ pass
+
+ if p.returncode != 0:
+ _logger.info("stdout:")
+ _logger.info("%s", out)
+ _logger.info("stderr:")
+ _logger.info("%s", err)
+ else:
+ _logger.debug("stdout:")
+ _logger.debug("%s", out)
+ _logger.debug("stderr:")
+ _logger.debug("%s", err)
+ self.assertEqual(p.returncode, 0)
+
+ def createTestEnv(self):
+ """
+ Returns an associated environment with a working project.
+ """
+ env = dict((str(k), str(v)) for k, v in os.environ.items())
+ env["PYTHONPATH"] = os.pathsep.join(sys.path)
+ return env
+
+ def testExecuteViewHelp(self):
+ """Test if the main module is well connected.
+
+ Uses subprocess to avoid to parasite the current environment.
+ """
+ env = self.createTestEnv()
+ commandLine = [sys.executable, main.__file__, "--help"]
+ self.executeCommandLine(commandLine, env)
+
+ def testExecuteSilxViewHelp(self):
+ """Test if the main module is well connected.
+
+ Uses subprocess to avoid to parasite the current environment.
+ """
+ env = self.createTestEnv()
+ commandLine = [sys.executable, silx_main.__file__, "view", "--help"]
+ self.executeCommandLine(commandLine, env)
+
+
+def suite():
+ test_suite = unittest.TestSuite()
+ loader = unittest.defaultTestLoader.loadTestsFromTestCase
+ test_suite.addTest(loader(TestLauncher))
+ return test_suite
+
+
+if __name__ == '__main__':
+ unittest.main(defaultTest='suite')