File: test_vtconfig.py

package info (click to toggle)
vitables 3.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 17,044 kB
  • sloc: python: 9,695; makefile: 214; sh: 90
file content (139 lines) | stat: -rw-r--r-- 6,071 bytes parent folder | download
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
"""Test class for vtconfig.py"""

import sys

import pytest

# from qtpy import QtCore
from qtpy import QtGui, QtWidgets

# from qtpy.QtTest import QTest
import vitables.utils


@pytest.mark.usefixtures('launcher')
class TestLogger:
    @pytest.fixture()
    def config(self, launcher):
        cfg = launcher.vtapp_object.config
        yield cfg
        # Tear down code
        cfg.writeValue('Logger/Paper', QtGui.QColor("#ffffff"))
        cfg.writeValue('Logger/Text', QtGui.QColor("#000000"))
        cfg.writeValue('Logger/Font', QtWidgets.QApplication.font())
        cfg.writeValue('Workspace/Background',
                       QtGui.QBrush(QtGui.QColor("#ffffff")))
        cfg.writeValue('Look/currentStyle', cfg.default_style)
        launcher.gui.setGeometry(100, 50, 700, 500)
        cfg.writeValue('Geometry/Position', launcher.gui.saveGeometry())
        launcher.gui.logger_dock.setFloating(False)
        launcher.gui.logger_dock.setVisible(True)
        launcher.gui.file_toolbar.setVisible(True)
        cfg.writeValue('Geometry/Layout', launcher.gui.saveState())
        cfg.writeValue('Geometry/HSplitter', launcher.gui.hsplitter.saveState())
        cfg.writeValue('Session/restoreLastSession', False)
        cfg.writeValue('Session/startupWorkingDir', 'home')
        cfg.writeValue('Session/lastWorkingDir', vitables.utils.getHomeDir())

    def test_credentials(self, launcher, config):
        organization = launcher.app.organizationName()
        product = launcher.app.applicationName()
        version = launcher.app.applicationVersion()
        reg_path = f'HKEY_CURRENT_USER\\Software\\{product}\\{version}'

        if sys.platform.startswith('win'):
            assert config.organizationName() == product
            assert config.applicationName() == version
            assert config.reg_path == reg_path
        elif sys.platform.startswith('darwin'):
            assert config.organizationName() == product
            assert config.applicationName() == version
        else:
            assert config.organizationName() == organization
            assert config.applicationName() == '-'.join((product, version))

    def test_logger(self, config):
        # Background
        bg = QtGui.QColor('#aabbcc')
        config.writeValue('Logger/Paper', bg)
        assert config.loggerPaper() == bg
        # Foreground
        fg = QtGui.QColor('#ccbbaa')
        config.writeValue('Logger/Text', fg)
        assert config.loggerText() == fg
        # Font
        font = QtGui.QFont('Times New Roman')
        config.writeValue('Logger/Font', font)
        assert config.loggerFont() == font

    def test_workspace(self, config):
        bg = QtGui.QBrush(QtGui.QColor('#aabbcc'))
        config.writeValue('Workspace/Background', bg)
        assert config.workspaceBackground() == bg

    def test_appStyle(self, config):
        style = QtWidgets.QStyleFactory.keys()[-1]
        config.writeValue('Look/CurrentStyle', style)
        assert config.readStyle() == style

    def test_windowGeometry(self, launcher, config):
        # Test the main window position and size (without the window frame)
        # Position means x and y coordinates of the top left corner
        # Size means width and height of the window
        launcher.gui.setGeometry(100, 50, 300, 250)
        config.writeValue('Geometry/Position', launcher.gui.saveGeometry())
        launcher.gui.setGeometry(150, 150, 300, 250)
        assert launcher.gui.restoreGeometry(config.windowPosition())
        assert launcher.gui.geometry().x() == 100
        assert launcher.gui.geometry().y() == 50
        assert launcher.gui.width() == 300
        assert launcher.gui.height() == 250

    def test_dockwidgetState(self, launcher, config):
        # Test the state of the main window's dockwidget
        logger_dock = launcher.gui.logger_dock
        logger_dock.setFloating(True)
        logger_dock.setVisible(False)
        config.writeValue('Geometry/Layout', launcher.gui.saveState())
        logger_dock.setFloating(False)
        assert launcher.gui.restoreState(config.windowLayout())
        assert logger_dock.isFloating()

    def test_toolbarsState(self, launcher, config):
        # Test the state (visibility and position) of the main window's toolbars
        # Note: it seems that position is not saved with saveState()
        ftb = launcher.gui.file_toolbar
        ftb.setVisible(False)
        config.writeValue('Geometry/Layout', launcher.gui.saveState())
        ftb.setVisible(True)
        assert launcher.gui.restoreState(config.windowLayout())
        assert not launcher.gui.file_toolbar.isVisible()

    def test_hsplitterState(self, launcher, config):
        launcher.gui.show()
        launcher.gui.setGeometry(100, 550, 700, 500)
        # Test the state (i.e. sizes) of the splitter
        splitter = launcher.gui.hsplitter
        expected_sizes = splitter.sizes()
        config.writeValue('Geometry/HSplitter', splitter.saveState())
        splitter.setSizes([200, 90])
        assert splitter.restoreState(config.hsplitterPosition())
        assert splitter.sizes() == expected_sizes
        launcher.gui.hide()

    def test_restoreLastSession(self, config):
        config.writeValue('Session/restoreLastSession', True)
        assert config.restoreLastSession()
        # None cannot be converted to a boolean value
        config.writeValue('Session/restoreLastSession', None)
        assert not config.restoreLastSession()

    def test_startupWorkingDir(self, config):
        config.writeValue('Session/startupWorkingDir', 'somepath')
        assert config.startupWorkingDir() == 'home'
        config.writeValue('Session/startupWorkingDir', 'last')
        assert config.startupWorkingDir() == 'last'

    def test_lastWorkingDir(self, config):
        config.writeValue('Session/lastWorkingDir', 1)
        assert config.lastWorkingDir() == vitables.utils.getHomeDir()