diff options
Diffstat (limited to 'sources/pyside2/tests')
| -rw-r--r-- | sources/pyside2/tests/QtCore/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | sources/pyside2/tests/QtCore/multiple_feature_test.py | 29 | ||||
| -rw-r--r-- | sources/pyside2/tests/QtCore/snake_prop_feature_test.py (renamed from sources/pyside2/tests/QtCore/snake_case_feature_test.py) | 44 |
3 files changed, 54 insertions, 21 deletions
diff --git a/sources/pyside2/tests/QtCore/CMakeLists.txt b/sources/pyside2/tests/QtCore/CMakeLists.txt index 0c89f0d03..9d268e079 100644 --- a/sources/pyside2/tests/QtCore/CMakeLists.txt +++ b/sources/pyside2/tests/QtCore/CMakeLists.txt @@ -128,7 +128,7 @@ PYSIDE_TEST(quuid_test.py) PYSIDE_TEST(qversionnumber_test.py) PYSIDE_TEST(repr_test.py) PYSIDE_TEST(setprop_on_ctor_test.py) -PYSIDE_TEST(snake_case_feature_test.py) +PYSIDE_TEST(snake_prop_feature_test.py) PYSIDE_TEST(staticMetaObject_test.py) PYSIDE_TEST(static_method_test.py) PYSIDE_TEST(thread_signals_test.py) diff --git a/sources/pyside2/tests/QtCore/multiple_feature_test.py b/sources/pyside2/tests/QtCore/multiple_feature_test.py index 351090382..329e513fb 100644 --- a/sources/pyside2/tests/QtCore/multiple_feature_test.py +++ b/sources/pyside2/tests/QtCore/multiple_feature_test.py @@ -48,8 +48,7 @@ from init_paths import init_test_paths init_test_paths(False) from PySide2 import QtCore -from PySide2.support.__feature__ import ( - _really_all_feature_names, pyside_feature_dict) +from PySide2.support import __feature__ from textwrap import dedent """ @@ -62,6 +61,8 @@ The first feature is `snake_case` instead of `camelCase`. There is much more to come. """ +MethodDescriptorType = type(str.split) + class FeaturesTest(unittest.TestCase): def testAllFeatureCombinations(self): @@ -69,7 +70,7 @@ class FeaturesTest(unittest.TestCase): Test for all 256 possible combinations of `__feature__` imports. """ - def tst_bit0(flag, self): + def tst_bit0(flag, self, bits): if flag == 0: QtCore.QCborArray.isEmpty QtCore.QCborArray.__dict__["isEmpty"] @@ -85,13 +86,25 @@ class FeaturesTest(unittest.TestCase): with self.assertRaises(KeyError): QtCore.QCborArray.__dict__["isEmpty"] + def tst_bit1(flag, self, bits): + getter_name = "object_name" if bits & 1 else "objectName" + setter_name = "set_object_name" if bits & 1 else "setObjectName" + thing = getattr(QtCore.QObject, getter_name) + if flag: + self.assertEqual(type(thing), property) + with self.assertRaises(AttributeError): + getattr(QtCore.QObject, setter_name) + else: + self.assertEqual(type(thing), MethodDescriptorType) + getattr(QtCore.QObject, setter_name) + edict = {} - for bit in range(1, 8): + for bit in range(2, 8): # We are cheating here, since the functions are in the globals. eval(compile(dedent(""" - def tst_bit{0}(flag, self): + def tst_bit{0}(flag, self, bits): if flag == 0: with self.assertRaises(AttributeError): QtCore.QCborArray.fake_feature_{1:02x} @@ -103,12 +116,12 @@ class FeaturesTest(unittest.TestCase): """).format(bit, 1 << bit), "<string>", "exec"), globals(), edict) globals().update(edict) - feature_list = _really_all_feature_names + feature_list = __feature__._really_all_feature_names func_list = [tst_bit0, tst_bit1, tst_bit2, tst_bit3, tst_bit4, tst_bit5, tst_bit6, tst_bit7] for idx in range(0x100): - pyside_feature_dict.clear() + __feature__.set_selection(0) config = "feature_{:02x}".format(idx) print() print("--- Feature Test Config `{}` ---".format(config)) @@ -121,7 +134,7 @@ class FeaturesTest(unittest.TestCase): eval(compile(text, "<string>", "exec"), globals(), edict) for bit in range(8): value = idx & 1 << bit - func_list[bit](value, self=self) + func_list[bit](value, self=self, bits=idx) if __name__ == '__main__': diff --git a/sources/pyside2/tests/QtCore/snake_case_feature_test.py b/sources/pyside2/tests/QtCore/snake_prop_feature_test.py index b7f23396e..779b8a408 100644 --- a/sources/pyside2/tests/QtCore/snake_case_feature_test.py +++ b/sources/pyside2/tests/QtCore/snake_prop_feature_test.py @@ -46,41 +46,61 @@ from init_paths import init_test_paths init_test_paths(False) from PySide2 import QtWidgets +from PySide2.support import __feature__ """ -snake_case_feature_test.py +snake_prop_feature_test.py -------------------------- -Test the snake_case feature. +Test the snake_case and true_property feature. This works now. More tests needed! """ -class RenamingTest(unittest.TestCase): +class Window(QtWidgets.QWidget): + def __init__(self): + super(Window, self).__init__() + + +class FeatureTest(unittest.TestCase): def setUp(self): qApp or QtWidgets.QApplication() + __feature__.set_selection(0) def tearDown(self): qApp.shutdown() def testRenamedFunctions(self): - - class Window(QtWidgets.QWidget): - def __init__(self): - super(Window, self).__init__() - window = Window() window.setWindowTitle('camelCase') # and now the same with snake_case enabled from __feature__ import snake_case - class Window(QtWidgets.QWidget): - def __init__(self): - super(Window, self).__init__() + # Works with the same window! window = Window() + window.set_window_title('snake_case') + def testPropertyAppearVanish(self): window = Window() - window.set_window_title('snake_case') + + self.assertTrue(callable(window.isModal)) + with self.assertRaises(AttributeError): + window.modal + + from __feature__ import snake_case, true_property + + self.assertTrue(isinstance(QtWidgets.QWidget.modal, property)) + self.assertTrue(isinstance(window.modal, bool)) + with self.assertRaises(AttributeError): + window.isModal + + # switching back + __feature__.set_selection(0) + + self.assertTrue(callable(window.isModal)) + with self.assertRaises(AttributeError): + window.modal + if __name__ == '__main__': unittest.main() |
