forked from metabrainz/picard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_settingsoverride.py
73 lines (59 loc) · 2.7 KB
/
test_settingsoverride.py
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
# -*- coding: utf-8 -*-
#
# Picard, the next-generation MusicBrainz tagger
#
# Copyright (C) 2019-2021 Laurent Monin
# Copyright (C) 2020 Philipp Wolfer
#
# 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 test.picardtestcase import PicardTestCase
from picard import config
from picard.util.settingsoverride import SettingsOverride
class SettingsOverrideTest(PicardTestCase):
def setUp(self):
super().setUp()
self.set_config_values({'key1': 'origval1', 'key2': 'origval2'})
self.new_settings = {'key1': 'newval2'}
def test_read_orig_settings(self):
override = SettingsOverride(config.setting, self.new_settings)
self.assertEqual(override['key1'], 'newval2')
self.assertEqual(override['key2'], 'origval2')
with self.assertRaises(KeyError):
x = override['key3'] # noqa: F841
def test_read_orig_settings_kw(self):
override = SettingsOverride(config.setting, key1='newval2')
self.assertEqual(override['key1'], 'newval2')
self.assertEqual(override['key2'], 'origval2')
def test_write_orig_settings(self):
override = SettingsOverride(config.setting, self.new_settings)
override['key1'] = 'newval3'
self.assertEqual(override['key1'], 'newval3')
self.assertEqual(config.setting['key1'], 'origval1')
override['key2'] = 'newval4'
self.assertEqual(override['key2'], 'newval4')
self.assertEqual(config.setting['key2'], 'origval2')
override['key3'] = 'newval5'
self.assertEqual(override['key3'], 'newval5')
with self.assertRaises(KeyError):
x = config.setting['key3'] # noqa: F841
def test_del_orig_settings(self):
override = SettingsOverride(config.setting, self.new_settings)
override['key1'] = 'newval3'
self.assertEqual(override['key1'], 'newval3')
del override['key1']
self.assertEqual(override['key1'], 'origval1')
self.assertEqual(override['key2'], 'origval2')
del override['key2']
self.assertEqual(override['key2'], 'origval2')