aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6/tests/QtCore/qsettings_test.py
diff options
context:
space:
mode:
Diffstat (limited to 'sources/pyside6/tests/QtCore/qsettings_test.py')
-rw-r--r--sources/pyside6/tests/QtCore/qsettings_test.py78
1 files changed, 46 insertions, 32 deletions
diff --git a/sources/pyside6/tests/QtCore/qsettings_test.py b/sources/pyside6/tests/QtCore/qsettings_test.py
index 00eec2679..64ceffd70 100644
--- a/sources/pyside6/tests/QtCore/qsettings_test.py
+++ b/sources/pyside6/tests/QtCore/qsettings_test.py
@@ -1,33 +1,9 @@
-#############################################################################
-##
-## Copyright (C) 2019 The Qt Company Ltd.
-## Contact: https://www.qt.io/licensing/
-##
-## This file is part of the test suite of Qt for Python.
-##
-## $QT_BEGIN_LICENSE:GPL-EXCEPT$
-## Commercial License Usage
-## Licensees holding valid commercial Qt licenses may use this file in
-## accordance with the commercial license agreement provided with the
-## Software or, alternatively, in accordance with the terms contained in
-## a written agreement between you and The Qt Company. For licensing terms
-## and conditions see https://www.qt.io/terms-conditions. For further
-## information use the contact form at https://www.qt.io/contact-us.
-##
-## GNU General Public License Usage
-## Alternatively, this file may be used under the terms of the GNU
-## General Public License version 3 as published by the Free Software
-## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-## included in the packaging of this file. Please review the following
-## information to ensure the GNU General Public License requirements will
-## be met: https://www.gnu.org/licenses/gpl-3.0.html.
-##
-## $QT_END_LICENSE$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
'''Test cases for QDate'''
+import gc
import os
import sys
import unittest
@@ -37,12 +13,14 @@ sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
from init_paths import init_test_paths
init_test_paths(False)
-from helper.helper import adjust_filename
-from PySide6.QtCore import QSettings
+from PySide6.QtCore import QDir, QSettings, QTemporaryDir, QByteArray
+
class TestQSettings(unittest.TestCase):
def testConversions(self):
- file_path = adjust_filename('qsettings_test.ini', __file__)
+ file = Path(__file__).resolve().parent / 'qsettings_test.ini'
+ self.assertTrue(file.is_file())
+ file_path = QDir.fromNativeSeparators(os.fspath(file))
settings = QSettings(file_path, QSettings.IniFormat)
r = settings.value('var1')
@@ -54,22 +32,48 @@ class TestQSettings(unittest.TestCase):
r = settings.value('var2', type=list)
self.assertEqual(type(r), list)
+ # Test mixed conversions
+ ba = QByteArray("hello".encode("utf-8"))
+
+ r = settings.value("test", ba, type=QByteArray)
+ self.assertEqual(type(r), QByteArray)
+
+ r = settings.value("test", ba, type=str)
+ self.assertEqual(type(r), str)
+
+ # Test invalid conversions
+ with self.assertRaises(TypeError):
+ r = settings.value("test", ba, type=dict)
def testDefaultValueConversion(self):
- settings = QSettings('foo.ini', QSettings.IniFormat)
+ temp_dir = QDir.tempPath()
+ dir = QTemporaryDir(f'{temp_dir}/qsettings_XXXXXX')
+ self.assertTrue(dir.isValid())
+ file_name = dir.filePath('foo.ini')
+ settings = QSettings(file_name, QSettings.IniFormat)
+ sample_list = ["a", "b"]
+ string_list_of_empty = [""]
settings.setValue('zero_value', 0)
settings.setValue('empty_list', [])
+ settings.setValue('some_strings', sample_list)
+ settings.setValue('string_list_of_empty', string_list_of_empty)
settings.setValue('bool1', False)
settings.setValue('bool2', True)
del settings
+ # PYSIDE-535: Need to collect garbage in PyPy to trigger deletion
+ gc.collect()
# Loading values already set
- settings = QSettings('foo.ini', QSettings.IniFormat)
+ settings = QSettings(file_name, QSettings.IniFormat)
# Getting value that doesn't exist
r = settings.value("variable")
self.assertEqual(type(r), type(None))
+ r = settings.value("variable", type=list)
+ self.assertEqual(type(r), list)
+ self.assertEqual(len(r), 0)
+
# Handling zero value
r = settings.value('zero_value')
self.assertEqual(type(r), int)
@@ -86,6 +90,15 @@ class TestQSettings(unittest.TestCase):
self.assertTrue(len(r) == 0)
self.assertEqual(type(r), list)
+ r = settings.value('some_strings')
+ self.assertEqual(r, sample_list)
+
+ r = settings.value('some_strings', type=list)
+ self.assertEqual(r, sample_list)
+
+ r = settings.value('string_list_of_empty', type=list)
+ self.assertEqual(r, string_list_of_empty)
+
# Booleans
r = settings.value('bool1')
self.assertEqual(type(r), bool)
@@ -112,5 +125,6 @@ class TestQSettings(unittest.TestCase):
r = settings.value('lala', 22, type=float)
self.assertEqual(type(r), float)
+
if __name__ == '__main__':
unittest.main()