1# -*- coding: utf-8 -*-
2'''
3test_qgstabwidget.py
4                     --------------------------------------
5               Date                 : September 2016
6               Copyright            : (C) 2016 Matthias Kuhn
7               email                : matthias@opengis.ch
8 ***************************************************************************
9 *                                                                         *
10 *   This program is free software; you can redistribute it and/or modify  *
11 *   it under the terms of the GNU General Public License as published by  *
12 *   the Free Software Foundation; either version 2 of the License, or     *
13 *   (at your option) any later version.                                   *
14 *                                                                         *
15 ***************************************************************************/
16'''
17
18import qgis  # NOQA
19
20from qgis.testing import unittest, start_app
21from qgis.gui import QgsTabWidget
22from qgis.PyQt.QtWidgets import QWidget
23
24start_app()
25
26
27class TestQgsTabWidget(unittest.TestCase):
28
29    def setUp(self):
30        """Run before each test."""
31        pass
32
33    def tearDown(self):
34        """Run after each test."""
35        pass
36
37    def testQgsTabWidget(self):
38        tabWidget = QgsTabWidget()
39
40        wdg1 = QWidget()
41        wdg2 = QWidget()
42        wdg3 = QWidget()
43
44        tabWidget.addTab(wdg1, '1')
45        tabWidget.addTab(wdg2, '2')
46        tabWidget.addTab(wdg3, '3')
47
48        tabWidget.hideTab(wdg2)
49        self.assertEqual(tabWidget.count(), 2)
50        tabWidget.showTab(wdg2)
51        self.assertEqual(tabWidget.count(), 3)
52
53        self.assertEqual(tabWidget.tabText(0), '1')
54        self.assertEqual(tabWidget.tabText(1), '2')
55        self.assertEqual(tabWidget.tabText(2), '3')
56
57        tabWidget.hideTab(wdg2)
58        tabWidget.removeTab(1)
59        self.assertEqual(tabWidget.tabText(0), '1')
60        tabWidget.showTab(wdg2)
61        self.assertEqual(tabWidget.tabText(1), '2')
62        self.assertEqual(tabWidget.count(), 2)
63
64        # Show an already visible tab
65        tabWidget.showTab(wdg2)
66        self.assertEqual(tabWidget.count(), 2)
67
68        # Hide twice
69        tabWidget.hideTab(wdg2)
70        self.assertEqual(tabWidget.count(), 1)
71        tabWidget.hideTab(wdg2)
72        self.assertEqual(tabWidget.count(), 1)
73
74        tabWidget.hideTab(wdg1)
75        self.assertEqual(tabWidget.count(), 0)
76
77        tabWidget.showTab(wdg1)
78        tabWidget.showTab(wdg2)
79        self.assertEqual(tabWidget.count(), 2)
80
81        tabWidget.removeTab(0)
82        self.assertEqual(tabWidget.count(), 1)
83        tabWidget.hideTab(wdg2)
84        self.assertEqual(tabWidget.count(), 0)
85
86
87if __name__ == '__main__':
88    unittest.main()
89