summaryrefslogtreecommitdiff
path: root/silx/gui/plot/test/testScatterView.py
blob: 40fdac6dd5d2ffcd2eb24552c4d344e0f8a52cbd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# coding: utf-8
# /*##########################################################################
#
# Copyright (c) 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
# 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.
#
# ###########################################################################*/
"""Basic tests for ScatterView"""

__authors__ = ["T. Vincent"]
__license__ = "MIT"
__date__ = "06/03/2018"


import unittest

import numpy

from silx.gui.plot.items import Axis, Scatter
from silx.gui.plot import ScatterView
from silx.gui.plot.test.utils import PlotWidgetTestCase


class TestScatterView(PlotWidgetTestCase):
    """Test of ScatterView widget"""

    def _createPlot(self):
        return ScatterView()

    def test(self):
        """Simple tests"""
        x = numpy.arange(100)
        y = numpy.arange(100)
        value = numpy.arange(100)
        self.plot.setData(x, y, value)
        self.qapp.processEvents()

        data = self.plot.getData()
        self.assertEqual(len(data), 5)
        self.assertTrue(numpy.all(numpy.equal(x, data[0])))
        self.assertTrue(numpy.all(numpy.equal(y, data[1])))
        self.assertTrue(numpy.all(numpy.equal(value, data[2])))
        self.assertIsNone(data[3])  # xerror
        self.assertIsNone(data[4])  # yerror

        # Test access to scatter item
        self.assertIsInstance(self.plot.getScatterItem(), Scatter)

        # Test toolbar actions

        action = self.plot.getScatterToolBar().getXAxisLogarithmicAction()
        action.trigger()
        self.qapp.processEvents()

        maskAction = self.plot.getScatterToolBar().actions()[-1]
        maskAction.trigger()
        self.qapp.processEvents()

        # Test proxy API

        self.plot.resetZoom()
        self.qapp.processEvents()

        scale = self.plot.getXAxis().getScale()
        self.assertEqual(scale, Axis.LOGARITHMIC)

        scale = self.plot.getYAxis().getScale()
        self.assertEqual(scale, Axis.LINEAR)

        title = 'Test ScatterView'
        self.plot.setGraphTitle(title)
        self.assertEqual(self.plot.getGraphTitle(), title)

        self.qapp.processEvents()

        # Reset scatter data

        self.plot.setData(None, None, None)
        self.qapp.processEvents()

        data = self.plot.getData()
        self.assertEqual(len(data), 5)
        self.assertEqual(len(data[0]), 0)  # x
        self.assertEqual(len(data[1]), 0)  # y
        self.assertEqual(len(data[2]), 0)  # value
        self.assertIsNone(data[3])  # xerror
        self.assertIsNone(data[4])  # yerror


def suite():
    test_suite = unittest.TestSuite()
    loadTests = unittest.defaultTestLoader.loadTestsFromTestCase
    test_suite.addTest(loadTests(TestScatterView))
    return test_suite


if __name__ == '__main__':
    unittest.main(defaultTest='suite')