File: test_interface_colors.py

package info (click to toggle)
picard 2.13.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 32,976 kB
  • sloc: python: 68,813; ansic: 89; makefile: 14
file content (71 lines) | stat: -rw-r--r-- 2,735 bytes parent folder | download | duplicates (2)
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
# -*- coding: utf-8 -*-
#
# Picard, the next-generation MusicBrainz tagger
#
# Copyright (C) 2020 Philipp Wolfer
# Copyright (C) 2020-2021 Laurent Monin
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.


from PyQt5.QtGui import QColor

from test.picardtestcase import PicardTestCase

from picard import config

from picard.ui.colors import (
    InterfaceColors,
    UnknownColorException,
    interface_colors,
)


settings = {
    'interface_colors': {
        'unknowncolor': '#deadbe',
        'entity_error': '#abcdef',
    },
    'interface_colors_dark': {
        'unknowncolor': '#deadbe',
        'entity_error': '#abcdef',
    }
}


class InterfaceColorsTest(PicardTestCase):
    def setUp(self):
        super().setUp()
        self.set_config_values(settings)

    def test_interface_colors(self):
        for key in ('interface_colors', 'interface_colors_dark'):
            interface_colors = InterfaceColors(dark_theme=key == 'interface_colors_dark')
            with self.assertRaises(UnknownColorException):
                interface_colors.get_color('testcolor')
            default_colors = interface_colors.default_colors
            self.assertEqual(interface_colors.get_color('entity_error'), default_colors['entity_error'].value)
            interface_colors.load_from_config()
            self.assertEqual(interface_colors.get_color('entity_error'), '#abcdef')
            self.assertEqual(interface_colors.get_colors()['entity_error'], '#abcdef')
            interface_colors.set_color('entity_error', '#000000')
            self.assertTrue(interface_colors.save_to_config())
            self.assertEqual(config.setting[key]['entity_error'], '#000000')
            self.assertNotIn('unknowncolor', config.setting[key])
            self.assertEqual(interface_colors.get_color_description('entity_error'), default_colors['entity_error'].description)
            self.assertEqual(interface_colors.get_qcolor('entity_error'), QColor('#000000'))

    def test_interface_colors_default(self):
        self.assertIsInstance(interface_colors, InterfaceColors)