diff options
author | Cristián Maureira-Fredes <Cristian.Maureira-Fredes@qt.io> | 2021-07-13 19:57:24 +0200 |
---|---|---|
committer | Cristián Maureira-Fredes <Cristian.Maureira-Fredes@qt.io> | 2021-07-20 16:56:48 +0200 |
commit | bace73605d2e0483c6f8990452e701efdf4d5675 (patch) | |
tree | 57b3512e59bbf24dc458b652d29863a38ffa0813 /sources/pyside6/tests/QtCore/qdir_test.py | |
parent | 2654740274986e897427caf667fed93601e01bbd (diff) |
pathlib: fix empty constructors in conversion
In some classes, like QDir, there is a default value
for constructors that accept a QString:
QDir(const QString &path = QString())
However this case was not considered in Python land
when nothing is passed.
Considering other classes might have a similar situation,
we fix this at the level of the conversion and not per Qt class.
To reproduce this issue, a simple:
from PySide6.QtCore import QDir
a = QDir()
will segfault.
Added a simple test case,
and instructions to make the parameter optional (pyi).
Task-number: PYSIDE-1499
Change-Id: I42156b87ca0aa60466c743a8cc8b42ea5eeb3559
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'sources/pyside6/tests/QtCore/qdir_test.py')
-rw-r--r-- | sources/pyside6/tests/QtCore/qdir_test.py | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/sources/pyside6/tests/QtCore/qdir_test.py b/sources/pyside6/tests/QtCore/qdir_test.py new file mode 100644 index 000000000..169959dbf --- /dev/null +++ b/sources/pyside6/tests/QtCore/qdir_test.py @@ -0,0 +1,64 @@ +############################################################################# +## +## Copyright (C) 2021 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$ +## +############################################################################# + +import os +import sys +import unittest + +from pathlib import Path +sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) +from init_paths import init_test_paths +init_test_paths(False) + +from PySide6.QtCore import QDir + + +class QDirTest(unittest.TestCase): + '''Test case for QDir''' + + def testConstructor(self): + # Optional case without arguments is equivalent to the constructor + # QDir(const QString &path = QString()) + a = QDir() + + self.assertTrue(a.isReadable()) + self.assertTrue(a.isRelative()) + + # Empty string + b = QDir("") + self.assertEqual(a, b) + + # Empty Path + c = QDir(Path()) + self.assertEqual(a, c) + + self.assertEqual(b, c) + + +if __name__ == '__main__': + unittest.main() |