diff options
Diffstat (limited to 'silx/test/test_sx.py')
-rw-r--r-- | silx/test/test_sx.py | 121 |
1 files changed, 113 insertions, 8 deletions
diff --git a/silx/test/test_sx.py b/silx/test/test_sx.py index 0de3b35..f0da32d 100644 --- a/silx/test/test_sx.py +++ b/silx/test/test_sx.py @@ -1,7 +1,7 @@ # coding: utf-8 # /*########################################################################## # -# Copyright (c) 2016-2017 European Synchrotron Radiation Facility +# Copyright (c) 2016-2018 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 @@ -24,16 +24,17 @@ # ###########################################################################*/ __authors__ = ["T. Vincent", "P. Knobel"] __license__ = "MIT" -__date__ = "05/12/2016" +__date__ = "27/02/2018" import logging import os import sys import unittest - import numpy +from silx.test.utils import test_options + _logger = logging.getLogger(__name__) @@ -52,15 +53,14 @@ if sys.platform.startswith('linux') and not os.environ.get('DISPLAY', ''): suite.addTest(SkipSXTest()) return suite -elif os.environ.get('WITH_QT_TEST', 'True') == 'False': +elif not test_options.WITH_QT_TEST: # Explicitly disabled tests - _logger.warning( - "silx.sx tests disabled (env. variable WITH_QT_TEST=False)") + msg = "silx.sx tests disabled %s" % test_options.WITH_QT_TEST_REASON + _logger.warning(msg) class SkipSXTest(unittest.TestCase): def runTest(self): - self.skipTest( - "silx.sx tests disabled (env. variable WITH_QT_TEST=False)") + self.skipTest(test_options.WITH_QT_TEST_REASON) def suite(): suite = unittest.TestSuite() @@ -73,6 +73,7 @@ else: from silx.gui import qt # load TestCaseQt before sx from silx.gui.test.utils import TestCaseQt + from silx.gui.plot.Colors import rgba from silx import sx class SXTest(TestCaseQt): @@ -163,6 +164,110 @@ else: title='origin=(10, 10), scale=(2, 2)') self._expose_and_close(plt) + def test_ginput(self): + """Test ginput function + + This does NOT perform interactive tests + """ + + plt = sx.plot() + self.qWaitForWindowExposed(plt) + self.qapp.processEvents() + + result = sx.ginput(1, timeout=0.1) + self.assertEqual(len(result), 0) + + plt.setAttribute(qt.Qt.WA_DeleteOnClose) + plt.close() + + @unittest.skipUnless(test_options.WITH_GL_TEST, + test_options.WITH_GL_TEST_REASON) + def test_contour3d(self): + """Test contour3d function""" + coords = numpy.linspace(-10, 10, 64) + z = coords.reshape(-1, 1, 1) + y = coords.reshape(1, -1, 1) + x = coords.reshape(1, 1, -1) + data = numpy.sin(x * y * z) / (x * y * z) + + # Just data + window = sx.contour3d(data) + + isosurfaces = window.getIsosurfaces() + self.assertEqual(len(isosurfaces), 1) + + self._expose_and_close(window) + if not window.getPlot3DWidget().isValid(): + self.skipTest("OpenGL context is not valid") + + # N contours + color + colors = ['red', 'green', 'blue'] + window = sx.contour3d(data, copy=False, contours=len(colors), + color=colors) + + isosurfaces = window.getIsosurfaces() + self.assertEqual(len(isosurfaces), len(colors)) + for iso, color in zip(isosurfaces, colors): + self.assertEqual(rgba(iso.getColor()), rgba(color)) + + self._expose_and_close(window) + + # by isolevel, single color + contours = 0.2, 0.5 + window = sx.contour3d(data, copy=False, contours=contours, + color='yellow') + + isosurfaces = window.getIsosurfaces() + self.assertEqual(len(isosurfaces), len(contours)) + for iso, level in zip(isosurfaces, contours): + self.assertEqual(iso.getLevel(), level) + self.assertEqual(rgba(iso.getColor()), + rgba('yellow')) + + self._expose_and_close(window) + + # Single isolevel, colormap + window = sx.contour3d(data, copy=False, contours=0.5, + colormap='gray', vmin=0.6, opacity=0.4) + + isosurfaces = window.getIsosurfaces() + self.assertEqual(len(isosurfaces), 1) + self.assertEqual(isosurfaces[0].getLevel(), 0.5) + self.assertEqual(rgba(isosurfaces[0].getColor()), + (0., 0., 0., 0.4)) + + self._expose_and_close(window) + + @unittest.skipUnless(test_options.WITH_GL_TEST, + test_options.WITH_GL_TEST_REASON) + def test_points3d(self): + """Test points3d function""" + x = numpy.random.random(1024) + y = numpy.random.random(1024) + z = numpy.random.random(1024) + values = numpy.random.random(1024) + + # 3D positions, no value + window = sx.points3d(x, y, z) + + self._expose_and_close(window) + if not window.getSceneWidget().isValid(): + self.skipTest("OpenGL context is not valid") + + # 3D positions, values + window = sx.points3d(x, y, z, values, mode='2dsquare', + colormap='magma', vmin=0.4, vmax=0.5) + self._expose_and_close(window) + + # 2D positions, no value + window = sx.points3d(x, y) + self._expose_and_close(window) + + # 2D positions, values + window = sx.points3d(x, y, values=values, mode=',', + colormap='magma', vmin=0.4, vmax=0.5) + self._expose_and_close(window) + def suite(): test_suite = unittest.TestSuite() test_suite.addTest( |