|
| 1 | +# Copyright Contributors to the OpenCue Project |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | + |
| 16 | +"""Tests for cuegui.Config""" |
| 17 | + |
| 18 | + |
| 19 | +from __future__ import print_function |
| 20 | +from __future__ import division |
| 21 | +from __future__ import absolute_import |
| 22 | + |
| 23 | +import os |
| 24 | +import shutil |
| 25 | +import tempfile |
| 26 | +import unittest |
| 27 | + |
| 28 | +from PySide2 import QtCore |
| 29 | + |
| 30 | +import cuegui.Config |
| 31 | + |
| 32 | + |
| 33 | +CONFIG_INI = ''' |
| 34 | +[General] |
| 35 | +Version=0.14 |
| 36 | +
|
| 37 | +[CueCommander] |
| 38 | +Open=true |
| 39 | +Title=CustomWindowTitle |
| 40 | +OtherAttr=arbitrary-value |
| 41 | +''' |
| 42 | + |
| 43 | +CONFIG_WITH_RESTORE_FLAG = ''' |
| 44 | +[General] |
| 45 | +Version=0.14 |
| 46 | +RevertLayout=true |
| 47 | +
|
| 48 | +[CueCommander] |
| 49 | +OtherAttr=arbitrary-value |
| 50 | +''' |
| 51 | + |
| 52 | + |
| 53 | +class ConfigTests(unittest.TestCase): |
| 54 | + def setUp(self): |
| 55 | + self.config_dir = tempfile.mkdtemp() |
| 56 | + QtCore.QSettings.setPath( |
| 57 | + QtCore.QSettings.IniFormat, QtCore.QSettings.UserScope, self.config_dir) |
| 58 | + |
| 59 | + def tearDown(self): |
| 60 | + shutil.rmtree(self.config_dir) |
| 61 | + |
| 62 | + def test__should_load_user_config(self): |
| 63 | + app_name = 'arbitraryapp' |
| 64 | + config_file_path = os.path.join(self.config_dir, '.%s' % app_name, 'config.ini') |
| 65 | + os.mkdir(os.path.dirname(config_file_path)) |
| 66 | + with open(config_file_path, 'w') as fp: |
| 67 | + fp.write(CONFIG_INI) |
| 68 | + |
| 69 | + settings = cuegui.Config.startup(app_name) |
| 70 | + |
| 71 | + self.assertEqual('0.14', settings.value('Version')) |
| 72 | + self.assertEqual('true', settings.value('CueCommander/Open')) |
| 73 | + self.assertEqual('CustomWindowTitle', settings.value('CueCommander/Title')) |
| 74 | + self.assertEqual('arbitrary-value', settings.value('CueCommander/OtherAttr')) |
| 75 | + |
| 76 | + def test__should_load_default_config(self): |
| 77 | + settings = cuegui.Config.startup('CueCommander') |
| 78 | + |
| 79 | + self.assertEqual('false', settings.value('CueCommander/Open')) |
| 80 | + self.assertEqual('CueCommander', settings.value('CueCommander/Title')) |
| 81 | + self.assertFalse(settings.value('CueCommander/OtherAttr', False)) |
| 82 | + |
| 83 | + def test__should_restore_default_config(self): |
| 84 | + config_file_path = os.path.join(self.config_dir, '.cuecommander', 'config.ini') |
| 85 | + os.mkdir(os.path.dirname(config_file_path)) |
| 86 | + with open(config_file_path, 'w') as fp: |
| 87 | + fp.write(CONFIG_WITH_RESTORE_FLAG) |
| 88 | + |
| 89 | + settings = cuegui.Config.startup('CueCommander') |
| 90 | + |
| 91 | + self.assertEqual('false', settings.value('CueCommander/Open')) |
| 92 | + self.assertEqual('CueCommander', settings.value('CueCommander/Title')) |
| 93 | + self.assertFalse(settings.value('CueCommander/OtherAttr', False)) |
0 commit comments