1# -*- coding: utf-8 -*-
2"""QGIS Unit tests for QgsMultiEditToolButton.
3
4.. note:: This program is free software; you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation; either version 2 of the License, or
7(at your option) any later version.
8"""
9__author__ = 'Nyall Dawson'
10__date__ = '16/03/2016'
11__copyright__ = 'Copyright 2016, The QGIS Project'
12
13import qgis  # NOQA switch sip api
14
15from qgis.gui import QgsMultiEditToolButton
16
17from qgis.testing import start_app, unittest
18
19start_app()
20
21
22class TestQgsMultiEditToolButton(unittest.TestCase):
23
24    def test_state_logic(self):
25        """
26        Test that the logic involving button states is correct
27        """
28        w = QgsMultiEditToolButton()
29        self.assertEqual(w.state(), QgsMultiEditToolButton.Default)
30
31        # set is changed should update state to changed
32        w.setIsChanged(True)
33        self.assertEqual(w.state(), QgsMultiEditToolButton.Changed)
34        w.setIsChanged(False)
35        self.assertEqual(w.state(), QgsMultiEditToolButton.Default)
36        # resetting changes should fall back to default state
37        w.setIsChanged(True)
38        w.resetChanges()
39        self.assertEqual(w.state(), QgsMultiEditToolButton.Default)
40        # setting changes committed should result in default state
41        w.setIsChanged(True)
42        w.changesCommitted()
43        self.assertEqual(w.state(), QgsMultiEditToolButton.Default)
44
45        # Test with mixed values
46        w.setIsMixed(True)
47        self.assertEqual(w.state(), QgsMultiEditToolButton.MixedValues)
48        # changed state takes priority over mixed state
49        w.setIsChanged(True)
50        self.assertEqual(w.state(), QgsMultiEditToolButton.Changed)
51        w.setIsChanged(False)
52        # should reset to mixed state
53        self.assertEqual(w.state(), QgsMultiEditToolButton.MixedValues)
54        # resetting changes should fall back to mixed state
55        w.setIsChanged(True)
56        w.resetChanges()
57        self.assertEqual(w.state(), QgsMultiEditToolButton.MixedValues)
58        # setting changes committed should result in default state
59        w.setIsChanged(True)
60        w.changesCommitted()
61        self.assertEqual(w.state(), QgsMultiEditToolButton.Default)
62
63
64if __name__ == '__main__':
65    unittest.main()
66